tj / node-migrate

Abstract migration framework for node
MIT License
1.53k stars 221 forks source link

Migration down does not work correctly #172

Open xfg opened 4 years ago

xfg commented 4 years ago

Hello. I created the test repo on which I am testing the current library.

I run migrate up command and get next output

up : 1585061628701-1.js
up 1 migration
  up : 1585061705214-2.js
up 2 migration
  up : 1585061975014-3.js
up 3 migration
  migration : complete

Everything works as it should but now I run migrate down 1585061705214-2 and get

down : 1585061975014-3.js
down 3 migration
  migration : complete

It is not right since the 1585061705214-2 migration should have rolled back too based on this quote from the documentation

Similarly you can run down-migrations up to (and including) a specific migration

and if after it I run migrate down 1585061975014-3 which was rolled back above I get

down : 1585061705214-2.js
down 2 migration
  migration : complete

That's very strange.

And the last.

If we have two branches and the migrations 1585061628701-1 and 1585061975014-3 were created and applied in first branch, and the migration 158506170521414-2 was created in the other branch, which was created earlier than 1585061975014-3, then when the second branch merges with the first and call migrate up and then migrate down 1585061705214-2 everything will break down and we won’t be able to roll back to any specific migration except migrate down.

wesleytodd commented 4 years ago

Hey @xfg, would you be willing to make a test case for this behavior as a PR? I believe the report, just would make it easier to fix quickly if there was a test written.