HomeRoadmapsDB Migration Day 1
Database Migrations & Zero-Downtime Schema Evolution Β· Day 1 Β· 20 min

Static SQL Migration Linter & Lock-Risk Analyzer
Zero-Downtime Schema Evolution β€” Day 1

Detect ACCESS EXCLUSIVE table locks, missing lock_timeout guards, non-concurrent index builds, and destructive DDL before a migration PR ever reaches staging.

⚑ Runtime: Node.js 22 LTS Β· VitestπŸ›‘οΈ Database Reliability & Schema Evolution QE Architect
SQL LintingLock Analysislock_timeoutCONCURRENTLYStatic Gate
About this lab

A single unguarded ALTER TABLE or non-concurrent CREATE INDEX can acquire an ACCESS EXCLUSIVE or SHARE lock and stall every application query behind a lock queue pile-up. Today you will build and test a deterministic SQL migration linter that catches lock-risk anti-patterns statically in CI.

Interactive Schema Evolution Lab

Expand-Contract & Lock-Risk Migration Simulator

Safe Expand-and-Contract (Zero-Downtime)
SET lock_timeout = '2s';
ALTER TABLE users ADD COLUMN display_name TEXT;
CREATE INDEX CONCURRENTLY idx_users_display_name ON users (display_name);
EXPAND
Lock: NONE (metadata)
N-1: OK Β· N: OK
Nullable column added
DUAL_WRITE
Lock: ROW_EXCLUSIVE
N-1: OK Β· N: OK
Chunked backfill + dual-write
SWITCH_READS
Lock: NONE
N-1: OK Β· N: OK
N reads display_name; N-1 safe
CONTRACT
Lock: ACCESS_EXCLUSIVE (2s guard)
N-1: OK Β· N: OK
N-1 pods retired, drop full_name
PASS: Highest lock is SHARE_UPDATE_EXCLUSIVE with lock_timeout guard.
πŸ“¦Sample Codebase & Working Solution (Day 1)Available Now
View on GitHub

The official reference codebase for Day 1 is hosted in the repository. Clone the repository and navigate to tests/day1-migration-linter.spec.ts to run the working solution.

Git Clone β€” Working Solution
git clone https://github.com/777abhi/db-migration-qe-roadmap.git
cd db-migration-qe-roadmap/tests/day1-migration-linter.spec.ts
🏭Production Context & Enterprise Implementation
πŸ’‘ Why We Are Doing This: Even fast metadata DDL can cause outages if a long-running analytics query holds a read lock and your migration waits in the lock queue, blocking all subsequent reads and writes.
🏒 Real-World Production Usecase: Gating Flyway, Liquibase, Prisma, or raw SQL migrations in GitHub Actions PRs before they ever touch production.
βš™οΈ How Implemented in Production: AST/statement-level lock classifier enforcing SET lock_timeout, CONCURRENTLY index builds, and Expand-and-Contract safety.
Phase 1

Run & Inspect the SQL Migration Linter

Clone the standalone reference repository and run the Day 1 Vitest suite.

Step 1.1: Clone and Run Day 1 Tests
Terminal β€” Setup Day 1 Lab
git clone https://github.com/777abhi/db-migration-qe-roadmap.git
cd db-migration-qe-roadmap
npm ci
npm run test:day1
Step 1.2: Sample Codebase & Working Solution (Day 1)
src/linter/sqlMigrationLinter.ts
if (/^CREATE\s+(UNIQUE\s+)?INDEX\b/.test(upper) && !/\bCONCURRENTLY\b/.test(upper)) {
  recordLock('SHARE');
  findings.push({
    ruleId: 'INDEX_NOT_CONCURRENT',
    severity: 'HIGH',
    lockLevel: 'SHARE',
    message: 'CREATE INDEX without CONCURRENTLY acquires a SHARE lock, blocking all writes.',
    remediation: 'Use CREATE INDEX CONCURRENTLY (outside a transaction block).',
  });
}
Day 1 Key Learnings
  • Classified PostgreSQL/SQL lock levels (NONE, SHARE_UPDATE_EXCLUSIVE, SHARE, ACCESS_EXCLUSIVE).
  • Enforced SET lock_timeout guards to prevent lock-queue pile-ups.
  • Blocked unsafe NOT NULL additions, DROP COLUMN, ALTER TYPE, and unvalidated foreign keys.

🧠 Knowledge Check

Why is CREATE INDEX without CONCURRENTLY dangerous on a high-traffic production table?