Skip to content

fix: guard SqlController Migrate() with IHistoryRepository.Exists()#4664

Merged
renemadsen merged 1 commit into
masterfrom
feat/ef-migration-helm-job
Jun 2, 2026
Merged

fix: guard SqlController Migrate() with IHistoryRepository.Exists()#4664
renemadsen merged 1 commit into
masterfrom
feat/ef-migration-helm-job

Conversation

@renemadsen
Copy link
Copy Markdown
Member

Summary

Add IHistoryRepository.Exists() guard around Database.Migrate() in SqlController so DDL is only issued when actually needed.

Why

The existing GetPendingMigrations().Any() guard throws (and re-throws) if __EFMigrationsHistory doesn't exist yet, crashing startup on a fresh SDK DB. With the IHistoryRepository.Exists() outer guard:

  • Fresh install: Exists() = false → falls through to Migrate() → creates schema ✅
  • Schema current (production): Exists() = true, GetPendingMigrations() = empty → skips entirely, no DDL, no GET_LOCK
  • Pending migrations: Exists() = true, pending found → Migrate() applies them ✅

On a Galera cluster with ~250 tenants, this eliminates SDK DDL from every pod restart.

Test Plan

  • Fresh SDK DB: migrations run and schema is created
  • Existing SDK DB (schema current): no DDL on restart

🤖 Generated with Claude Code

Prevents crash on fresh install if __EFMigrationsHistory is absent.
In production (schema current): Exists()=true, GetPendingMigrations()=empty,
Migrate() is never called — no DDL, Galera-safe.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@renemadsen renemadsen merged commit 97d82de into master Jun 2, 2026
12 of 13 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