-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP : Implement more migration features, fix a rollback all bug #3169
Conversation
… --to flag to specify a specific migration
…n --to flag to specify a migration (exclusive)
@leeallen337 Could you please split this in multiple PRs, each of which would address just one thing? |
@@ -202,13 +202,39 @@ function invoke(env) { | |||
.catch(exit); | |||
}); | |||
|
|||
commander | |||
.command('migrate:up') | |||
.description(' Run the next migration.') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Description seems inaccurate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are your thoughts on Run the next chronological migration that has not yet been run.
?
@@ -222,6 +248,29 @@ function invoke(env) { | |||
.catch(exit); | |||
}); | |||
|
|||
commander | |||
.command('migrate:down') | |||
.description(' Rollback the last migration performed.') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Description seems inaccurate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are your thoughts on Undo the last previous migration performed.
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm more concerned about
a) usage of --to flag making description completely incorrect;
b) difference between last migration and last migration batch being not emphasized enough;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see what you mean. That makes complete sense! When working on a pull request for this I'll try and think of a more accurate and all encompassing description 👍
Bugfix for rollback order is very much welcome and would probably warrant one more release in 0.16.x line just for that change alone. --up and --down commands make sense to me. Could you please explain how differently --all is supposed to work from just a simple rollback? |
Oh, and documentation should be updated here: https://github.com/knex/documentation |
@kibertoad Happy to split these up. I'll make some new smaller individual pull requests to break these up. I'll tackle the bugfix rollback order one first since that's a bugfix rather than a new feature.
If you had batch 1, batch 2, and batch 3, you would have to run |
Appreciate it! |
@kibertoad I created a separate pull request for the I'm thinking of leaving this pull request open to serve as kind of a table of contents and documentation for these smaller ones I'm making. I can close this one after all these smaller ones have been finished. How does that sound? I also don't want to clog up the list of pull requests either so I could just go ahead and close this now too. Let me know what you think |
@leeallen337 Sure, no problem! Appreciate the contribution :) |
Is anything still left? |
@kibertoad Just a couple more things. The |
} | ||
|
||
const indexOfToMigration = findIndex(migrationCopy, (migration) => { | ||
return migration.file === toFile; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assume we have following migrations:
- 20001101000001_initial.js
- 20001102000002_migration1.js
- 20001103000003_migration2.js
Here is we have three possible migrate 'up/down to' cases:
- to filename - 20001102000002_migration1.js
- to timestamp (equal to) - 20001102000002
- to timestamp (lower / upper bound)
- up to 20001103000000 = migrationsToRun: [20001101000001_initial.js, 20001102000002_migration1.js]
- down to 20001102000000 = migrationsToRun: [20001103000003_migration2.js, 20001102000002_migration1.js]
- use short form 20001103, or pattern 2000??03, or regexp: 20001103.*.js
Actually you are running migration to exactly specific file name.
What do you think about other cases ?
This pull request aims to address a few issues (e.g. feature request and a bug) that I will elaborate on below.
rollback all running in wrong order #3131 - This bug looks like when trying to rollback all migrations it's running them in chronological order and, I think, attempting to rollback all migrations and not just the ones completed. From this line in theMigrator
,val[0]
I think is a list of all migrations in chronological order rather than only attempting to rollback the completed migrations in reverse chronological order.See Bugfix/rollback all wrong order #3172 for a pull request which address this specific bugfix
Migrate to version #352, Migrate to the desired migration. #1550 and It would be great to be able to run an individual migration up/down #666 - These issues are requests to support migrating or down to specific versions and just migrating up one migration at a time or rolling back one migration at a time. I've implemented functionality to run
migrate:up
ormigrate:down
, which will migrate only the next migration or rollback only the last migration, respectively. There is also an optional--to
flag which you can specify a specific the filename of the migration to migrate to (inclusive) or rollback to (exclusive) which I think addresses the issue.Feature request: migrate:reset #783 - I also add in the--all
flag to themigrate:rollback
cli command which I think would address this issueSee pull request Feature/add rollback all to cli #3187
Knex migrations refresh #2907 - This issue is kind of addressed. There's not a command to rollback everything and run latest in one command but a combination ofmigrate:rollback --all
andmigrate:latest
would address this issueSee pull request Feature/add rollback all to cli #3187
I've marked this issue as still a work in progress for a few reasons.
Possible ToDos: