refactor(db): adopt email settings migration
This commit is contained in:
@@ -43,6 +43,9 @@ public sealed class MigrationChainTests
|
||||
Assert.Equal(1, await ScalarAsync<long>(connection, """
|
||||
SELECT COUNT(*) FROM pragma_table_info('AspNetUsers') WHERE name = 'UiLanguage';
|
||||
"""));
|
||||
Assert.Equal(10, await ScalarAsync<long>(connection, """
|
||||
SELECT COUNT(*) FROM pragma_table_info('SystemEmailSettings');
|
||||
"""));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -96,12 +99,55 @@ public sealed class MigrationChainTests
|
||||
Assert.Contains("CONSTRAINT `FK_AccountDeletionFiles_Request`", script, StringComparison.Ordinal);
|
||||
Assert.Contains("CREATE TABLE IF NOT EXISTS `AspNetUsers`", script, StringComparison.Ordinal);
|
||||
Assert.Contains("CREATE TABLE IF NOT EXISTS `AiInteractions`", script, StringComparison.Ordinal);
|
||||
Assert.Contains("CREATE TABLE IF NOT EXISTS `SystemEmailSettings`", script, StringComparison.Ordinal);
|
||||
Assert.Contains("`UiLanguage` varchar(16)", script, StringComparison.Ordinal);
|
||||
Assert.All(
|
||||
Regex.Matches(script, "CONSTRAINT `([^`]+)`").Select(match => match.Groups[1].Value),
|
||||
identifier => Assert.True(identifier.Length <= 64, $"MariaDB constraint identifier exceeds 64 characters: {identifier}"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task System_email_settings_adoption_preserves_legacy_rows()
|
||||
{
|
||||
await using var connection = new SqliteConnection("Data Source=:memory:");
|
||||
await connection.OpenAsync();
|
||||
await using var db = Context(connection);
|
||||
var migrator = db.GetService<IMigrator>();
|
||||
await migrator.MigrateAsync("20260828090000_AddUiLanguagePreference");
|
||||
await ExecuteAsync(connection, """
|
||||
CREATE TABLE "SystemEmailSettings" (
|
||||
"Id" INTEGER NOT NULL CONSTRAINT "PK_SystemEmailSettings" PRIMARY KEY,
|
||||
"Enabled" INTEGER NULL,
|
||||
"SmtpHost" TEXT NULL,
|
||||
"SmtpPort" INTEGER NULL,
|
||||
"SmtpUser" TEXT NULL,
|
||||
"SmtpPassword" TEXT NULL,
|
||||
"From" TEXT NULL,
|
||||
"FromName" TEXT NULL,
|
||||
"SmtpEnableSsl" INTEGER NULL,
|
||||
"SmtpTimeoutMs" INTEGER NULL
|
||||
);
|
||||
INSERT INTO "SystemEmailSettings" ("Id", "Enabled", "SmtpHost", "SmtpPort")
|
||||
VALUES (1, 1, 'smtp.fixture.invalid', 587);
|
||||
""");
|
||||
|
||||
await migrator.MigrateAsync();
|
||||
|
||||
Assert.Equal("smtp.fixture.invalid", await ScalarAsync<string>(connection,
|
||||
"SELECT SmtpHost FROM SystemEmailSettings WHERE Id = 1;"));
|
||||
Assert.Equal(587L, await ScalarAsync<long>(connection,
|
||||
"SELECT SmtpPort FROM SystemEmailSettings WHERE Id = 1;"));
|
||||
Assert.Empty(await db.Database.GetPendingMigrationsAsync());
|
||||
|
||||
await migrator.MigrateAsync("20260828090000_AddUiLanguagePreference");
|
||||
Assert.Equal("smtp.fixture.invalid", await ScalarAsync<string>(connection,
|
||||
"SELECT SmtpHost FROM SystemEmailSettings WHERE Id = 1;"));
|
||||
await migrator.MigrateAsync();
|
||||
Assert.Equal("smtp.fixture.invalid", await ScalarAsync<string>(connection,
|
||||
"SELECT SmtpHost FROM SystemEmailSettings WHERE Id = 1;"));
|
||||
Assert.Empty(await db.Database.GetPendingMigrationsAsync());
|
||||
}
|
||||
|
||||
private static JobTrackerContext Context(SqliteConnection connection)
|
||||
{
|
||||
var currentUser = new Mock<ICurrentUserService>();
|
||||
|
||||
Reference in New Issue
Block a user