dbmate icon indicating copy to clipboard operation
dbmate copied to clipboard

Add option for migrate/down to apply/rollback specific migration

Open jfedyczak opened this issue 5 years ago • 8 comments

Would be nice if I could specify which migration to run. E.g.:

dbmate migrate 20200213212633
dbmate down 20200213212633

jfedyczak avatar Feb 14 '20 12:02 jfedyczak

I think it is a must - not nice to have.

gudata avatar May 07 '20 15:05 gudata

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?

jayarjo avatar May 25 '20 13:05 jayarjo

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 avatar May 25 '20 22:05 amacneil

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.

jayarjo avatar May 26 '20 06:05 jayarjo

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?

amacneil avatar May 27 '20 13:05 amacneil

Yes, in between test suites, to restore fresh database state.

jayarjo avatar May 27 '20 19:05 jayarjo

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.

amacneil avatar May 28 '20 15:05 amacneil

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.

jayarjo avatar May 28 '20 15:05 jayarjo