Document and harden curated critical imports
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -691,9 +691,16 @@ public sealed class StandardCriticalTableParserIntegrationTests
|
||||
{
|
||||
var databasePath = Path.Combine(GetArtifactCacheRoot(), $"rolemaster-{Guid.NewGuid():N}.db");
|
||||
File.Copy(Path.Combine(GetRepositoryRoot(), "src", "RolemasterDb.App", "rolemaster.db"), databasePath, true);
|
||||
UpgradeDatabase(databasePath).GetAwaiter().GetResult();
|
||||
return databasePath;
|
||||
}
|
||||
|
||||
private static async Task UpgradeDatabase(string databasePath)
|
||||
{
|
||||
await using var dbContext = CreateDbContext(databasePath);
|
||||
await RolemasterDbSchemaUpgrader.EnsureLatestAsync(dbContext);
|
||||
}
|
||||
|
||||
private static string GetRepositoryRoot()
|
||||
{
|
||||
var probe = new DirectoryInfo(AppContext.BaseDirectory);
|
||||
|
||||
Reference in New Issue
Block a user