fix: always get the latest migration even when two are applied at the same time
without also ordering by migration_name, two migrations being applied at the same time *can* (but won't always) result in the *earlier* migration being returned as the latest one. as our migrations are not idempotent, this causes the bot to crash on startup (and even if they *were* idempotent, the code that inserts the new migration name into the migrations table isn't)
This commit is contained in:
parent
27e77eeaed
commit
4047df8610
1 changed files with 2 additions and 2 deletions
|
|
@ -141,7 +141,7 @@ public class DatabaseMigrator(ILogger logger, IClock clock, DatabaseConnection c
|
|||
if (hasMigrationTable)
|
||||
{
|
||||
return await conn.QuerySingleOrDefaultAsync<MigrationEntry>(
|
||||
"SELECT * FROM migrations ORDER BY applied_at DESC LIMIT 1"
|
||||
"SELECT * FROM migrations ORDER BY applied_at DESC, migration_name DESC LIMIT 1"
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -163,7 +163,7 @@ public class DatabaseMigrator(ILogger logger, IClock clock, DatabaseConnection c
|
|||
return await reader.ReadToEndAsync();
|
||||
}
|
||||
|
||||
public static IEnumerable<string> GetMigrationNames() =>
|
||||
private static IEnumerable<string> GetMigrationNames() =>
|
||||
typeof(DatabasePool)
|
||||
.Assembly.GetManifestResourceNames()
|
||||
.Where(s => s.StartsWith($"{RootPath}.Migrations"))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue