fix(api): always apply EF migrations on startup, not only in Development
Stage deploy crashed in CrashLoopBackoff because the production container landed on an empty fresh Postgres, then OpenIddictClientSeeder hit "relation public.OpenIddictApplications does not exist". The Migrate() call was guarded by IsDevelopment() so prod never bootstrapped. Migrations are idempotent — running them every startup is the standard pattern for SaaS containers (no separate migrate-then-app step needed). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
75d73b9dcd
commit
01f99cfff3
|
|
@ -187,9 +187,10 @@
|
|||
});
|
||||
}).RequireAuthorization();
|
||||
|
||||
if (app.Environment.IsDevelopment())
|
||||
// Apply migrations on every startup (idempotent). Without this, fresh
|
||||
// stage/prod deploys land on an empty DB and OpenIddict seeders fail.
|
||||
using (var scope = app.Services.CreateScope())
|
||||
{
|
||||
using var scope = app.Services.CreateScope();
|
||||
var db = scope.ServiceProvider.GetRequiredService<AppDbContext>();
|
||||
db.Database.Migrate();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue