Skip to content

Commit cbfc397

Browse files
committed
Run database migrations in independent context
1 parent 31e1ec1 commit cbfc397

24 files changed

+86
-51
lines changed

API/Program.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,14 @@
9898
{
9999
Log.Information("Running database migrations...");
100100
using var scope = app.Services.CreateScope();
101-
var openShockContext = scope.ServiceProvider.GetRequiredService<OpenShockContext>();
102-
var pendingMigrations = openShockContext.Database.GetPendingMigrations().ToArray();
101+
102+
await using var migrationContext = new MigrationOpenShockContext(config.Db.Conn, config.Db.Debug);
103+
var pendingMigrations = migrationContext.Database.GetPendingMigrations().ToArray();
103104

104105
if (pendingMigrations.Length > 0)
105106
{
106107
Log.Information("Found pending migrations, applying [{@Migrations}]", pendingMigrations);
107-
openShockContext.Database.Migrate();
108+
migrationContext.Database.Migrate();
108109
Log.Information("Applied database migrations... proceeding with startup");
109110
}
110111
else

Common/Migrations/20240123062040_Initial.Designer.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Common/Migrations/20240304081753_AccountActivation.Designer.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Common/Migrations/20240308054253_AccountService.Designer.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Common/Migrations/20240319160003_DbCleanup.Designer.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Common/Migrations/20240327034706_Petrainer998DR.Designer.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Common/Migrations/20240503020144_AddPermissionTypes1.Designer.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Common/Migrations/20240709221359_Add API Token last used.Designer.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Common/Migrations/20240710020052_Fix last used.Designer.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Common/Migrations/20240710204029_DefaultValueForTokenLastUsed.Designer.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)