Remove redundant SQL from SQLite rebuild migration
This commit is contained in:
@@ -121,6 +121,8 @@ For migration authoring, use the local tool command form:
|
|||||||
dotnet dotnet-ef migrations add <MigrationName> --project RpgRoller/RpgRoller.csproj --startup-project RpgRoller/RpgRoller.csproj
|
dotnet dotnet-ef migrations add <MigrationName> --project RpgRoller/RpgRoller.csproj --startup-project RpgRoller/RpgRoller.csproj
|
||||||
```
|
```
|
||||||
|
|
||||||
|
For SQLite migrations, avoid `migrationBuilder.Sql(...)` in the same migration step that rebuilds a table for schema changes; prefer column defaults or a follow-up migration so EF Core does not warn about raw SQL executing while a rebuilt table is still pending.
|
||||||
|
|
||||||
## Frontend Runtime
|
## Frontend Runtime
|
||||||
|
|
||||||
- Runtime frontend is Blazor Server with interactive components.
|
- Runtime frontend is Blazor Server with interactive components.
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
using Microsoft.Data.Sqlite;
|
using Microsoft.Data.Sqlite;
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
@@ -203,6 +205,23 @@ public sealed class HostingCoverageTests
|
|||||||
Assert.Equal(1, rolemasterHistoryCount);
|
Assert.Equal(1, rolemasterHistoryCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void AuthorizationRolesAndCampaignDeletion_MigrationScript_DoesNotMixUsersSqlIntoCharactersRebuild()
|
||||||
|
{
|
||||||
|
var dbPath = Path.Combine(Path.GetTempPath(), $"rpgroller-migration-script-{Guid.NewGuid():N}.db");
|
||||||
|
var options = new DbContextOptionsBuilder<RpgRollerDbContext>().UseSqlite($"Data Source={dbPath}").Options;
|
||||||
|
|
||||||
|
using var db = new RpgRollerDbContext(options);
|
||||||
|
var migrator = db.GetService<IMigrator>();
|
||||||
|
var script = migrator.GenerateScript(
|
||||||
|
fromMigration: "20260226131003_AddSkillGroupPrototypes",
|
||||||
|
toMigration: "20260226160859_AddAuthorizationRolesAndCampaignDeletion");
|
||||||
|
|
||||||
|
Assert.Contains("""ALTER TABLE "Users" ADD "Roles" TEXT NOT NULL DEFAULT 'admin';""", script);
|
||||||
|
Assert.Contains("""CREATE TABLE "ef_temp_Characters" (""", script);
|
||||||
|
Assert.DoesNotContain("UPDATE Users", script);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void InitializeRpgRollerState_MigratesCopiedDevelopmentDatabaseAndPreservesD6Rolling()
|
public void InitializeRpgRollerState_MigratesCopiedDevelopmentDatabaseAndPreservesD6Rolling()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -26,12 +26,6 @@ namespace RpgRoller.Migrations
|
|||||||
nullable: true,
|
nullable: true,
|
||||||
oldClrType: typeof(Guid),
|
oldClrType: typeof(Guid),
|
||||||
oldType: "TEXT");
|
oldType: "TEXT");
|
||||||
|
|
||||||
migrationBuilder.Sql("""
|
|
||||||
UPDATE Users
|
|
||||||
SET Roles = 'admin'
|
|
||||||
WHERE Roles IS NULL OR TRIM(Roles) = '';
|
|
||||||
""");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
Reference in New Issue
Block a user