revert: Back to simple MigrateAsync - it's already idempotent
All checks were successful
Build and Deploy to Kubernetes / build-and-deploy (push) Successful in 2m5s
All checks were successful
Build and Deploy to Kubernetes / build-and-deploy (push) Successful in 2m5s
MigrateAsync is smart enough to: - Create DB if it doesn't exist - Apply only pending migrations - Skip if DB is up to date The orphaned CMS.mdf files were cleaned from SQL Server.
This commit is contained in:
@@ -23,25 +23,7 @@ public class ApplicationDbContextInitialiser
|
||||
{
|
||||
if (_context.Database.IsSqlServer())
|
||||
{
|
||||
// Use EnsureCreated for initial setup, then apply migrations
|
||||
// EnsureCreated is idempotent - safe to call multiple times
|
||||
var created = await _context.Database.EnsureCreatedAsync();
|
||||
|
||||
if (!created)
|
||||
{
|
||||
// Database exists, check for pending migrations
|
||||
_logger.LogInformation("Database already exists, checking for migrations...");
|
||||
var pending = await _context.Database.GetPendingMigrationsAsync();
|
||||
if (pending.Any())
|
||||
{
|
||||
_logger.LogInformation("Applying {Count} pending migrations", pending.Count());
|
||||
await _context.Database.MigrateAsync();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogInformation("Database created successfully");
|
||||
}
|
||||
await _context.Database.MigrateAsync();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
Reference in New Issue
Block a user