Contents

Chapter 1

Schema Evolution Toolkit

Schema Evolution Toolkit

Detect, validate, migrate, and analyze schema changes across Delta Lake tables β€” safely and automatically.

By Datanest Digital | Version 2.0.0 | $39



What You Get

A complete toolkit for managing schema evolution in Databricks / Delta Lake pipelines:

  • Schema Detector β€” compare live table schemas against expected definitions, detect drift
  • Schema Diff β€” detailed field-level diff between any two schema versions (no Spark required)
  • Schema Migrator β€” apply safe migrations (add columns, widen types, rename) with rollback
  • Migration Generator β€” auto-generate SQL forward, rollback, and Python migration scripts
  • Impact Analyzer β€” check which pipelines, views, and dashboards break before deploying
  • Compatibility Checker β€” verify backward/forward compatibility before deploying changes
  • Schema Registry β€” Delta-table-backed registry for versioned schema definitions
  • Schema Validator β€” validate DataFrames against registered schemas at runtime
  • Ready-to-use Notebooks β€” detect drift, evolve schemas, and generate migrations interactively
  • Schema Versions β€” example customer (v1/v2/v3) and order (v1/v2) JSON schema files
  • Evolution Strategy Guide β€” comprehensive guide to schema versioning, migration, and impact analysis

File Tree

schema-evolution-toolkit/
β”œβ”€β”€ README.md
β”œβ”€β”€ manifest.json
β”œβ”€β”€ LICENSE
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ schema_detector.py       # Detect schema drift between expected and actual
β”‚   β”œβ”€β”€ schema_diff.py           # Field-level diff with severity classification
β”‚   β”œβ”€β”€ schema_migrator.py       # Apply safe migrations with rollback support
β”‚   β”œβ”€β”€ migration_generator.py   # Generate SQL/Python migration scripts from diffs
β”‚   β”œβ”€β”€ impact_analyzer.py       # Analyze downstream impact of schema changes
β”‚   β”œβ”€β”€ compatibility_checker.py # Backward/forward compatibility validation
β”‚   β”œβ”€β”€ schema_registry.py       # Delta-table-backed schema version registry
β”‚   └── schema_validator.py      # Runtime DataFrame schema validation
β”œβ”€β”€ configs/
β”‚   β”œβ”€β”€ schema_policy.yaml       # Evolution rules and policies per layer
β”‚   └── schemas/
β”‚       β”œβ”€β”€ v1_customer.json     # Customer schema v1 (4 fields)
β”‚       β”œβ”€β”€ v2_customer.json     # Customer schema v2 (rename, add nested struct)
β”‚       β”œβ”€β”€ v3_customer.json     # Customer schema v3 (arrays, nested structs, new fields)
β”‚       β”œβ”€β”€ v1_order.json        # Order schema v1 (7 fields)
β”‚       └── v2_order.json        # Order schema v2 (type widening, shipping, discounts)
β”œβ”€β”€ notebooks/
β”‚   β”œβ”€β”€ detect_drift.py          # Interactive drift detection notebook
β”‚   β”œβ”€β”€ evolve_schema.py         # Interactive schema migration notebook
β”‚   └── generate_migration.py    # Migration script generation notebook
β”œβ”€β”€ tests/
β”‚   β”œβ”€β”€ conftest.py              # Shared pytest fixtures (SparkSession, sample schemas)
β”‚   β”œβ”€β”€ test_schema_detector.py  # Detector unit tests
β”‚   β”œβ”€β”€ test_compatibility.py    # Compatibility checker tests
β”‚   β”œβ”€β”€ test_schema_diff.py      # Schema diff tests
β”‚   β”œβ”€β”€ test_migration_generator.py  # Migration generator tests
β”‚   └── test_impact_analyzer.py  # Impact analyzer tests
└── guides/
    └── schema-evolution-strategy.md  # Versioning, migration & impact analysis guide

Architecture

  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
  β”‚  Upstream     │────▢│  Schema Detector  │────▢│  Drift Report   β”‚
  β”‚  Data Source  β”‚     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                                        β”‚
                                                          β–Ό
                        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                        β”‚  Schema Diff     │◀────│  Compare v1/v2  β”‚
                        β”‚  (field-level)   β”‚     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                        β””β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚
                   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                   β–Ό            β”‚                β–Ό
          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
          β”‚ Compatibility  β”‚   β”‚     β”‚ Impact Analyzer   β”‚
          β”‚ Checker        β”‚   β”‚     β”‚ (downstream deps) β”‚
          β””β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚     β””β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                  β”‚            β”‚             β”‚
         Compatible?     β”Œβ”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”      Risk
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”‚ Migration β”‚    Score OK?
        β–Ό YES     β–Ό NO   β”‚ Generator β”‚    β”Œβ”€β”€β”€β”€β”€β”€β”€β”
 β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”  β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜   β–Ό YES   β–Ό NO
 β”‚ Generate β”‚  β”‚Alert/β”‚        β”‚    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”
 β”‚ Scripts  β”‚  β”‚Block β”‚        β”‚    β”‚ Apply    β”‚ β”‚ Manual  β”‚
 β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”˜        β”‚    β”‚ Scripts  β”‚ β”‚ Review  β”‚
       β”‚                       β”‚    β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
       β–Ό                       β”‚          β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”               β”‚          β”‚
β”‚ Schema       β”‚β—€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚ Registry     β”‚
β”‚ (store ver.) β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
Chapter 2

Getting Started

Follow this guide to get schema evolution toolkit up and running in your environment.

Getting Started

1. Detect Schema Drift

python
from schema_detector import SchemaDetector

detector = SchemaDetector(spark)

# Compare a live table against an expected JSON schema
report = detector.compare_table_to_schema(
    table_name="catalog.bronze.customers",
    expected_schema_path="/Volumes/schemas/v2_customer.json",
)

print(report.summary())
# SchemaReport: 2 added columns, 1 type change, 0 removed columns

2. Detailed Schema Diff (No Spark Required)

python
from schema_diff import SchemaDiff

differ = SchemaDiff()
diff = differ.diff_from_files("v1_customer.json", "v2_customer.json")

# Print a categorized report
print(diff.to_text())

# Get Markdown for PR comments
print(diff.to_markdown())

# Check for breaking changes
if diff.has_breaking_changes:
    for bc in diff.breaking_changes:
        print(f"  BREAKING: {bc.field_path} β€” {bc.message}")

3. Check Compatibility

python
from compatibility_checker import CompatibilityChecker

checker = CompatibilityChecker()

result = checker.check_backward_compatible(old_schema, new_schema)
if not result.is_compatible:
    for issue in result.issues:
        print(f"  BREAKING: {issue}")

4. Generate Migration Scripts

python
from migration_generator import MigrationGenerator

gen = MigrationGenerator()
migration = gen.generate_from_files(
    "v1_customer.json", "v2_customer.json",
    table_name="catalog.silver.customers",
)

# Print forward SQL
print(migration.render_forward_sql())

# Print rollback SQL
print(migration.render_rollback_sql())

# Generate a Python migration module
print(migration.render_python_migration())

# Get structured JSON for CI/CD
print(migration.to_json())

5. Analyze Downstream Impact

python
from impact_analyzer import ImpactAnalyzer

analyzer = ImpactAnalyzer()
analyzer.load_manifest_file("dependency_manifest.json")
impact = analyzer.analyze_from_diff(diff, "catalog.silver.customers")

print(impact.summary())
# Impact Analysis: 3/5 assets impacted, risk_score=0.45, critical=1

if impact.critical_impacts:
    print("BLOCKED: SLA-critical assets affected!")

6. Apply a Migration

python
from schema_migrator import SchemaMigrator

migrator = SchemaMigrator(spark)

migrator.add_columns(
    table_name="catalog.silver.customers",
    columns={"loyalty_tier": "STRING", "last_login": "TIMESTAMP"},
)

7. Register a Schema Version

python
from schema_registry import SchemaRegistry

registry = SchemaRegistry(spark, registry_table="catalog.meta.schema_registry")
registry.register(
    subject="customers",
    version=2,
    schema=new_schema,
    description="Added loyalty_tier and last_login columns",
)

8. Validate at Runtime

python
from schema_validator import SchemaValidator

validator = SchemaValidator(spark)
result = validator.validate(df, expected_schema, mode="strict")
if not result.is_valid:
    raise ValueError(f"Schema validation failed: {result.errors}")

Schema Version Examples

The toolkit includes example schemas demonstrating common evolution patterns:

Customer Domain (v1 β†’ v2 β†’ v3)

VersionFieldsChanges
v1id, name, email, created_atInitial schema
v2id, name, contact_email, phone, address (struct), created_atRename email, add phone + nested address
v3All v2 + preferences (struct with array), tags (array), loyalty_points, updated_at, address.regionComplex nested types, arrays

Order Domain (v1 β†’ v2)

VersionFieldsChanges
v1order_id, customer_id, order_date (date), status, total_amount, item_count, created_atInitial schema
v2All v1 + currency, shipping_address (struct), discount_code, discount_amount, updated_atType widening (date→timestamp), multi-currency, discounts

Requirements

  • Python 3.9+
  • Schema Diff, Migration Generator, Impact Analyzer: Python stdlib only (no Spark required)
  • Schema Detector, Migrator, Registry, Validator: PySpark 3.4+ / Databricks Runtime 13.3+
  • Schema Registry: Delta Lake (delta-spark)
  • Policy config loading: PyYAML
Chapter 3
πŸ”’ Available in full product

Configuration

Chapter 4
πŸ”’ Available in full product

Advanced Reference

You’ve reached the end of the free preview

Get the full Schema Evolution Toolkit and unlock everything.

All Chapters

Get the complete guide with every chapter unlocked, including code samples, diagrams, and best practices.

Full Tool Suite

Access all interactive tools with complete data, all workload profiles, and the full scenario library.

Source Files

Downloadable source code, configuration files, and working examples from every chapter.

Lifetime Updates

Free updates for life. Every new chapter, tool, and improvement included.

Buy Now — $39 →
πŸ“¦ Free sample included — download another copy for the full product.
Schema Evolution Toolkit v1.0.0 β€” Free Preview