the baseline asks the database which tables it has, because EF's own check answers wrong on postgres
Measured against a real postgres 18, not inferred: a database created by ensurecreated and then asked to migrate gained request_rules and source_streaks — one migration baselined, one applied, both rows in __EFMigrationsHistory, PK and both indexes present. Before this, the same scenario answered schemaMissingTables: [request_rules, source_streaks] and requestRulesAvailable false, and the log said nothing about why. The reason it said nothing: IHistoryRepository.Exists() returned true for a database that has tables and no history table at all — the one state BaselineIfUntrackedAsync exists to notice — so the method returned 0 through its first guard and never reached a log line. The same call returns false on sqlite, which is why the sqlite integration test was green and the postgres path was broken: the test and the product were asking different providers. The check is now made against the table listing this step already takes, which is the answer both providers agree on. The empty-listing branch is no longer silent either. An empty listing is the one answer that would make an upgrade destructive — it would mean 'create everything' against a database that has data — so it is logged rather than treated as 'empty database'. Also measured on the same postgres instance, with the sqlite default strategy pointed at it: AddMissingTables created the two dropped tables in place (schemaTablesAdded 2, schemaMissingTables []) and the PK and both indexes arrived with the table, which is the GO-batch splitting in SchemaDdl working on a provider that uses batch separators. Gates: build 0 warnings / 0 errors, unit 240/240, integration 230/230, smoke passed 52 failed 0, compose 216 passed 0 failed against the rebuilt image. Console unchanged at 90 assertions 0 failed from the previous commit; the admin surface this commit touches is a field the page does not read.
This commit is contained in:
@@ -345,6 +345,15 @@ happened is on `/admin-api/state`: `schemaStrategy`, `schemaTablesAdded`,
|
||||
can run with no storage behind it. `none` changes nothing and reports all of it
|
||||
the same way.
|
||||
|
||||
Measured on postgres rather than assumed: a database created by `ensurecreated`
|
||||
and then asked to `migrate` gained `request_rules` and `source_streaks` — one
|
||||
migration baselined, one applied, both rows in the history table, the indexes
|
||||
present. That run is also what caught a trap in EF itself:
|
||||
`IHistoryRepository.Exists()` answers **true** on postgres for a database that
|
||||
has tables and no history table at all — the one state this step exists to
|
||||
notice — while the same call answers false on sqlite. The question is therefore
|
||||
asked of the table listing, the answer both providers agree on.
|
||||
|
||||
## Admin API
|
||||
|
||||
Requires `X-Admin-Token` (or `?token=`). **No token configured means the admin
|
||||
|
||||
@@ -99,10 +99,26 @@ public static class SchemaUpgrader
|
||||
public static async Task<int> BaselineIfUntrackedAsync(OpenWafDbContext db, ILogger log, CancellationToken ct = default)
|
||||
{
|
||||
var history = db.GetService<IHistoryRepository>();
|
||||
if (await history.ExistsAsync(ct)) return 0;
|
||||
|
||||
// Asked of the table listing rather than of IHistoryRepository.Exists:
|
||||
// measured on postgres, Exists() answered true for a database that has
|
||||
// tables and no history table at all — which is exactly the state this
|
||||
// method exists to notice. On sqlite the same call answered false. The
|
||||
// listing is the one answer both providers agree on.
|
||||
var existing = await ExistingTablesAsync(db, ct);
|
||||
if (existing.Count == 0) return 0;
|
||||
if (existing.Contains(HistoryRepository.DefaultTableName)) return 0;
|
||||
|
||||
if (existing.Count == 0)
|
||||
{
|
||||
// Either a first install, which the migrations describe from the
|
||||
// beginning, or a listing this provider does not answer — and an
|
||||
// empty listing is the one answer that would make an upgrade
|
||||
// destructive, so it is said out loud rather than treated as "empty".
|
||||
log.LogWarning(
|
||||
"edge: the table listing for this database came back empty while it has no migration history — "
|
||||
+ "nothing can be baselined, so the migrations will run against it and report what they find.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
var assembly = db.GetService<IMigrationsAssembly>();
|
||||
var migrations = new List<SchemaBaseline.Migration>();
|
||||
|
||||
Reference in New Issue
Block a user