From 4c3ed8a76c4b9d391b6492a02b5bc0f282facb2b Mon Sep 17 00:00:00 2001 From: Frank Date: Sun, 19 Apr 2026 14:04:53 +0200 Subject: [PATCH] Persist app DB changes directly --- docs/critical_import_tool.md | 2 ++ .../Data/RolemasterDbInitializer.cs | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/docs/critical_import_tool.md b/docs/critical_import_tool.md index 9f15a34..a59ae41 100644 --- a/docs/critical_import_tool.md +++ b/docs/critical_import_tool.md @@ -13,6 +13,8 @@ The tool is intentionally separate from the web application startup path. Critic The tool currently lives in `src/RolemasterDb.ImportTool` and operates against the same SQLite schema used by the web app. +For the committed app database workflow, the web app forces SQLite `journal_mode=DELETE` during startup so local curation changes land in `src/RolemasterDb.App/rolemaster.db` directly instead of accumulating in a long-lived WAL sidecar. + ## Goals The importer is designed around the following requirements: diff --git a/src/RolemasterDb.App/Data/RolemasterDbInitializer.cs b/src/RolemasterDb.App/Data/RolemasterDbInitializer.cs index 3a799d8..48a2cc8 100644 --- a/src/RolemasterDb.App/Data/RolemasterDbInitializer.cs +++ b/src/RolemasterDb.App/Data/RolemasterDbInitializer.cs @@ -11,6 +11,7 @@ public static class RolemasterDbInitializer await using var dbContext = await dbFactory.CreateDbContextAsync(cancellationToken); await dbContext.Database.EnsureCreatedAsync(cancellationToken); + await EnsureDeleteJournalModeAsync(dbContext, cancellationToken); await RolemasterDbSchemaUpgrader.EnsureLatestAsync(dbContext, cancellationToken); RolemasterSeedData.BackfillAttackTableMetadata(dbContext); @@ -23,4 +24,18 @@ public static class RolemasterDbInitializer RolemasterSeedData.SeedAttackStarterData(dbContext); await dbContext.SaveChangesAsync(cancellationToken); } -} + + private static async Task EnsureDeleteJournalModeAsync(RolemasterDbContext dbContext, + CancellationToken cancellationToken) + { + await dbContext.Database.OpenConnectionAsync(cancellationToken); + await using var command = dbContext.Database.GetDbConnection().CreateCommand(); + command.CommandText = "PRAGMA journal_mode=DELETE;"; + + var result = await command.ExecuteScalarAsync(cancellationToken); + if (!string.Equals(Convert.ToString(result), "delete", StringComparison.OrdinalIgnoreCase)) + { + throw new InvalidOperationException("Failed to configure SQLite journal_mode=DELETE."); + } + } +} \ No newline at end of file