Skip to content

Commit

Permalink
Handle Dot Net 9 upgrade PendingModelChangesWarning for AB#16871
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianMaki committed Dec 4, 2024
1 parent 0142fac commit e9a81e8
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions Apps/JobScheduler/src/Jobs/DbMigrationsJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
// -------------------------------------------------------------------------
namespace HealthGateway.JobScheduler.Jobs
{
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Hangfire;
Expand Down Expand Up @@ -50,9 +52,32 @@ public DbMigrationsJob(ILogger<DbMigrationsJob> logger, GatewayDbContext dbConte
[DisableConcurrentExecution(ConcurrencyTimeout)]
public async Task MigrateAsync(CancellationToken ct = default)
{
this.logger.LogInformation("Applying database migrations");
await this.dbContext.Database.MigrateAsync(ct);
this.logger.LogInformation("Applied database migrations");
const string jobName = nameof(this.MigrateAsync);

this.logger.LogInformation(
"Job '{JobName}' - Checking for pending database migrations",
jobName
);

// Retrieve all migrations that are defined in the application's assembly
IEnumerable<string> pendingMigrations = await this.dbContext.Database.GetPendingMigrationsAsync(ct);

if (pendingMigrations.Any())
{
this.logger.LogInformation(
"Job '{JobName}' - Pending migrations found. Applying database migrations...",
jobName
);
await this.dbContext.Database.MigrateAsync(ct);
this.logger.LogInformation("Applied database migrations successfully");
}
else
{
this.logger.LogInformation(
"Job '{JobName}' - No pending migrations found. Skipping migration step",
jobName
);
}
}
}
}

0 comments on commit e9a81e8

Please sign in to comment.