Verifying a Data Migration with Queries

Before and after counts and representative comparisons can show whether a migration preserved identities, relationships, and expected new constraints.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
1 min
In this article4 chapters
  1. Trace a new required field
  2. Check more than counts
  3. Check identities and representative values as well as total counts
  4. Test with older rows and normal application readers

Trace a new required field

Count rows with unsupported missing values before enforcement. Compare older records after filling the field and verify new inserts consume the intended default. Evolving an existing schema gives the multi-version problem.

Check more than counts

Two equal counts can hide a replaced or disconnected row. Compare stable IDs and sample joined values. Foreign keys describe one preserved relationship.[1]

Check identities and representative values as well as total counts

A migration converts durations from seconds to milliseconds. Equal row counts before and after cannot expose a uniform factor error. Check old and new values by stable identity and inspect exceptions such as absent durations. See units in database columns.

Row A: 2 seconds → 2000 milliseconds
Row B: 0 seconds → 0 milliseconds
Row C: missing → stays missing under chosen policy
Aggregate counts by migration state and investigate differences

Test with older rows and normal application readers

A query-level check can confirm the transformed data. A page or export reading it verifies the consumer uses the right unit. Include a dry run and compare identity preservation.

References

  1. PostgreSQL Global Development Group, Queries ↩