Pre Migration Data Verification

Use before adding a constraint to an existing populated table (CREATE UNIQUE INDEX, ALTER ... ADD CHECK, ALTER ... NOT NULL, ADD FOREIGN KEY): query the existing data for would-be violations FIRST and write a cleanup-statement (UPDATE/DELETE) into the same migration block BEFORE the constraint-create. Skipping this → silent migration failure ("duplicate key" / "check violation" / "null value not allowed"), the entire migration rolls back and no error surfaces until the next deploy. Trigger on phrases like "add unique constraint to existing table", "CREATE UNIQUE INDEX migration", "ALTER TABLE ADD CHECK", "make column NOT NULL on existing data", "add foreign key to populated table", "migration silently failed". Do NOT load for first-time CREATE TABLE migrations (no existing data to violate), for column ADD migrations without constraints (defaults handle the gap), or for development DBs that can be wiped. PostgreSQL-focused; the pattern transfers to MySQL/SQLite/Oracle.

Ed3Design 7d40f83 9.2 KB Updated

File contents

Ed3Design/ed3design-skill-bundles/tree/main/schema-discipline/skills/pre-migration-data-verification commit 7d40f83402

Frequently asked questions

npx skillmds@latest add ed3design/pre-migration-data-verification