Persist app DB changes directly
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user