-
Notifications
You must be signed in to change notification settings - Fork 279
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
Add allowUnorderedMigrations
option to Migrator
#723
Add allowUnorderedMigrations
option to Migrator
#723
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Hey 👋 Thanks! 💪 I feel like |
That would definitely be clearer, good thinking. I'll update and post up the changes. |
migrationOrder
option to Migrator to allow out of order migrationsallowUnorderedMigrations
option to Migrator
@igalklebanov Done, and I updated the docs / comments too 👍 |
Hi @igalklebanov and @koskimas, I was just wondering if you've gotten a chance to look at this and what you think. Let me know if you've got any questions / requests 😄 Thanks! |
I think this is a really necessary change for coordinating across multiple teams, environments, and timezones. |
Yes can you please release this already 😭 |
ad5d746
to
463740a
Compare
This branch was out of date with |
This would be super helpful for our team's workflow! 😍 Hopefully it gets approved and merged soon (cc @igalklebanov @koskimas ) 🙏🏻 |
This would be really useful for my team as well, coordinating migrations is very tricky for us and this would solve all of our problems. Other than this little snag, Kysely has been absolutely incredible to use, thanks so much to the maintainers for writing such an incredible library!!! |
463740a
to
a363dee
Compare
Now that I have a week off from work, I finally have some time for Kysely and could review this one. @danolife We're not keeping these PRs waiting just to be mean or because we hate your team. We simply haven't had time. @tracehelms This seems excellent and will definitely get merged! Could you rebase this one more time? |
Hey @koskimas, thanks for reviewing! I'll get this rebased and patched up with your changes. 👍 |
a363dee
to
c46567e
Compare
Ready for another look @koskimas 👍 |
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.
Perfect!
Awesome, thanks for reviewing and merging! 💯 |
This is now released in 0.27.2 |
* naive version of allowing out of order migrations * refactor migrator.ts to allow the concept of pending migrations * fix test * add more tests * prettier * more test cases * add docs to getting started * clean up * change Migrator option to allowUnorderedMigrations * add a secondary order by name for migrations
@loremru this PR contains a unit test that proves it does. Thus makes me highly doubt your error has anything to do with this feature. |
@igalklebanov |
@loremru you're misunderstanding the feature. It is about not throwing migrator-specific errors if a new migration file is added that is in the middle of the sorted ran migrations. e.g. If PR 2 gets merged first, running the migrations once PR 1 is merged would fail because: [x] 0001 This feature makes it not fail. In your case, the migrations are poorly named. You should at least pad left with 0s. This probably results in sql errors, not migrator errors as the historic order is wrong between migrations that access the same resource. e.g. alter before create. |
What is this?
This add an
allowUnorderedMigrations
option toMigratorProps
. The options aretrue
orfalse
, withfalse
being the default.When true, it will allow new migrations to be run even if they are added alphabetically before ones that have already executed.
When false, it will give an error if your migration files are not alphabetically ordered in the same order that they were executed in the database.
Closes #697
Why?
If a team has multiple developers, two people can create migrations asynchronously on separate branches. With strict ordering, those migration files have to be merged in the right order (or renamed before merging) or else Kysely will throw an error when trying to migrate them.
Example:
Kysely will give an error for this with strict ordering. With permissive ordering, the unrun migration is executed.
Pending migrations vs. executed migrations
This also adds the concept of pending (unexecuted) migrations to Migrator. When migrating up, Migrator will run pending migrations in order for
n
steps. When migrating down, Migrator will consult the database for executed migrations and travel down that listn
steps.This doesn't change the current functionality for ensuring ordered migrations, but also allows out of order ones.
Some examples:
(
*
denotes current migration version)New migration:
Migrate down one:
New out-of-order migration:
Migrate down with out-of-order migration: