Skip to content

feat: remove Database.Migrate() from startup — run via Helm Job instead#7924

Merged
renemadsen merged 2 commits into
stablefrom
feat/ef-migration-helm-job
Jun 2, 2026
Merged

feat: remove Database.Migrate() from startup — run via Helm Job instead#7924
renemadsen merged 2 commits into
stablefrom
feat/ef-migration-helm-job

Conversation

@renemadsen
Copy link
Copy Markdown
Member

Summary

  • Remove the GetPendingMigrations().Any() → Database.Migrate() block from eFormAPI.Web/Program.cs startup path
  • EF Core migrations for NNN_Angular are now run by the Helm pre-upgrade Job in helm-charts/work-items-planning-container-traefik (see microting/helm-charts#3)

Why

On a MariaDB 11.4 Galera cluster, every Database.Migrate() call at pod startup issues DDL that triggers Galera desync/resync. With 250 tenants and multiple pods per tenant, simultaneous migration checks cascade into a cluster-wide DDL storm. The Helm migration Job now handles this once per deployment.

⚠️ CI Note

CI workflows that bootstrap the Angular DB via the app startup will no longer get migrations applied automatically. Integration tests that depend on Program.cs applying migrations on startup will need to be updated to either call migrations directly in test setup, or run the migration bundle as part of CI setup.

Test Plan

  • Application starts cleanly without calling Database.Migrate()
  • Helm migration Job runs Angular DB migrations before the frontend pod starts
  • Remaining try block (menu item seeding) still executes correctly on startup

🤖 Generated with Claude Code

…rade Job

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 2, 2026 15:30
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR changes the eFormAPI backend startup behavior to stop running EF Core migrations automatically on application startup (previously GetPendingMigrations().Any() -> Database.Migrate() in Program.MigrateDb). This aligns with the operational goal of avoiding Galera cluster DDL storms by delegating migrations to an external Helm pre-upgrade Job.

Changes:

  • Removed the startup-time EF Core pending-migration check and Database.Migrate() call for the Angular DB.
  • Left the remaining startup DB “maintenance/seeding” logic (menu item security group seeding, etc.) in place.

Comment on lines 200 to 202
using var service = dbContext = scope.ServiceProvider.GetRequiredService<BaseDbContext>();
try
{
var connectionStrings =
scope.ServiceProvider.GetRequiredService<IOptions<ConnectionStrings>>();
if (connectionStrings.Value.DefaultConnection != "..." && dbContext.Database.GetPendingMigrations().Any())
{
Log.LogEvent("Migrating Angular DB");
dbContext.Database.Migrate();
}
}
catch (Exception e)
{
var logger = scope.ServiceProvider.GetRequiredService<ILogger<Program>>();
logger.LogError(e, "Error while migrating db");
}


try
…grateDb()

Avoids DDL on every pod restart when schema is current (Galera-safe).
Falls back to Migrate() on fresh install or when migrations are pending.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@renemadsen renemadsen merged commit fc2bf14 into stable Jun 2, 2026
15 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants