Skip to content

Create a migration validation script for production database schema drift #608

Description

@success-OG

Labels: backend infrastructure database

Background
scripts/validate-migrations.ts (2.7 KB) checks that migration files are ordered correctly but does not compare the actual DB schema against what the migrations should have produced. Schema drift (direct DB edits in staging accidentally applied to prod) is undetectable.

What "Done" Looks Like

  • Script connects to the target DB and runs pg_dump --schema-only
  • Compares the dump against the expected schema derived by running all migrations on a fresh DB
  • Reports any columns/tables/indexes present in the DB but absent from the migration history (and vice versa)
  • Runnable as npm run validate:schema -- --env production
  • Non-destructive: read-only DB connection

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions