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.
π¦Sample Codebase & Working Solution (Day 4)Available Now
View on GitHubThe 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:day4Step 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?