This repository demonstrates advanced SQL Server drift detection using Liquibase Pro with Flow automation, severity-based classification, and comprehensive reporting capabilities. It showcases enterprise-grade database change governance with automated drift monitoring, structured logging, and detailed HTML reporting suitable for compliance and audit requirements.
- Flow-based automation: Orchestrated database operations using Liquibase Flow with configurable stages and actions
- Severity-based drift classification: Four-level severity system (0-4) for different types of drift detection
- Structured logging: JSON-formatted logs with custom data integration for enterprise monitoring systems
- Comprehensive reporting: HTML reports with detailed drift analysis and visual change summaries
- Flow orchestration templates: Multi-stage Flow configuration with drift detection, snapshot, and reporting stages
- Enterprise configuration: Complete properties configuration with drift thresholds and reporting settings
- Organized SQL structure: Clean separation of DDL and DML operations with complete rollback coverage
- Automation scripts: Command examples for different operational scenarios and logging configurations
- Easy customizations: Database connections, drift severity thresholds, report paths, and logging configurations
- Moderate customizations: Adding Flow stages, modifying SQL scripts, implementing environment filtering
- Complex customizations: Enterprise CI/CD integration, custom reporting, and automated notification systems
- Adapting to different SQL Server versions and deployment patterns (Azure SQL Database, on-premise, hybrid)
- Integrating with enterprise change management and approval workflows
- Customizing drift severity thresholds based on business impact and compliance requirements
- Adding automated alerting and notification based on drift detection results
- Flow execution debugging: Stage-by-stage analysis with structured logging and error context
- Drift detection accuracy: Snapshot validation, timing considerations, and false positive elimination
- Database connectivity: Authentication, network, and permission troubleshooting in enterprise environments
- Performance optimization: Large database handling and resource allocation for drift operations
This pattern addresses large enterprises with SQL Server environments requiring strict change governance, automated drift monitoring, and comprehensive reporting. Particularly valuable for organizations with compliance requirements, multiple environments, and complex change approval processes that need detailed audit trails and automated detection of unauthorized schema changes.
- How to implement enterprise-grade drift detection with Liquibase Pro Flow
- Techniques for severity-based drift classification and threshold management
- Best practices for structured logging and enterprise monitoring integration
- Methods for automated reporting and change governance workflows
- SQL Server 2017 or higher (local instance or enterprise access)
- Liquibase Pro license (required for Flow and advanced drift features)
- PowerShell or Shell scripting capability for automation
- Network access to SQL Server instance (demo environment or enterprise)
- Understanding of enterprise database change governance requirements
# Clone the repository
git clone <repository-url>
cd drift_detection_2
# Verify SQL Server connectivity
sqlcmd -S demo-db1-win.liquibase.net -U DATICAL_USER -P DATICAL_USER_PW -Q "SELECT @@VERSION"
# Configure your SQL Server connection in liquibase.properties
# Update the following parameters:
# - url: Your SQL Server connection string
# - username/password: Your database credentials
# - reference-url: Offline snapshot reference for drift detection
# Test database connection
liquibase status
# Review and customize liquibase.properties:
# - Drift severity thresholds (1-4 scale)
# - Report output paths and naming
# - Logging configuration and custom data integration
# Review Flow configuration in liquibase.flowfile.yaml:
# - Drift detection stage settings
# - Snapshot generation parameters
# - Report configuration options
# Execute the complete Flow automation
liquibase flow --flow-file=liquibase.flowfile.yaml
# Or run individual operations:
liquibase update # Apply schema changes
liquibase snapshot --output-file=mySnapshot.json # Generate baseline snapshot
liquibase diff --reference-url="offline:sqlserver?snapshot=mySnapshot.json" # Detect drift
drift_detection_2/
├── liquibase.properties # Enterprise configuration with drift settings
├── liquibase.flowfile.yaml # Flow automation orchestration
├── liquibase.checks-settings.conf # Quality checks configuration
├── changelog.xml # Main changelog with structured organization
├── commands.sh # Command examples and automation scripts
├── mySnapshot.json # Generated database snapshot for comparison
├── main/
│ ├── 100_ddl/ # DDL operations (tables, indexes, constraints)
│ │ ├── 01_sales.sql
│ │ ├── 01_sales-rollback.sql
│ │ ├── 02_employee.sql
│ │ ├── 02_employee-rollback.sql
│ │ └── ... (additional DDL files)
│ └── 700_dml/ # DML operations (data changes, inserts)
│ ├── Q4-2022_employees.sql
│ ├── Q4-2022_employees-rollback.sql
│ └── Q4-2022_employees2.sql
└── reports/
└── 06.diff-report.html # Generated drift detection report
Advanced orchestration capabilities including:
- Multi-stage Flow execution with configurable actions
- Automated drift detection with severity classification
- Integrated snapshot generation and comparison
- Structured logging with custom data integration
- Error handling and cleanup procedures in endStage
Comprehensive drift monitoring featuring:
- Four-level severity classification (0-4 scale)
- Configurable thresholds for different drift types (missing, unexpected, changed)
- Offline snapshot comparison for environment validation
- HTML reporting with detailed change analysis
- JSON output for programmatic integration
Clean separation of concerns with:
- DDL operations organized by sequence (100_ddl)
- DML operations organized by time period (700_dml)
- Complete rollback coverage for all changesets
- External SQL file organization for maintainability
Variable | Description | Default | Required |
---|---|---|---|
DB_URL |
SQL Server connection string | See liquibase.properties | Yes |
DB_USER |
Database username | DATICAL_USER | Yes |
DB_PASSWORD |
Database password | DATICAL_USER_PW | Yes |
SNAPSHOT_FILE |
Snapshot file for drift comparison | mySnapshot.json | No |
Key configuration options in liquibase.properties
:
changelogFile
: Main changelog file (changelog.xml)url
: Primary database connection stringreference-url
: Offline snapshot reference for drift detectionliquibase.command.diff.driftSeverity
: Base drift severity threshold (1-4)liquibase.command.diff.driftSeverityMissing
: Missing objects severity (2)liquibase.command.diff.driftSeverityUnexpected
: Unexpected objects severity (3)liquibase.command.diff.driftSeverityChanged
: Changed objects severity (4)liquibase.reports.enabled
: Enable HTML report generationliquibase.reports.path
: Report output directory (reports)liquibase.reports.name
: Report filename (diff_report.html)
- Apply schema changes using
liquibase update
- Generate current snapshot for comparison baseline
- Test rollback procedures for all changesets
- Validate change organization and file structure
- Execute Flow automation to detect drift from development
- Review generated drift reports for unexpected changes
- Apply approved changes with automated reporting
- Validate environment consistency with snapshot comparison
- Generate comprehensive baseline snapshot of current state
- Execute drift detection Flow with enterprise reporting
- Review and approve changes based on severity classification
- Apply changes during maintenance window with immediate rollback capability
-- Create new SQL file in appropriate directory (DDL or DML)
-- Example: main/100_ddl/06_indexes.sql
CREATE INDEX idx_sales_lastname ON sales(last_name);
-- Create corresponding rollback file: main/100_ddl/06_indexes-rollback.sql
DROP INDEX idx_sales_lastname ON sales;
-- Add changeset to changelog.xml
<changeSet id="DB-1016" author="yourname">
<sqlFile path="main/100_ddl/06_indexes.sql"/>
<rollback>
<sqlFile path="main/100_ddl/06_indexes-rollback.sql"/>
</rollback>
</changeSet>
# Rollback specific number of changesets
liquibase rollbackCount 3
# Rollback to specific tag
liquibase rollbackToTag v1.0
# Test rollback without execution
liquibase rollbackCountSql 3 > rollback.sql
# Execute complete Flow with reporting
liquibase flow --flow-file=liquibase.flowfile.yaml
# Manual drift detection with custom settings
liquibase diff --drift-severity=1 --drift-severity-missing=2 \
--reference-url="offline:sqlserver?snapshot=mySnapshot.json" \
--reports-enabled=true --reports-path=reports
# Generate structured logs with custom data
liquibase --log-format=JSON_PRETTY --log-level=INFO \
--custom-log-data-file=custom-data.yaml status --verbose
- Liquibase Pro Flow Documentation
- Liquibase Drift Detection Guide
- SQL Server Integration Best Practices
- Enterprise Logging and Monitoring
For issues related to this implementation pattern, please review the troubleshooting section in the summary.md file. For Liquibase Pro support and enterprise features, contact Liquibase support through your enterprise agreement.