← Back to articles
Technology

Rehearse Data Migrations at Production Scale

Rehearse Data Migrations at Production Scale

A migration script that runs cleanly on 100 rows can fall apart on a few million in production. It stops on a value nobody expected, takes many times longer than planned, or dies halfway and leaves partial data behind. This article is about the release phase: how to rehearse a migration at production scale so that duration, recovery, and verification are settled before the real run.

Why It Passes Small and Fails Big

Small test data contains only the values its author could imagine. Production contains things like:

  • NULLs, empty strings, strings longer than expected, values saved under an old spec
  • Records from years ago with different encodings or date formats
  • Rows that no longer match other tables, or point to deleted records

Volume is a separate problem. Updating one row at a time is instant for 100 rows and takes hours for 5 million. Memory exhaustion and long-held locks that block normal traffic also show up only at scale.

Four Things to Check in the Rehearsal

1. Duration

Run to completion with a production-like row count and measure the time. Decide here whether it fits the maintenance window, and whether you need batching or parallelism.

2. Recovery from a Mid-Run Failure

Stop the run on purpose. Then re-run it and check that nothing is inserted twice and that it can continue from where it stopped. To make a migration resumable, either record what has been processed or write it so that running it repeatedly gives the same result.

-- Example: safe to re-run
INSERT INTO new_users (id, name, created_at)
SELECT id, name, created_at FROM old_users
ON CONFLICT (id) DO NOTHING;

3. Before/After Reconciliation

"It finished without errors" is not proof of success. Compare counts and totals before and after.

-- Count check
SELECT (SELECT COUNT(*) FROM old_users) AS before_cnt,
       (SELECT COUNT(*) FROM new_users) AS after_cnt;

-- Totals check (amounts, etc.)
SELECT SUM(amount) FROM old_orders;
SELECT SUM(amount) FROM new_orders;

-- Find rows that were missed
SELECT o.id FROM old_users o
LEFT JOIN new_users n ON n.id = o.id
WHERE n.id IS NULL LIMIT 20;

4. Surfacing Unexpected Values

Running against an anonymized copy of production turns up values your test data never had. Add each one to the migration rules right away. Decide in advance what happens to a row that cannot be converted: stop, skip and log it, or fill a default.

The Runbook for the Real Day

Turn what the rehearsal settled into the runbook for the real run, and read it through together the day before.

  1. Preparation: take a backup and confirm it can be restored
  2. The exact commands, who runs them, and who verifies
  3. Expected time per stage, and a "stop if not done by here" line
  4. Reconciliation queries and the pass criteria
  5. How to roll back, and who to notify

Use the same runbook in the rehearsal. Every place where the run did not follow it becomes a fix.

Common Failures

  • Staging holds a few hundred rows, so duration was never measured
  • Reconciliation done by eye, missing a 1% gap
  • No resume procedure, so a stopped run is restarted from scratch and creates duplicates
  • One developer rehearses alone, and the person running it on the day has never seen the steps

Putting It into Practice with Bugoon

Display glitches and data differences noticed during the rehearsal or right after the real run tend to get scattered across chat and email. Embed the Bugoon widget in your verification environment, and the QA or support people taking part can report from the very screen where they noticed, with a screenshot and annotations. Operation steps are recorded too, so a report such as "on this screen after migration, this action shows a wrong value" arrives with reproduction steps. Reports become GitHub Issues, and the kanban board shows their status at a glance, so you can follow findings from the rehearsal through to the runbook fix in one place.

Streamline bug reporting for your team.

Bugoon is free to get started. Add one line of code to your site and transform how your team handles bugs.

Get Started