ASP.NET Core & Web API (50 Qs)•Part 2: Entity Framework Core, Security & High-Performance Data (11 - 24)
How do Database Migrations work in production without downtime?
mid LevelFormsPerformanceSecurity & Auth
In Simple Words:
Never call context.Database.Migrate() on application startup in production (risk of concurrency race conditions when multiple pods start simultaneously).
- Generate idempotent SQL scripts:
dotnet ef migrations script -i -o migrate.sql. - Run the migration script in your CI/CD deployment pipeline before deploying new pods.
- Follow the Expand/Contract schema pattern.