You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
MasterDataStore.EnsureSchema can silently miss a column, and the drift test from #396 cannot catch it #397
Follow-up from #396, which fixed the equivalent hole in the per-incident store.
The gap
MasterDataStore.EnsureSchema (src/LageBuch.Persistence/MasterData/MasterDataStore.cs, ~line 165) does the right thing structurally — the master-data file has no version marker, so the schema is re-checked on every open rather than gated behind a version number. That is exactly why it did not suffer the bug in #396.
But its reconciliation is three hand-written lines:
SchemaHelpers.AddColumnIfMissing(cn,null,"md_checklist_template","is_mandatory","INTEGER NOT NULL DEFAULT 0");SchemaHelpers.AddColumnIfMissing(cn,null,"md_checklist_template","kind","INTEGER NOT NULL DEFAULT 0");SchemaHelpers.AddColumnIfMissing(cn,null,"md_vehicles","has_zugfuehrer","INTEGER NOT NULL DEFAULT 0");
A future column added to an existing md_*CREATE TABLEwithout a matching line here breaks every pre-existing store — silently, and only for users who already have one.
SchemaReconciliationTests.Declared_schema_matches_a_freshly_migrated_database works because the incident store's expected schema is compared against a database built by running the migrations. Here, a fresh store is created directly from the CREATE TABLE statements, so it always matches itself — the new column is present, the missing AddColumnIfMissing line is invisible, and the test passes while old stores stay broken.
The test that does catch it
The drop-column theory, driven by EnsureSchema instead of Migrate:
Create a fresh master-data store.
For every md_* column that is nullable or carries a default (pk = 0 AND (notnull = 0 OR dflt_value IS NOT NULL)), ALTER TABLE ... DROP COLUMN it.
Re-open the store.
Assert the column is back.
That is SchemaReconciliationTests.Every_repairable_column_is_restored_after_being_dropped pointed at the other store, and it fails the moment a column exists in the CREATE TABLE but not in EnsureSchema. Declaring the expected columns the way SchemaGuard does would work too, but the drop-column sweep alone is enough here and needs no second list.
Not urgent
No such column is currently missing — the three lines above are complete as of today. This is about the next one.
From the portability review in #405 — a second failure mode for the same design, worth recording here rather than as its own issue since it is the same three lines.
This issue covers a column added to a CREATE TABLE without a matching AddColumnIfMissing. The mirror case is a column or settings key renamed, and it fails differently and more quietly.
ReadSettings falls back to IncidentSettings.Defaults for any key it does not find (MasterDataStore.cs, ~:234). So renaming md_settings.return_pressure_bar, or md_vehicles.wache, or any of the *_max_duration_minutes keys does not throw and does not leave a gap — it silently resets that install to the shipped defaults. A brigade running a 40-bar Rückzugsdruck or a 25-minute AGT-Zeit would find itself back on 50 and 30 with nothing in the UI saying so, and the Stammdaten editor would then write the defaults back as if they had been chosen.
The drop-column sweep proposed here catches the add case but not this one: a renamed column is not missing from the fresh schema, so it is never restored and never noticed.
I am not arguing for a version marker — the reasoning above for re-checking on every open is right, and #396 is the evidence. Two cheaper guards would cover it:
treat the md_settings keys and the md_* column names as a published contract and say so in a comment next to the CREATE TABLE statements, so a rename is recognised as a breaking change rather than a refactor;
or have ReadSettings distinguish absent from never written — a single settings_initialised marker row would let a missing key be a warning rather than a silent default.
Relevant now because #398, #401 and #403 all propose touching md_settings or md_trupp_types, and each of them is exactly the kind of change that would trip this.
Activity
DeepDiver1975 commentedon Sep 18, 2026
From the portability review in #405 — a second failure mode for the same design, worth recording here rather than as its own issue since it is the same three lines.
This issue covers a column added to a
CREATE TABLEwithout a matchingAddColumnIfMissing. The mirror case is a column or settings key renamed, and it fails differently and more quietly.ReadSettingsfalls back toIncidentSettings.Defaultsfor any key it does not find (MasterDataStore.cs, ~:234). So renamingmd_settings.return_pressure_bar, ormd_vehicles.wache, or any of the*_max_duration_minuteskeys does not throw and does not leave a gap — it silently resets that install to the shipped defaults. A brigade running a 40-bar Rückzugsdruck or a 25-minute AGT-Zeit would find itself back on 50 and 30 with nothing in the UI saying so, and the Stammdaten editor would then write the defaults back as if they had been chosen.The drop-column sweep proposed here catches the add case but not this one: a renamed column is not missing from the fresh schema, so it is never restored and never noticed.
I am not arguing for a version marker — the reasoning above for re-checking on every open is right, and #396 is the evidence. Two cheaper guards would cover it:
md_settingskeys and themd_*column names as a published contract and say so in a comment next to theCREATE TABLEstatements, so a rename is recognised as a breaking change rather than a refactor;ReadSettingsdistinguish absent from never written — a singlesettings_initialisedmarker row would let a missing key be a warning rather than a silent default.Relevant now because #398, #401 and #403 all propose touching
md_settingsormd_trupp_types, and each of them is exactly the kind of change that would trip this.fix(stammdaten): widen a leftover pre-#173 md_streets instead of cras…