Skip to content

Advanced SQL Server drift detection using Liquibase Pro Flow automation with severity-based classification and comprehensive HTML reporting

Notifications You must be signed in to change notification settings

liquibase-examples/drift_detection_2

Repository files navigation

Drift Detection 2

Overview

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.

Implementation Summary

Core Implementation Patterns

  • 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

Reusable Components

  • 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

Customer Adaptation Points

  • 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

Common Customizations

  • 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

Troubleshooting Patterns

  • 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

Use Case

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.

What You'll Learn

  • 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

Prerequisites

  • 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

Quick Start

1. Environment Setup

# 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"

2. Database Setup

# 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

3. Configure Liquibase

# 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

4. Run Initial Migration

# 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

Repository Structure

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

Key Features Demonstrated

Liquibase Pro Flow Integration

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

Enterprise Drift Detection

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

Structured Database Organization

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

Configuration

Environment Variables

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

Liquibase Properties

Key configuration options in liquibase.properties:

  • changelogFile: Main changelog file (changelog.xml)
  • url: Primary database connection string
  • reference-url: Offline snapshot reference for drift detection
  • liquibase.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 generation
  • liquibase.reports.path: Report output directory (reports)
  • liquibase.reports.name: Report filename (diff_report.html)

Deployment Workflows

Development Environment

  1. Apply schema changes using liquibase update
  2. Generate current snapshot for comparison baseline
  3. Test rollback procedures for all changesets
  4. Validate change organization and file structure

QA Environment

  1. Execute Flow automation to detect drift from development
  2. Review generated drift reports for unexpected changes
  3. Apply approved changes with automated reporting
  4. Validate environment consistency with snapshot comparison

Production Environment

  1. Generate comprehensive baseline snapshot of current state
  2. Execute drift detection Flow with enterprise reporting
  3. Review and approve changes based on severity classification
  4. Apply changes during maintenance window with immediate rollback capability

Common Operations

Adding a New Migration

-- 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>

Rolling Back Changes

# 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

Checking Database Status

# 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

Additional Resources

Support

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.

About

Advanced SQL Server drift detection using Liquibase Pro Flow automation with severity-based classification and comprehensive HTML reporting

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •