dbmate
dbmate copied to clipboard
Add option for migrate/down to apply/rollback specific migration
Would be nice if I could specify which migration to run. E.g.:
dbmate migrate 20200213212633
dbmate down 20200213212633
I think it is a must - not nice to have.
At the moment I do something like this:
seq `ls /migrations | wc -l` | xargs -I INDEX \
dbmate --no-dump-schema --migrations-dir /migrations down
to migrate down completely. It works, but it's slow like hell. Anyone any ideas how to make it faster?
Out of interest, why are you migrating down completely? If it's a test harness or something it would be a lot faster to drop and recreate the database.
Out of interest, why are you migrating down completely? If it's a test harness or something it would be a lot faster to drop and recreate the database.
@amacneil dbmate doesn't drop when there are open connections established to the database, but can migrate down/up. I would use drop I think, if I could.
Can you share why/when you are migrating down completely though? Is it at the start of your tests, or between each test, or something else?
Yes, in between test suites, to restore fresh database state.
Makes sense. I'm not sure whether you considered this, but in the past when running test suites I just drop and recreate the database once at the very start (before my test harness connects to the db), then run a command like TRUNCATE tablea, tableb, tablec CASCADE
in between each test suite. It's much faster than running all the migrations for every test.
Yeah, that's what I ended up with at the moment. Also since I run db in docker container - stopping it and running anew might also be faster.