Add migration cutover reconciliation journal
This commit is contained in:
1 parent
a21d35a165
commit
62ac397459
12 files changed
+319
-6
No files matched your search
@@ -23,7 +23,7 @@ describe("domain services", () => {
|
||||
const connection = createConnection();
|
||||
|
||||
const rows = connection.db.prepare("select version from schema_migrations order by version asc").all() as Array<{ version: number }>;
|
||||
expect(rows.map((row) => row.version)).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27]);
|
||||
expect(rows.map((row) => row.version)).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28]);
|
||||
connection.close();
|
||||
});
|
||||
|
||||
|
||||
@@ -159,6 +159,8 @@ describe("migration service", () => {
|
||||
create table search_documents(entity_id text);
|
||||
create table audit_replay_runs(id text primary key, org_id text, thread_id text, created_by_employee_id text);
|
||||
create table rollback_snapshots(id text primary key, org_id text, migration_report_id text, created_by_employee_id text);
|
||||
create table migration_cutover_events(id text primary key, org_id text, migration_report_id text, rollback_snapshot_id text);
|
||||
create table migration_reconciliation_items(id text primary key, org_id text, migration_report_id text, rollback_snapshot_id text, resolved_by_employee_id text);
|
||||
create table audit_events(id text primary key, org_id text);
|
||||
insert into organizations(id) values ('org-1');
|
||||
insert into employees(id, org_id) values ('emp-1', 'org-1');
|
||||
@@ -228,6 +230,8 @@ describe("migration service", () => {
|
||||
insert into search_documents(entity_id) values ('task-1');
|
||||
insert into audit_replay_runs(id, org_id, thread_id, created_by_employee_id) values ('replay-1', 'org-1', 'thread-1', 'emp-1');
|
||||
insert into rollback_snapshots(id, org_id, migration_report_id, created_by_employee_id) values ('rollback-1', 'org-1', 'migration-1', 'emp-1');
|
||||
insert into migration_cutover_events(id, org_id, migration_report_id, rollback_snapshot_id) values ('cutover-1', 'org-1', 'migration-1', 'rollback-1');
|
||||
insert into migration_reconciliation_items(id, org_id, migration_report_id, rollback_snapshot_id, resolved_by_employee_id) values ('reconcile-1', 'org-1', 'migration-1', 'rollback-1', 'emp-1');
|
||||
insert into audit_events(id, org_id) values ('audit-1', 'org-1');
|
||||
`);
|
||||
let orgId = "";
|
||||
@@ -262,6 +266,8 @@ describe("migration service", () => {
|
||||
expect(body.tableCounts.compliance_exports).toBe(1);
|
||||
expect(body.tableCounts.audit_replay_runs).toBe(1);
|
||||
expect(body.tableCounts.rollback_snapshots).toBe(1);
|
||||
expect(body.tableCounts.migration_cutover_events).toBe(1);
|
||||
expect(body.tableCounts.migration_reconciliation_items).toBe(1);
|
||||
expect(body.tableCounts.search_documents).toBe(1);
|
||||
expect(body.tableChecksums.audit_events).toHaveLength(64);
|
||||
expect(body.idMaps.skill_runtime_snapshots).toEqual(["snapshot-1"]);
|
||||
@@ -276,6 +282,8 @@ describe("migration service", () => {
|
||||
expect(body.idMaps.retention_freezes).toEqual(["freeze-1"]);
|
||||
expect(body.idMaps.audit_replay_runs).toEqual(["replay-1"]);
|
||||
expect(body.idMaps.rollback_snapshots).toEqual(["rollback-1"]);
|
||||
expect(body.idMaps.migration_cutover_events).toEqual(["cutover-1"]);
|
||||
expect(body.idMaps.migration_reconciliation_items).toEqual(["reconcile-1"]);
|
||||
expect(body.idMaps.provider_usage_windows).toEqual(["usage-1"]);
|
||||
expect(body.idMaps.provider_rate_limit_observations).toEqual(["quota-1"]);
|
||||
expect(body.idMaps.browser_session_containers).toEqual(["container-1"]);
|
||||
|
||||
@@ -4,6 +4,7 @@ import { join } from "node:path";
|
||||
import { DatabaseSync } from "node:sqlite";
|
||||
import { describe, expect, test } from "vitest";
|
||||
import { DatabaseConnection } from "../../src/main/database/connection";
|
||||
import { AuditService } from "../../src/main/services/audit-service";
|
||||
import { MigrationService } from "../../src/main/services/migration-service";
|
||||
import { OrganizationService } from "../../src/main/services/organization-service";
|
||||
import { RollbackService } from "../../src/main/services/rollback-service";
|
||||
@@ -31,6 +32,7 @@ describe("rollback service", () => {
|
||||
const migrations = new MigrationService(connection.db);
|
||||
const rollback = new RollbackService(connection.db);
|
||||
const snapshot = new SnapshotService(connection.db);
|
||||
const audit = new AuditService(connection.db);
|
||||
const legacyPath = createLegacyDatabase();
|
||||
let orgId = "";
|
||||
let employeeId = "";
|
||||
@@ -47,6 +49,15 @@ describe("rollback service", () => {
|
||||
employeeId = (connection.db.prepare("select id from employees where org_id = ?").get(orgId) as { id: string }).id;
|
||||
seedWorkspace(connection.db, orgId);
|
||||
reportId = migrations.createReport({ orgId, sourceDatabasePath: legacyPath });
|
||||
audit.record({
|
||||
orgId,
|
||||
entityType: "task",
|
||||
entityId: "task-cutover",
|
||||
actorType: "employee",
|
||||
actorId: employeeId,
|
||||
action: "created",
|
||||
payload: { title: "Reconcile release delta" },
|
||||
});
|
||||
rollbackId = rollback.createSnapshot({ orgId, migrationReportId: reportId, createdByEmployeeId: employeeId });
|
||||
rollback.setActive({ orgId, snapshotId: rollbackId, active: true, employeeId });
|
||||
});
|
||||
@@ -64,6 +75,19 @@ describe("rollback service", () => {
|
||||
expect(workspaceManifest.files).toHaveLength(1);
|
||||
expect(deltaJournal.length).toBeGreaterThan(0);
|
||||
expect(restorePlan).toMatchObject({ migrationReportId: reportId, restoreStrategy: "legacy_snapshot_restore" });
|
||||
expect(state.migrationCutoverEvents.map((event) => event.eventType).sort()).toEqual([
|
||||
"rollback_snapshot_activated",
|
||||
"rollback_snapshot_created",
|
||||
]);
|
||||
expect(state.migrationReconciliationItems).toContainEqual(expect.objectContaining({
|
||||
orgId,
|
||||
migrationReportId: reportId,
|
||||
rollbackSnapshotId: rollbackId,
|
||||
targetType: "task",
|
||||
targetId: "task-cutover",
|
||||
reason: "manual_delta_replay",
|
||||
state: "open",
|
||||
}));
|
||||
expect(state.auditEvents.some((event) => event.entityType === "rollback_snapshot" && event.action === "activated")).toBe(true);
|
||||
connection.close();
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user