Skip to content

Commit 22a3309

Browse files
committed
Add a Migration step on startup
1 parent 4a24e53 commit 22a3309

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/MaintenanceLog/DatabaseUtility.cs

+15-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using MaintenanceLog.Data;
1+
using MaintenanceLog.Data;
22
using Microsoft.EntityFrameworkCore;
33

44
namespace MaintenanceLog;
@@ -17,11 +17,19 @@ public static async Task EnsureDbCreatedAndSeedWithDefaults(DbContextOptions<App
1717
{
1818
Console.WriteLine("Database already exists or was not otherwise created.");
1919
}
20-
// if ((await context.Database.GetPendingMigrationsAsync()).Any())
21-
// {
22-
// // not good with distributed UI... but for now...
23-
// Console.WriteLine("Applying migrations...");
24-
// await context.Database.MigrateAsync();
25-
// }
20+
21+
try
22+
{
23+
if ((await context.Database.GetPendingMigrationsAsync()).Any())
24+
{
25+
// not good with distributed UI... but for now...
26+
Console.WriteLine("Applying migrations...");
27+
await context.Database.MigrateAsync();
28+
}
29+
}
30+
catch (Exception ex)
31+
{
32+
Console.WriteLine($"Error applying migrations: {ex.Message}");
33+
}
2634
}
2735
}

0 commit comments

Comments
 (0)