Browse Source

fix migrations for new databases (#2217)

pull/2218/head
Jason Dove 3 weeks ago committed by GitHub
parent
commit
00f40c2568
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 14
      ErsatzTV/Services/RunOnce/DatabaseMigratorService.cs

14
ErsatzTV/Services/RunOnce/DatabaseMigratorService.cs

@ -40,15 +40,19 @@ public class DatabaseMigratorService : BackgroundService
await dbContext.Database.MigrateAsync("Add_MediaFilePathHash", stoppingToken); await dbContext.Database.MigrateAsync("Add_MediaFilePathHash", stoppingToken);
} }
// this can't be part of a migration, so we have to stop here and run some sql List<string> appliedMigrations = await dbContext.Database
await PopulatePathHashes(dbContext); .GetAppliedMigrationsAsync(stoppingToken)
.Map(l => l.ToList());
// then continue migrating if (appliedMigrations.Count > 0)
if (pendingMigrations.Count > 0)
{ {
await dbContext.Database.MigrateAsync(stoppingToken); // this can't be part of a migration, so we have to stop here and run some sql
await PopulatePathHashes(dbContext);
} }
// then continue migrating
await dbContext.Database.MigrateAsync(stoppingToken);
await DbInitializer.Initialize(dbContext, stoppingToken); await DbInitializer.Initialize(dbContext, stoppingToken);
_systemStartup.DatabaseIsReady(); _systemStartup.DatabaseIsReady();

Loading…
Cancel
Save