refactor(db): adopt email settings migration
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
using System;
|
||||
using JobTrackerApi.Data;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace JobTrackerApi.Migrations;
|
||||
|
||||
/// <summary>
|
||||
/// Transfers creation ownership of the legacy SystemEmailSettings singleton from startup
|
||||
/// reconciliation to the migration chain. Both statements are additive and preserve a table
|
||||
/// created by an older MariaDB deployment.
|
||||
/// </summary>
|
||||
[DbContext(typeof(JobTrackerContext))]
|
||||
[Migration("20260830120000_AdoptSystemEmailSettingsSchema")]
|
||||
public sealed class AdoptSystemEmailSettingsSchema : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
if (ActiveProvider.Contains("MySql", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
migrationBuilder.Sql("""
|
||||
CREATE TABLE IF NOT EXISTS `SystemEmailSettings` (
|
||||
`Id` int NOT NULL,
|
||||
`Enabled` tinyint(1) NULL,
|
||||
`SmtpHost` longtext NULL,
|
||||
`SmtpPort` int NULL,
|
||||
`SmtpUser` longtext NULL,
|
||||
`SmtpPassword` longtext NULL,
|
||||
`From` longtext NULL,
|
||||
`FromName` longtext NULL,
|
||||
`SmtpEnableSsl` tinyint(1) NULL,
|
||||
`SmtpTimeoutMs` int NULL,
|
||||
PRIMARY KEY (`Id`)
|
||||
) CHARACTER SET=utf8mb4;
|
||||
""");
|
||||
return;
|
||||
}
|
||||
|
||||
migrationBuilder.Sql("""
|
||||
CREATE TABLE IF NOT EXISTS "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
|
||||
);
|
||||
""");
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
// Deliberately preserve the table: older deployments created it outside migrations, so a
|
||||
// downgrade cannot know whether this migration owns the existing data.
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
[assembly: InternalsVisibleTo("JobTrackerApi.Tests")]
|
||||
@@ -1469,25 +1469,6 @@ public static class StartupInitializationExtensions
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
if (!HasMySqlTable(conn, "SystemEmailSettings"))
|
||||
{
|
||||
using var cmd = conn.CreateCommand();
|
||||
cmd.CommandText = @"CREATE TABLE IF NOT EXISTS `SystemEmailSettings` (
|
||||
`Id` int NOT NULL,
|
||||
`Enabled` tinyint(1) NULL,
|
||||
`SmtpHost` longtext NULL,
|
||||
`SmtpPort` int NULL,
|
||||
`SmtpUser` longtext NULL,
|
||||
`SmtpPassword` longtext NULL,
|
||||
`From` longtext NULL,
|
||||
`FromName` longtext NULL,
|
||||
`SmtpEnableSsl` tinyint(1) NULL,
|
||||
`SmtpTimeoutMs` int NULL,
|
||||
PRIMARY KEY (`Id`)
|
||||
);";
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
if (!HasMySqlTable(conn, "CvUploadArtifacts"))
|
||||
{
|
||||
using var cmd = conn.CreateCommand();
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
namespace JobTrackerApi.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Records the current table-creation owner while the legacy startup reconciler is retired in
|
||||
/// migration-backed increments. This is a governance boundary, not a second schema definition.
|
||||
/// A table must appear in exactly one creation set.
|
||||
/// </summary>
|
||||
internal static class StartupSchemaOwnership
|
||||
{
|
||||
internal static readonly IReadOnlySet<string> MigrationOwnedTables = new HashSet<string>(StringComparer.Ordinal)
|
||||
{
|
||||
"AccountDeletionFiles",
|
||||
"AccountDeletionRequests",
|
||||
"AiUsageRecords",
|
||||
"Attachments",
|
||||
"Companies",
|
||||
"Correspondences",
|
||||
"EmailDrafts",
|
||||
"EmailSendAttempts",
|
||||
"JobApplications",
|
||||
"JobEvents",
|
||||
"Jobs",
|
||||
"RuleSettings",
|
||||
"SystemEmailSettings",
|
||||
"UserNotifications",
|
||||
"UserOperations",
|
||||
};
|
||||
|
||||
internal static readonly IReadOnlySet<string> ReconcilerOwnedTables = new HashSet<string>(StringComparer.Ordinal)
|
||||
{
|
||||
"AiInteractions",
|
||||
"AiWorkspaceNotes",
|
||||
"ApplicationChecklistItems",
|
||||
"AspNetRoleClaims",
|
||||
"AspNetRoles",
|
||||
"AspNetUserClaims",
|
||||
"AspNetUserLogins",
|
||||
"AspNetUserRoles",
|
||||
"AspNetUsers",
|
||||
"AspNetUserTokens",
|
||||
"CareerCertifications",
|
||||
"CareerEducations",
|
||||
"CareerExperiences",
|
||||
"CareerLanguages",
|
||||
"CareerProfiles",
|
||||
"CareerProfileVersions",
|
||||
"CareerProjects",
|
||||
"CareerSkills",
|
||||
"CoverLetterVersions",
|
||||
"CvExtractionRuns",
|
||||
"CvUploadArtifacts",
|
||||
"CvVariants",
|
||||
"CvVariantVersions",
|
||||
"GmailConnections",
|
||||
"GmailReviewDecisions",
|
||||
"ImapConnections",
|
||||
"InterviewPrepItems",
|
||||
"InterviewPrepNotes",
|
||||
"MicrosoftGraphConnections",
|
||||
"TailoredCvDrafts",
|
||||
"TrustedDevices",
|
||||
"TwoFactorRecoveryCodes",
|
||||
"UserRuleSettings",
|
||||
"UserSessions",
|
||||
};
|
||||
|
||||
// Historical migrations contain guarded compatibility bootstraps for these tables so direct
|
||||
// EF tooling can traverse the chain. Their current creation owner remains the reconciler.
|
||||
internal static readonly IReadOnlySet<string> MigrationCompatibilityBootstrapTables =
|
||||
new HashSet<string>(StringComparer.Ordinal) { "AiInteractions", "AspNetUsers" };
|
||||
}
|
||||
Reference in New Issue
Block a user