You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 the timestamp and secondarily the name 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 used
in the ORDER BY clause.
Example.
We have the following pending migrations:
2024-01-01-create-table
2024-01-01.2-update-table
After running migrator.migrateToLatest() We get the following values in the table (the timestamps are the same)
name
Timestamp
2024-01-01-create-table
2024-01-01T00:00:00.000Z
2024-01-01.2-update-table
2024-01-01T00:00:00.000Z
When migratetoLatest() is called again without allowUnorderedMigrations set to true
it will fail in version 0.27.2 and prior versions because the index of the candidate
migrations and the executed migrations won't match
index
candiate Migrations
executed_migrations (as read from db)
0
2024-01-01-create-table
2024-01-01.2-update-table
1
2024-01-01.2-update-table
2024-01-01-create-table
The text was updated successfully, but these errors were encountered:
timestamp in the migrations table doesn't come from the file name. It's the execution time of the migration.
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
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: