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

Shadow-Table Cutover & Data Parity Verifier
Zero-Downtime Schema Evolution β€” Day 4

Verify row counts, canonical row SHA-256 hashes, and rolling table checksums between source and shadow tables before executing an atomic cutover.

⚑ Runtime: Node.js 22 LTS Β· VitestπŸ›‘οΈ Database Reliability & Schema Evolution QE Architect
πŸ“¦Sample Codebase & Working Solution (Day 4)Available Now
View on GitHub

The official reference codebase for Day 4 is hosted in the repository. Clone the repository and navigate to tests/day4-shadow-parity.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/day4-shadow-parity.spec.ts
🏭Production Context & Enterprise Implementation
πŸ’‘ Why We Are Doing This: Row-count checks alone miss silent value drift (e.g., truncated strings, timezone shifts, or missed UPDATE triggers) during online shadow-table migrations like gh-ost or pg_repack.
🏒 Real-World Production Usecase: Pre-cutover verification gate comparing canonical SHA-256 row checksums between users and users_shadow.
βš™οΈ How Implemented in Production: Canonical key-sorted SHA-256 record hasher and rolling checksum verifier flagging MISSING_IN_SHADOW, EXTRA_IN_SHADOW, and CHECKSUM_DRIFT.
Phase 1

Run Shadow Parity Verification Tests

Step 4.1: Run Day 4 Tests
Terminal β€” Day 4 Lab
npm run test:day4
Step 4.2: Sample Codebase & Working Solution (Day 4)
src/parity/shadowParityVerifier.ts
export function hashRecord(record: TableRecord, ignoreKeys: string[] = []): string {
  const canonicalKeys = Object.keys(record)
    .filter((k) => !ignoreKeys.includes(k))
    .sort();
  const payload = canonicalKeys.map((k) => `${k}:${JSON.stringify(record[k])}`).join('|');
  return createHash('sha256').update(payload).digest('hex').slice(0, 16);
}
Day 4 Key Learnings
  • Computed canonical, key-order-independent SHA-256 hashes per row.
  • Detected silent value drift (CHECKSUM_DRIFT) even when row counts matched.
  • Produced deterministic READY_FOR_CUTOVER vs PARITY_DRIFT_DETECTED verdicts.

🧠 Knowledge Check

Why is comparing only COUNT(*) between source and shadow tables insufficient before cutover?