Test run migrations on a copy of the prod db

Hey !

I was wondering if anyone has a setup, reusable app, sample code, or more generally inputs/ideas about test-running migrations on a copy of the production db ?

The goal is to reduce the risk of failure in data-migrations, as it happens that migrations run fine in dev/tests, but then fail on prod due to the data (integrity errors, etc.).

I was thinking of something like manage.py migrate --test-first that would:

    1. create a test database (similarly to how the test framework creates a test database) using the prod database as a template
    1. run the migrations on the copy
  • 3a. if it succeeds, run the migrations on prod db
  • 3b. if it fails, don’t run the migrations
    1. delete the copy

Obviously that’s only suitable for small DBs, and for relatively simple projects, but would be quite practical.

Or otherwise how do you guys deal with potential migrations failures on prod ?

Cheers !!


We do daily backups of our databases for our larger production systems. (You do do regular backups, don’t you?) We then restore that data into our “staging” environment for testing all updates before a production deployment.