2 ms·
I take the approach of storing the name of any migrations run in the database in a metadata table - this means you can run them out of order, restore from a bac
by grey-area 9y ago
I take the approach of storing the name of any migrations run in the database in a metadata table - this means you can run them out of order, restore from a backup then run migrations not yet run etc. to test or adjust them. With multiple devs it's often the case that we want to run things out of order on production too, so ordering by time doesn't work and running manually is error-prone.
Code for this here - it'd be pretty simple to put it in its own little tool or even a bash script or something, and there are surely some other tools that do something similar... This one psql only as it relies on the psql binary to load the sql, but hopefully gives you the idea. I haven't bothered developing it further to do things like run a single migration or down migrations as haven't required that so far.
https://github.com/fragmenta/fragmenta/blob/master/migrate.go https://github.com/fragmenta/fragmenta/blob/master/migrate.g...