MCPcopy Create free account
hub / github.com/TryCatchLearn/Overflow / MigrationRunner

Class MigrationRunner

Common/MigrationRunner.cs:8–29  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6namespace Common;
7
8public static class MigrationRunner
9{
10 public static async Task MigrateDbContextAsync<TContext>(this IHost host)
11 where TContext : DbContext
12 {
13 using var scope = host.Services.CreateScope();
14 var services = scope.ServiceProvider;
15 var loggerFactory = services.GetRequiredService<ILoggerFactory>();
16 var logger = loggerFactory.CreateLogger(typeof(MigrationRunner));
17 try
18 {
19 var context = services.GetRequiredService<TContext>();
20 await context.Database.MigrateAsync();
21 }
22 catch (Exception ex)
23 {
24 logger.LogError(ex, "An error occured during migration");
25 }
26
27 logger.LogInformation("✅ Migration complete for {Name}", typeof(TContext).Name);
28 }
29}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…