Document and harden curated critical imports

This commit is contained in:
2026-03-17 22:29:48 +01:00
parent 14bd666f43
commit 8269a1f68e
3 changed files with 111 additions and 12 deletions

View File

@@ -94,6 +94,11 @@ public static class RolemasterDbSchemaUpgrader
private static async Task EnsureCriticalResultCurationColumnsAsync(RolemasterDbContext dbContext, CancellationToken cancellationToken)
{
if (!await TableExistsAsync(dbContext, "CriticalResults", cancellationToken))
{
return;
}
if (!await ColumnExistsAsync(dbContext, "CriticalResults", "IsCurated", cancellationToken))
{
await dbContext.Database.ExecuteSqlRawAsync(
@@ -195,4 +200,38 @@ public static class RolemasterDbSchemaUpgrader
}
}
}
private static async Task<bool> TableExistsAsync(
RolemasterDbContext dbContext,
string tableName,
CancellationToken cancellationToken)
{
var connection = dbContext.Database.GetDbConnection();
var shouldClose = connection.State != System.Data.ConnectionState.Open;
if (shouldClose)
{
await connection.OpenAsync(cancellationToken);
}
try
{
await using var command = connection.CreateCommand();
command.CommandText = "SELECT COUNT(*) FROM sqlite_master WHERE type = 'table' AND name = $tableName;";
var parameter = command.CreateParameter();
parameter.ParameterName = "$tableName";
parameter.Value = tableName;
command.Parameters.Add(parameter);
var result = await command.ExecuteScalarAsync(cancellationToken);
return Convert.ToInt32(result) > 0;
}
finally
{
if (shouldClose)
{
await connection.CloseAsync();
}
}
}
}