kysely icon indicating copy to clipboard operation
kysely copied to clipboard

#843 - Use JS sort method to sort migrations by name

Open DavesBorges opened this issue 1 year ago • 6 comments

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

Closes #843

DavesBorges avatar Jan 15 '24 03:01 DavesBorges

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 Apr 21, 2024 10:18am

vercel[bot] avatar Jan 15 '24 03:01 vercel[bot]

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.

koskimas avatar Jan 15 '24 07:01 koskimas

Then perhaps choose the sort method based on allowUnordered migrations?

DavesBorges avatar Jan 15 '24 07:01 DavesBorges

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 avatar Jan 15 '24 16:01 koskimas

@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

DavesBorges avatar Jan 15 '24 16:01 DavesBorges

@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.

DavesBorges avatar Jan 17 '24 18:01 DavesBorges