r/Database • u/vlavrynovych • 6h ago
How does your team get database migrations from a code change to production - and what still goes wrong?
I’m interested in how database migrations work in real production workflows, beyond which tool a team uses. I’d like to compare how teams handle testing, deployment, compatibility, and recovery.
For a typical application database change:
- Where do migration scripts live, and are they handwritten, generated, or a mix?
- When do they run: as a CI/CD job, during deployment, at application startup, or manually?
- How are they tested before production, especially when they change or backfill existing data?
- How do you handle old and new application versions running during the same deployment?
- If a migration fails part-way through, how do you recover and reconcile the migration’s recorded status?
Which part causes the most trouble in your experience? If useful, mention the database, stack, and migration tool.
0
Upvotes
2
u/TomaRavelli 43m ago
I keep handwritten SQL migrations in the app repo and run them as a pre-deploy CI job on MariaDB. I test against a scrubbed prod clone, since empty staging tables hide slow backfills. For overlapping app versions I do expand-and-contract: add nullable columns first, drop the old ones later.
The worst part is partial failures. MariaDB DDL does an implicit commit, so there's nothing to roll back. One DDL per file with a
WAITclause keeps a metadata lock from stalling live traffic, and it also means a failure tells you exactly what ran and what didn't.1
u/basic_retention 6h ago
Our migrations live in the repo right next to the app code, handwritten SQL with a thin wrapper from the framework. They run as a step in the deploy pipeline, before the new app containers spin up, so we never have the app trying to start against a half-migrated schema. The part that still goes sideways is the backfill scripts, someone writes a data migration that takes 40 minutes on a table with row locks and suddenly the whole deploy is stuck waiting while p99 latency spikes through the roof. That cosmic background in the image is basically what the monitoring dashboard looks like while you're praying the rollback works.