Skip to content

fix: guard ConfigureDbContext() Migrate() with IHistoryRepository (Galera-safe)#1412

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

fix: guard ConfigureDbContext() Migrate() with IHistoryRepository (Galera-safe)#1412
renemadsen merged 4 commits into
stablefrom
feat/ef-migration-helm-job

Conversation

@renemadsen
Copy link
Copy Markdown
Member

Summary

  • Wrap Database.Migrate() in ConfigureDbContext() with an IHistoryRepository.Exists() guard to eliminate unnecessary DDL on every API pod restart

Why

On a MariaDB 11.4 Galera cluster with ~250 tenants, Database.Migrate() issues DDL (CREATE TABLE IF NOT EXISTS __EFMigrationsHistory, GET_LOCK) on every app restart even when the schema is already current. With multiple pods per tenant this causes cluster-wide desync/resync on every rolling update.

The guard pattern:

  • IHistoryRepository.Exists() — safe information_schema read, returns false if history table is absent
  • GetPendingMigrations().Any() — only called when the table exists
  • Database.Migrate() — called only when needed: fresh install, or pending migrations

In production (schema current): no DDL, no GET_LOCK. On fresh plugin activation: falls through and creates the schema.

Test Plan

  • Plugin activates from UI correctly (schema created on first activation)
  • Subsequent pod restarts do not trigger DDL when schema is current

🤖 Generated with Claude Code

Avoids DDL on every API pod restart when plugin schemas are 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>
Copilot AI review requested due to automatic review settings June 2, 2026 15:59
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 updates the Workflow plugin startup database initialization to avoid running EF Core migrations (and the associated DDL/locks) on every API pod restart by guarding Database.Migrate() with an IHistoryRepository.Exists() check plus a pending-migrations check.

Changes:

  • Added EF Core infrastructure/migrations dependencies to access IHistoryRepository.
  • Wrapped context.Database.Migrate() behind !historyRepo.Exists() || context.Database.GetPendingMigrations().Any() to only migrate on fresh installs or when migrations are pending.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 154 to +158
var contextFactory = new WorkflowPnContextFactory();
var context = contextFactory.CreateDbContext(new[] { connectionString });
context.Database.Migrate();
var historyRepo = context.GetService<IHistoryRepository>();
if (!historyRepo.Exists() || context.Database.GetPendingMigrations().Any())
{
renemadsen and others added 3 commits June 2, 2026 18:55
The eform-angular-frontend checkout in CI does not have these directories
pre-created, causing cp to fail. Add mkdir -p to ensure they exist.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
LoginConstants.ts was removed from eform-angular-frontend stable but is
still imported by cypress/e2e/Login.page.ts. Vendor it in the plugin repo
and copy it into the frontend checkout in CI.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…adlessplugin

- workflow-playwright-test: mkdir e2e/Constants + copy LoginConstants.ts
  so cypress DB config test resolves the import
- workflow-test: replace missing testheadlessplugin npm script with a skip
  message (wdio plugin tests were migrated to workflow-playwright-test)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@renemadsen renemadsen merged commit 2abe5d1 into stable Jun 2, 2026
8 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