Skip to content

Introduce EF Core migrations with legacy database baseline detection#364

Merged
Wiesenwischer merged 1 commit intomainfrom
feature/ef-core-migrations
Apr 14, 2026
Merged

Introduce EF Core migrations with legacy database baseline detection#364
Wiesenwischer merged 1 commit intomainfrom
feature/ef-core-migrations

Conversation

@Wiesenwischer
Copy link
Copy Markdown
Owner

Summary

Fixes a production outage on test-ux-dokker after v0.61: SQLite Error 1: 'no such column: s.RegistryPassword'.

Root cause: the schema was created via EnsureCreated() which only works for fresh databases. Adding new columns (like the OCI registry fields in v0.61) broke existing installations.

Changes

  • Design-time factory (DesignTimeDbContextFactory) for dotnet-ef tooling
  • InitialCreate migration representing the pre-v0.61 schema (without OCI columns) — the baseline for existing installations
  • AddOciRegistrySource migration — 5 ALTER TABLE ADD COLUMN statements for the OCI fields
  • Explicit column configuration in StackSourceConfiguration for all OCI properties
  • MigrateDatabase() replaces EnsureDatabaseCreated() in Program.cs, with legacy database detection:
    1. Tables exist but __EFMigrationsHistory doesn't → insert InitialCreate entry as baseline
    2. Run Migrate() → applies subsequent migrations (AddOciRegistrySource) against the existing schema
    3. Fresh DBs get both migrations; already-migrated DBs get only new ones

Test plan

  • 4 new MigrationBaselineTests: fresh DB, legacy DB, data preservation, idempotency
  • 2870 unit tests pass
  • 402 integration tests pass (CustomWebApplicationFactory updated to use Migrate())
  • Zero compile errors

Upgrade behavior

Existing installs (like test-ux-dokker) will on next startup:

  1. Detect __EFMigrationsHistory doesn't exist → insert InitialCreate as applied
  2. Run AddOciRegistrySource → adds 5 OCI columns
  3. Data is preserved, no manual intervention needed

Before this change, the schema was created via EnsureCreated(), which
only works for brand new databases. Adding new columns (like the OCI
registry fields added in v0.61) broke existing installations with
"no such column" errors at runtime.

Changes:
- Add IDesignTimeDbContextFactory for dotnet-ef tooling
- Generate InitialCreate migration representing the pre-v0.61 schema
  (without OCI columns) — this is the baseline for existing installs
- Generate AddOciRegistrySource migration (ALTER TABLE ADD COLUMN)
- Add explicit column configuration for OCI properties
- Replace EnsureDatabaseCreated() with MigrateDatabase() that:
  1. Detects legacy databases (tables exist but no __EFMigrationsHistory)
  2. Inserts InitialCreate as baseline so existing schema is treated as
     already-migrated
  3. Runs Migrate() to apply any subsequent migrations

Test harness:
- CustomWebApplicationFactory now uses Migrate() instead of EnsureCreated()
  so integration tests exercise the same pipeline as production
- 4 new MigrationBaselineTests covering: fresh DB, legacy DB, data
  preservation, and idempotency (2 runs in sequence)

All 2870 unit tests and 402 integration tests pass.
@github-actions github-actions Bot added the feature New feature or enhancement label Apr 13, 2026
@Wiesenwischer Wiesenwischer merged commit 97bf52d into main Apr 14, 2026
2 checks passed
@Wiesenwischer Wiesenwischer deleted the feature/ef-core-migrations branch April 14, 2026 06:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant