-
Notifications
You must be signed in to change notification settings - Fork 28
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
feat: sort migrations before applying #111
feat: sort migrations before applying #111
Conversation
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.
LGTM
Should check if order should be by file sort than className... |
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.
Hi @sf0rman, thank you very much for your input.
I have simply made a change to compare the className as a string with localeCompare
when sorting the migrations, This way we are not dependent on the format of the className which may change.
I'll generate a fix version with these changes right now!
Thanks again!
Edit: I messed up it with the localCompare
option, I have reverted to your original code in the version 1.6.2, it works perfectly. Thank you
Use localeCompare instead of relying on the format of the className that could change.
🎉 This PR is included in version 1.6.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Problem Description
Migration files are not ordered by timestamp when running
up
-command which can cause ordering issues.For example
Migration1: createCollection
Migration2: change stuff within collection
If not ordered, migration-stuff attempts to run first and fails due to dependency on Migration1 (or collection existing)
Solution
When creating a migration file, we know that all class names end with a 13-digit timestamp (
./lib/commands/new.ts:57
) regardless of using a custom template or the default one.We can therefore extract timestamp from className (last 13 digits of className) and sort migrations based on this before running migrations.