Skip to content

Fail when a model change has no migration - #20

Merged
fdaniel02 merged 1 commit into
mainfrom
pending-model-changes-check
Oct 21, 2026
Merged

fdaniel02 merged 1 commit into
mainfrom
pending-model-changes-check

Conversation

@fdaniel02

Copy link
Copy Markdown
Owner

The bUnit tests create their schema from the model (EnsureCreated()), so a model change committed without a
migration passed every test and only failed at startup in the cluster.

Changes

New test MigrationsTests.Model_changes_all_have_a_migration: db.Database.HasPendingModelChanges() must be
false. Its failure message says how to add the migration.

It's a plain unit test, not a SQL Server test: the check compares the model with the last migration's snapshot
and never opens the database. The context is configured with UseSqlServer (connection string never used), so the
SQL Server model is compared, and the test needs no Docker.

Testing

Passes on main. With a property added to Workout and no migration, it fails with the message.

The bUnit tests build their schema from the model, so a model change without a migration passed every test and only failed at startup.
@sonarqubecloud

Copy link
Copy Markdown

@fdaniel02
fdaniel02 merged commit 4d48550 into main Oct 21, 2026
5 checks passed
@fdaniel02
fdaniel02 deleted the pending-model-changes-check branch October 21, 2026 13:56
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