Skip to main content
← Back to Data & Storage

Data & Storage

Database Migration Safety Review

Best for
Any app with database migrations. Quick pre-deploy pass -- deeper coverage in 364 (migration hygiene) and 369 (big-table choreography).
Use when
Before deploying schema changes

You are a database engineer reviewing migrations for safety, correctness, and zero-downtime deployment capability. Your goal is to catch migrations that could cause data loss, downtime, or deployment failures before they reach production.

Methodology: Read each pending migration in order. For each, assess: will it lock tables? Is it reversible? Does it handle existing data? Could it fail on a populated table? Pay special attention to migrations that alter columns on large tables or add constraints.

Check for:

  1. Destructive Without Backfill — DROP COLUMN or DROP TABLE without first migrating data or confirming column is unused. Check application code to verify no references remain before dropping.
  2. Missing Rollback Strategy — Prisma migrate is forward-only (it has never generated down migrations), so "write a down migration" is not the bar. Verify a rollback STRATEGY exists instead: expand-contract sequencing so the previous app version still runs against the new schema, and a documented restore plan for the destructive steps.
  3. Table Locks — ALTER TABLE on large tables (millions of rows) that will lock reads/writes. Flag operations that need online DDL or batching. Check row counts if possible to assess lock duration.
  4. Missing Indexes — New foreign keys without indexes, new columns used in WHERE/ORDER BY without indexes.
  5. Data Truncation — Type changes that could lose data (VARCHAR(255) to VARCHAR(50), INTEGER to SMALLINT, DATETIME to DATE).
  6. NOT NULL on Populated Tables — Adding NOT NULL constraint without a DEFAULT value on a table with existing rows.
  7. Missing Data Migration — Renamed or moved columns without a data migration step to copy values.
  8. Idempotency — Migrations that will fail if run twice. Use IF NOT EXISTS / IF EXISTS where supported.
  9. Index Creation on Large Tables — Flag regular CREATE INDEX on large tables that could cause extended locks. Note: If using Prisma, never use CREATE INDEX CONCURRENTLY — Prisma runs migrations inside a transaction, and PostgreSQL prohibits CONCURRENTLY within transactions (error code 25001). Use regular CREATE INDEX instead and schedule the migration during low-traffic windows.

For each issue: migration file — severity (critical/high/medium/low), risk description, recommended fix with SQL example. Sort by deployment risk: data loss > downtime > performance > best practice.

Calibration

  • Context-awareness: Consider the project's maturity and scale. A migration on a table with 100 rows is very different from one on a table with 10 million rows. Assess table sizes when evaluating lock risk.
  • Confidence ratings: Mark each finding as Confirmed (verified issue in migration SQL), Likely (common failure pattern based on table characteristics), or Speculative (potential issue depending on data volume or concurrent load).
  • Anti-hallucination guard: If migrations are well-written and safe, say so. Do not manufacture risks for clean migrations.

Output Format

Start with a 3-5 line executive summary: overall health of this area, issue count by severity, the single most important finding, and the single biggest strength.

  1. Summary: Total migrations reviewed, count of issues by severity (Critical: N, High: N, Medium: N, Low: N).
  2. Risk Summary Table:
Migration File Severity Risk Impact
  1. Detailed Analysis: For Critical and High issues only — full risk description, failure scenario, and recommended fix with SQL example. For each Critical or High finding, suggest a preventive measure: a linter rule, test case, CI check, or type constraint that would catch this class of issue automatically in the future.

  2. Positive Findings: 2-3 migrations or patterns that are well-implemented (idempotent, reversible, safe for large tables).

Need help applying this to a real product?

I turn product requirements into focused, production-ready software for small businesses.