From 01f99cfff3205e8bb1c9c2b158a4cfccefabc338 Mon Sep 17 00:00:00 2001 From: nurdotnet <278048682+nurdotnet@users.noreply.github.com> Date: Wed, 22 Apr 2026 16:03:01 +0500 Subject: [PATCH] fix(api): always apply EF migrations on startup, not only in Development MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- src/food-market.api/Program.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/food-market.api/Program.cs b/src/food-market.api/Program.cs index 7a19a34..f152ff2 100644 --- a/src/food-market.api/Program.cs +++ b/src/food-market.api/Program.cs @@ -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(); db.Database.Migrate(); }