refactor(db): migrate tailored CV drafts
Move job-specific tailored documents into an additive provider-aware migration. Preserve edited content, indexes, and application cascade semantics.
This commit is contained in:
@@ -110,6 +110,7 @@ public sealed class MigrationChainTests
|
||||
Assert.Contains("CREATE TABLE IF NOT EXISTS `ImapConnections`", script, StringComparison.Ordinal);
|
||||
Assert.Contains("CREATE TABLE IF NOT EXISTS `CvUploadArtifacts`", script, StringComparison.Ordinal);
|
||||
Assert.Contains("CREATE TABLE IF NOT EXISTS `CvExtractionRuns`", script, StringComparison.Ordinal);
|
||||
Assert.Contains("CREATE TABLE IF NOT EXISTS `TailoredCvDrafts`", script, StringComparison.Ordinal);
|
||||
Assert.Contains("`UiLanguage` varchar(16)", script, StringComparison.Ordinal);
|
||||
Assert.All(
|
||||
Regex.Matches(script, "CONSTRAINT `([^`]+)`").Select(match => match.Groups[1].Value),
|
||||
@@ -451,6 +452,61 @@ public sealed class MigrationChainTests
|
||||
Assert.Empty(await db.Database.GetPendingMigrationsAsync());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Tailored_cv_adoption_preserves_document_and_cascade_relationship()
|
||||
{
|
||||
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("20260830125000_AdoptCvExtractionSchema");
|
||||
await ExecuteAsync(connection, """
|
||||
INSERT INTO Companies (Name) VALUES ('Fixture company');
|
||||
INSERT INTO JobApplications
|
||||
(CompanyId, JobTitle, DateApplied, SavedAt, Status, ResponseReceived, OwnerUserId,
|
||||
HasResume, HasCoverLetter, HasPortfolio, HasOtherAttachment, IsDeleted)
|
||||
VALUES
|
||||
(1, 'Fixture role', '2026-08-01T09:00:00', '2026-07-20T09:00:00',
|
||||
'Applied', 0, 'owner-fixture', 0, 0, 0, 0, 0);
|
||||
CREATE TABLE "TailoredCvDrafts" (
|
||||
"Id" INTEGER NOT NULL CONSTRAINT "PK_TailoredCvDrafts" PRIMARY KEY AUTOINCREMENT,
|
||||
"OwnerUserId" TEXT NOT NULL, "JobApplicationId" INTEGER NOT NULL,
|
||||
"CanonicalProfileVersion" INTEGER NULL, "TemplateId" TEXT NOT NULL,
|
||||
"Headline" TEXT NULL, "SummaryJson" TEXT NULL, "SelectedSkillsJson" TEXT NULL,
|
||||
"ExperienceJson" TEXT NULL, "EducationJson" TEXT NULL, "CustomSectionsJson" TEXT NULL,
|
||||
"RenderOptionsJson" TEXT NULL, "GenerationContextHash" TEXT NULL,
|
||||
"LastGeneratedAtUtc" TEXT NULL, "LastEditedAtUtc" TEXT NULL, "Status" TEXT NOT NULL,
|
||||
CONSTRAINT "FK_TailoredCvDrafts_JobApplications_JobApplicationId"
|
||||
FOREIGN KEY ("JobApplicationId") REFERENCES "JobApplications" ("Id") ON DELETE CASCADE
|
||||
);
|
||||
INSERT INTO "TailoredCvDrafts"
|
||||
("OwnerUserId", "JobApplicationId", "CanonicalProfileVersion", "TemplateId",
|
||||
"SummaryJson", "CustomSectionsJson", "GenerationContextHash", "Status")
|
||||
VALUES
|
||||
('owner-fixture', 1, 7, 'code', '{"text":"preserve me"}', '[{"title":"Awards"}]',
|
||||
'context-fixture', 'edited');
|
||||
""");
|
||||
|
||||
await migrator.MigrateAsync();
|
||||
Assert.Equal("{\"text\":\"preserve me\"}", await ScalarAsync<string>(connection,
|
||||
"SELECT SummaryJson FROM TailoredCvDrafts WHERE JobApplicationId = 1;"));
|
||||
|
||||
await migrator.MigrateAsync("20260830125000_AdoptCvExtractionSchema");
|
||||
Assert.Equal("context-fixture", await ScalarAsync<string>(connection,
|
||||
"SELECT GenerationContextHash FROM TailoredCvDrafts WHERE JobApplicationId = 1;"));
|
||||
await migrator.MigrateAsync();
|
||||
Assert.Equal(2L, await ScalarAsync<long>(connection, """
|
||||
SELECT COUNT(*) FROM sqlite_master
|
||||
WHERE type = 'index' AND name IN (
|
||||
'IX_TailoredCvDrafts_OwnerUserId_JobApplicationId',
|
||||
'IX_TailoredCvDrafts_JobApplicationId');
|
||||
"""));
|
||||
|
||||
await ExecuteAsync(connection, "DELETE FROM JobApplications WHERE Id = 1;");
|
||||
Assert.Equal(0L, await ScalarAsync<long>(connection, "SELECT COUNT(*) FROM TailoredCvDrafts;"));
|
||||
Assert.Empty(await db.Database.GetPendingMigrationsAsync());
|
||||
}
|
||||
|
||||
private static JobTrackerContext Context(SqliteConnection connection)
|
||||
{
|
||||
var currentUser = new Mock<ICurrentUserService>();
|
||||
|
||||
Reference in New Issue
Block a user