schema-migration
Schema Migration Analysis
Requirements
Agent: any (read-only analysis) Tools used: altimate_core_migration, altimate_core_schema_diff, schema_diff, read, glob, bash (for git operations)
When to Use This Skill
Use when the user wants to:
- Analyze a DDL migration for data loss risks before applying it
- Compare two schema versions to find breaking changes
- Review ALTER TABLE / CREATE TABLE changes in a PR
- Validate that a model refactoring doesn't break the column contract
Do NOT use for:
- Writing new models -> use
dbt-develop - Analyzing downstream impact of SQL logic changes -> use
dbt-analyze - Optimizing queries -> use
query-optimize
Workflow
1. Get the Schema Versions
For DDL migrations (ALTER TABLE, CREATE TABLE):
- Read the migration file(s) from disk
- The "old" schema is the current state; the "new" schema is after applying the migration
For dbt model changes (comparing before/after SQL):
# Get the old version from git
git show HEAD:<path/to/model.sql> > /tmp/old_model.sql
# The new version is the current file
For schema YAML changes:
- Read both versions of the schema.yml file
2. Analyze DDL Migration Safety
Call altimate_core_migration to detect data loss risks:
altimate_core_migration(old_ddl: <old_ddl>, new_ddl: <new_ddl>, dialect: <dialect>)
This checks for:
- Type narrowing: VARCHAR(100) -> VARCHAR(50) (truncation risk)
- NOT NULL without default: Adding NOT NULL column without DEFAULT (fails on existing rows)
- Dropped columns: Data loss if column has values
- Dropped constraints: Unique/check constraints removed (data integrity risk)
- Type changes: INTEGER -> VARCHAR (irreversible in practice)
- Index drops: Performance regression risk
3. Diff Schema Structures
For YAML/JSON schemas: Call altimate_core_schema_diff to compare two schema definitions:
altimate_core_schema_diff(schema1: <old_schema>, schema2: <new_schema>)
Returns: added/removed/modified tables and columns, type changes, constraint changes, breaking change detection.
For SQL model changes: Call schema_diff to compare two SQL models for column-level breaking changes:
schema_diff(old_sql: <old_sql>, new_sql: <new_sql>, dialect: <dialect>)
Returns: dropped columns (BREAKING), type changes (WARNING), potential renames (Levenshtein distance matching).
4. Present the Analysis
Schema Migration Analysis
=========================
Migration: alter_orders_table.sql
Dialect: snowflake
BREAKING CHANGES (2):
[DATA LOSS] Dropped column: orders.discount_amount
-> Column has 1.2M non-NULL values. Data will be permanently lost.
[TRUNCATION] Type narrowed: orders.customer_name VARCHAR(200) -> VARCHAR(50)
-> 3,400 rows exceed 50 chars. Values will be truncated.
WARNINGS (1):
[CONSTRAINT] Dropped unique constraint on orders.external_id
-> Duplicates may be inserted after migration.
SAFE CHANGES (3):
[ADD] New column: orders.updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
[ADD] New column: orders.version INTEGER DEFAULT 1
[WIDEN] Type widened: orders.amount DECIMAL(10,2) -> DECIMAL(18,2)
Recommendation: DO NOT apply without addressing BREAKING changes.
1. Back up discount_amount data before dropping
2. Verify no values exceed 50 chars, or widen the target type
3. Confirm external_id uniqueness is no longer required
5. For dbt Model Refactoring
When the user is refactoring a dbt model (renaming columns, changing types):
- Run
schema_diffon old vs new compiled SQL - Cross-reference with
dbt-analyzeto check downstream consumers - Flag any downstream model that references a dropped/renamed column
Usage
/schema-migration migrations/V003__alter_orders.sql-- Analyze a DDL migration file/schema-migration models/staging/stg_orders.sql-- Compare current file against last commit/schema-migration --old schema_v1.yml --new schema_v2.yml-- Compare two schema files
More from altimateai/altimate-code
data-viz
>
6dbt-unit-tests
Generate dbt unit tests automatically for any model. Analyzes SQL logic (CASE/WHEN, JOINs, window functions, NULLs), creates type-correct mock inputs from manifest schema, and assembles complete YAML. Use when a user says "generate tests", "add unit tests", "test this model", or "test coverage" for dbt models.
3dbt-test
Add schema tests, unit tests, and data quality checks to dbt models. Use when validating data integrity, adding test definitions to schema.yml, writing unit tests, or practicing test-driven development in dbt. Powered by altimate-dbt.
2dbt-docs
Document dbt models and columns in schema.yml with business context — model descriptions, column definitions, and doc blocks. Use when adding or improving documentation for discoverability. Powered by altimate-dbt.
2sql-review
Pre-merge SQL quality gate — lint 26 anti-patterns, grade readability/performance A-F, validate syntax, and scan for injection threats. Use before committing or reviewing SQL changes.
2dbt-troubleshoot
Debug dbt errors — compilation failures, runtime database errors, test failures, wrong data, and performance issues. Use when something is broken, producing wrong results, or failing to build. Powered by altimate-dbt.
2