kawadhiya21 / mysql-migrations

A tool to use with mysql package to maintain migrations
MIT License
31 stars 25 forks source link

Not executing the old pending migration. #1

Closed the-yadu closed 7 years ago

the-yadu commented 7 years ago

I have 2 migrations

  1. 1502687997145_create_X_table.js
  2. 1501765435866_create_Y_table.js

Migration y_table was created before the x_table but was committed later.

With every deploy in production, we have a script to run migrations up. So Y_table migration was executed first

Later I committed x_table migration, and the ran the migration command again with deploy. The x_table migration is not getting executed. The table in MySQL does not contain the row of x_table migration.

Is the migrations execution depends only on time? Ideally, it should execute all the pending migrations, right?

kawadhiya21 commented 7 years ago

Umm no. In my understanding, the numbers assigned should work like a story line. So it should always execute in increasing order. Let me give you another scenario:

  1. 2_create_table1.js (gets committed and executed)
  2. 4_update_table1.js (remains pending in some abc unmerged branch)
  3. 5_drop_table1.js (get committed and executed)

If at a later date, abc is merged with master branch, do you expect the 4_update_table1.js to run smoothly? Definitely No.

Before you decide to add a migration, you need to fetch and merge the master branch, execute all the migrations and only then add your new migrations to avoid a collision.

the-yadu commented 7 years ago

According to my understanding, it should run all the pending migrations because every time I commit the code I have to pull changes, which will bring the 5_drop_table1.js into my local. Now If I run migrations on my local it should drop my table.(5_drop_table1.js) Now it should be my headache to fix my 4_update_table1.js and then commit the code.

Correct me If I am wrong.

And 1 more request. Please console out the output of migrations run. Thanks for making this. I needed it.

kawadhiya21 commented 7 years ago

I went through few other migration managers and your concern is a valid one. Unfortunately, I cannot address this issue in the current version. This also means that no new version will be published for this major version. Version 2.0.0 will have this feature along with few other fixes related to logging etc.

I will also include an extra script to migrate from v1.x.x to v2.

Will try to publish it in a week. Thanks

kawadhiya21 commented 3 years ago

This has been fixed.