-
Notifications
You must be signed in to change notification settings - Fork 284
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
Postgres migrateUp sometimes failing if migration name has a "-" character #843
Comments
You should really use full ISO date-time strings in your migration names. Not just the dates. But we should sort the migrations using javascript as you suggested 👍. Databases sort things differently depending on the collation. |
Yes. In that scenario they were the same because we assume that they run very fast one after the other (or the system clock was unrelibable) and so they endup being the same date in the timestamp column |
…ns enabled This is needed to test if migrating down works when the up migrations were not executed in alphabetical order
Co-authored-by: DavesBorges <66228145+DavesBorges@users.noreply.github.com> Co-authored-by: Igal Klebanov <igalklebanov@gmail.com>
Description
In versions of kysely < 0.27.2, if migration names have a "-" character (beyond the usual ISO date string), running
migrateToLatest
against a postgres database might fail even if it had previously succeeded.The postgres
ORDER BY
ignores "-" character when ordering strings (while javascript sort method considers it when sorting strings) causing the order of executed migrations returned from database and the order of candidate migrations to not be the same.Since 0.27.2 this issue is less likely to occur because when
querying for executed migrations the
ORDER BY
uses thetimestamp
and secondarily thename
column to order executed migrations (introduced in #723).But it can still occurr if the system where the migrations are being
runned is extremly fast or the system clock is unreliable causing the timestamps to be the same.
That would result in the ordering of migrations being the same as if only the
name
column were usedin the
ORDER BY
clause.Example.
We have the following pending migrations:
After running
migrator.migrateToLatest()
We get the following values in the table (the timestamps are the same)When
migratetoLatest()
is called again withoutallowUnorderedMigrations
set to trueit will fail in version
0.27.2
and prior versions because the index of the candidatemigrations and the executed migrations won't match
The text was updated successfully, but these errors were encountered: