-
Notifications
You must be signed in to change notification settings - Fork 250
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
#843 - Use JS sort method to sort migrations by name #844
base: master
Are you sure you want to change the base?
#843 - Use JS sort method to sort migrations by name #844
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
This now breaks the sorting by timestamp. Out-of-order migrations can be executed in different order than the name order. That's why the primary ordering is by timestamp. |
Then perhaps choose the sort method based on allowUnordered migrations? |
All you need to do is sort using the same logic as the SQL. Sort by timestamp and if the timestamps are equal, sort by name. |
@koskimas I will add more tests for the out of order migration because the current tests didn't break when I ordered the executed migrations only by name |
…ns enabled This is needed to test if migrating down works when the up migrations were not executed in alphabetical order
@koskimas I've found out why the tests haven't broken with |
return executedMigrations | ||
.sort((a, b) => { | ||
if (a.timestamp === b.timestamp) { | ||
return a.name < b.name ? -1 : 1 |
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.
change to localeCompare.
let originalToIsoString: typeof Date.prototype.toISOString | ||
|
||
before(() => { | ||
originalToIsoString = Date.prototype.toISOString | ||
const defaultDateIsoString = new Date(2024, 0, 11).toISOString() | ||
Date.prototype.toISOString = () => defaultDateIsoString | ||
}) | ||
|
||
after(() => { | ||
// Reset to originalToIsoString function so that upcoming tests are not affected | ||
Date.prototype.toISOString = originalToIsoString | ||
}) |
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.
This is not clean, too coupled with implementation detail.
Use sinon fake timers instead to freeze time in a predictable way.
Simple fix to #843. Now javascript sort function is used to both sort the executed migrations and the migrations to be executed.
Closes #843