cli
cli copied to clipboard
"sequelize db:migrate:undo" always rollback at least one file even if it is not necessary
i'm sorry if this is not the correct place to post it (if so please point me to the right direction..)
We have a migration folder with all of our migration files, And in our build pipeline in Jenkins, we run the migration at some point (sequelize db:migrate), and then later, if the build fails for some reason we run the rollback (sequelize db:migrate:undo)
recently we've noticed a weird behaviour, so i did a small test: I added a new migration file (that both its up and down don't really do anything), i tried to run the build, it ran the migration (at that point i could see the new migration name appear the DB table of finished migrations), then the build failed, the rollback ran and at the end i could see the migration name was removed from the DB so far all good. then i manually added the name back to DB, assuming this will make this new migration not to run (which it did not) in the next build migration part - and i assumed also not to rollback if the build failed - and here is the problem - after the build failed, and the rollback ran - the line in the DB i added manually was removed.. as if it always has to roll back at least 1 file or something..
again, sorry if this is the wrong place to write this, but we need help here..
thanks
db:migrate:undo does indeed execute the down function of the last migration that was done, regardless if there was a migration done in the same build.
If I understand your problem correctly, it might be good to only run db:migrate:undo if there is actually a new migration that ran in the build. Do note that it only undoes one migration, so if you have multiple new migrations in the same build you need to run the command multiple times. This is something that you could change to your pipeline, do you think that might be a good solution?
Hi @giladgreen did I answer your questions? Or can I still help you with anything?