Skip to content

fix(persistence): two migrations were never discovered by EF — schema drifts from model on every install#727

Open
kevinheneveld wants to merge 1 commit into
Listenarrs:canaryfrom
kevinheneveld:fix/movejob-sourcepath-migration
Open

fix(persistence): two migrations were never discovered by EF — schema drifts from model on every install#727
kevinheneveld wants to merge 1 commit into
Listenarrs:canaryfrom
kevinheneveld:fix/movejob-sourcepath-migration

Conversation

@kevinheneveld

Copy link
Copy Markdown
Contributor

The bug

20251124102000_AddMoveJobSourcePath.cs shipped without a [Migration] attribute or Designer file, so EF's migration discovery has never seen it. Every SQLite install is missing MoveJobs.SourcePath while the model maps it — verifiable on any instance:

sqlite3 config/database/listenarr.db "PRAGMA table_info(MoveJobs);"   # no SourcePath
sqlite3 config/database/listenarr.db "SELECT MigrationId FROM __EFMigrationsHistory WHERE MigrationId LIKE '%SourcePath%';"   # empty

Any full-entity MoveJobs query or insert dies with SQLite Error 1: 'no such column: m.SourcePath' — I hit it live on a new endpoint, but move-job persistence itself is affected.

The fix

  • Restore the Designer for AddMoveJobSourcePath (attributes + model as of that migration). EF applies not-yet-recorded migrations on next startup regardless of later ones already being in history, so existing installs heal themselves on upgrade.
  • The audit found a second identical drift: ProcessExecutionLog has been in the model and every snapshot since late 2025, but no discovered migration ever created its table (SELECT name FROM sqlite_master WHERE name='ProcessExecutionLogs' is empty on real installs). New migration AddProcessExecutionLogs creates it.
  • Regression net: SqliteMigrationSchemaTests migrates a real (shared in-memory) SQLite database and asserts every mapped column of every entity exists in the migrated schema. Hand-written migrations + an InMemory-provider test suite is exactly the combination that let this ship silently; this test makes the whole class of drift fail CI. It found the second bug above on its first run.

Heads-up

There are 16 more migration files without a [Migration] attribute/Designer (mostly AddXxxToApplicationSettings and pre-org-migration files) — equally invisible to EF. The schema test passing means the current model doesn't depend on any of them (their changes were superseded or re-rooted), but they're dead code worth cleaning up separately. List available on request.

Tests

Full suite passing (1017/1017), including the 2 new schema tests.

🤖 Generated with Claude Code

… drifts from model on every install

20251124102000_AddMoveJobSourcePath shipped without a [Migration]
attribute or Designer, so EF migration discovery never saw it: every
SQLite install is missing MoveJobs.SourcePath while the model maps it,
and the first full-entity MoveJobs query (or insert) fails at runtime
with "no such column: m.SourcePath". Restore the Designer (model as of
that migration) so it is discovered and applied; EF applies it on next
startup regardless of later migrations already being recorded.

The same audit found a second drift: ProcessExecutionLog has been in
the model and every snapshot since late 2025, but no discovered
migration ever created its table — IProcessExecutionLogRepository
writes fail on real databases. Add AddProcessExecutionLogs to create
it.

Neither drift was catchable by the test suite: migrations are
hand-written and the suite runs on the EF InMemory provider, which
never executes them. Add SqliteMigrationSchemaTests, which migrates a
real (in-memory) SQLite database and verifies every mapped column of
every entity exists — so this entire class of drift fails CI instead of
production.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@kevinheneveld kevinheneveld requested a review from a team July 2, 2026 19:30
@kevinheneveld kevinheneveld force-pushed the fix/movejob-sourcepath-migration branch from 87bbe5b to 3103996 Compare July 2, 2026 19:31
therobbiedavis pushed a commit that referenced this pull request Jul 2, 2026
Cherry-picked PR #727 from 3103996 and adapted the current branch by removing the now-redundant MoveJobs runtime schema repair.

Co-authored-by: Kevin Heneveld <1192102+kevinheneveld@users.noreply.github.com>

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
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.

1 participant