Skip to content
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

Merged

Conversation

DavesBorges
Copy link
Contributor

Simple fix to #843. Now javascript sort function is used to both sort the executed migrations and the migrations to be executed.

Closes #843

Copy link

vercel bot commented Jan 15, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
kysely ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 5, 2025 1:23am

@koskimas
Copy link
Member

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.

@DavesBorges
Copy link
Contributor Author

Then perhaps choose the sort method based on allowUnordered migrations?

@koskimas
Copy link
Member

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.

@DavesBorges
Copy link
Contributor Author

@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
@DavesBorges
Copy link
Contributor Author

@koskimas I've found out why the tests haven't broken with allowUnordereMigrations enabled. The reason was the test migrations name were already in alphabetical order so I've added a test case where the migrations name are not in order to test that when migrating down it determines the migration order using the timestamps.

@igalklebanov igalklebanov added bug Something isn't working migrations Related to migrations postgres Related to PostgreSQL labels Jun 19, 2024
Copy link

pkg-pr-new bot commented Jan 5, 2025

Open in Stackblitzkysely_koa_example

npm i https://pkg.pr.new/kysely-org/kysely@844

commit: 2d8bcde

Co-authored-by: DavesBorges <[email protected]>
@igalklebanov igalklebanov merged commit bd5ded0 into kysely-org:master Jan 5, 2025
24 checks passed
@igalklebanov igalklebanov self-assigned this Jan 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working migrations Related to migrations postgres Related to PostgreSQL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Postgres migrateUp sometimes failing if migration name has a "-" character
3 participants