@jini-ai/db 0.7.3-next.2 → 0.7.3-next.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +46 -1
- package/dist/core/ports.d.ts +2 -2
- package/dist/core/ports.js +2 -2
- package/dist/data-modules/data-module.d.ts +2 -46
- package/dist/data-modules/plugin-identity.d.ts +2 -11
- package/dist/data-modules/snapshot.d.ts +5 -3
- package/dist/data-modules/snapshot.js +5 -3
- package/dist/events/change-set-repo.sql.d.ts +18 -5
- package/dist/events/change-set-repo.sql.js +25 -8
- package/dist/events/index.d.ts +1 -1
- package/dist/events/outbox-repo.sql.d.ts +26 -1
- package/dist/events/outbox-repo.sql.js +36 -2
- package/dist/events/repo.rows.d.ts +22 -4
- package/dist/events/repo.rows.js +32 -4
- package/dist/kernel/idle-turn.d.ts +62 -0
- package/dist/kernel/idle-turn.js +32 -0
- package/dist/kernel/index.d.ts +1 -0
- package/dist/kernel/index.js +1 -0
- package/dist/kernel/kernel-core.js +28 -0
- package/dist/kernel/schema-scope.js +2 -0
- package/dist/kernel/sqlite/driver.js +2 -0
- package/dist/kernel/turn-lock.d.ts +2 -0
- package/dist/kernel/turn-lock.js +7 -0
- package/dist/pglite/copy-source.d.ts +45 -0
- package/dist/pglite/copy-source.js +36 -0
- package/dist/pglite/index.d.ts +1 -0
- package/dist/pglite/index.js +1 -0
- package/dist/react/recovery/Recovery.d.ts +205 -0
- package/dist/react/recovery/Recovery.js +141 -0
- package/dist/react/recovery/Recovery.restore-steps.d.ts +10 -0
- package/dist/react/recovery/Recovery.restore-steps.js +71 -0
- package/dist/recovery/agent-tools.d.ts +33 -0
- package/dist/recovery/agent-tools.js +166 -0
- package/dist/recovery/drift.d.ts +47 -0
- package/dist/recovery/drift.js +51 -0
- package/dist/recovery/journal-kernel.d.ts +80 -0
- package/dist/recovery/journal-kernel.js +40 -0
- package/dist/recovery/journal-repo.sql.d.ts +154 -0
- package/dist/recovery/journal-repo.sql.js +303 -0
- package/dist/recovery/journal-schema.d.ts +37 -0
- package/dist/recovery/journal-schema.js +110 -0
- package/dist/recovery/migrate-forward-hooks.d.ts +2 -1
- package/dist/recovery/migrate-forward-hooks.js +3 -3
- package/dist/recovery/operation-lock.d.ts +2 -17
- package/dist/recovery/reconcile-interrupted-migration.d.ts +2 -5
- package/dist/recovery/reconcile-interrupted-migration.js +0 -30
- package/dist/recovery/restore-hooks.d.ts +4 -0
- package/dist/recovery/restore-hooks.js +1 -1
- package/dist/recovery/tool-registrations.d.ts +175 -0
- package/dist/recovery/tool-registrations.js +295 -0
- package/dist/site/repo.memory.d.ts +149 -0
- package/dist/site/repo.memory.js +162 -0
- package/dist/site/tool-registrations.d.ts +130 -0
- package/dist/site/tool-registrations.js +185 -0
- package/dist/sqlite/backup-policy.d.ts +14 -0
- package/dist/sqlite/backup-policy.js +47 -3
- package/dist/sqlite/compaction-steps.d.ts +43 -0
- package/dist/sqlite/compaction-steps.js +73 -0
- package/dist/sqlite/compaction.d.ts +63 -0
- package/dist/sqlite/compaction.js +263 -0
- package/dist/sqlite/index.d.ts +2 -1
- package/dist/sqlite/index.js +2 -1
- package/dist/tools/index.d.ts +2 -0
- package/dist/tools/index.js +2 -0
- package/dist/tools/plan-store.d.ts +1 -1
- package/dist/tools/plan-store.js +10 -6
- package/dist/tools/site-db-messages.d.ts +10 -0
- package/dist/tools/site-db-messages.js +23 -0
- package/dist/tools/site-transfer-messages.d.ts +9 -0
- package/dist/tools/site-transfer-messages.js +20 -0
- package/dist/transfer/confirmation-ui.d.ts +19 -0
- package/dist/transfer/confirmation-ui.js +39 -0
- package/dist/transfer/copy-engine.js +11 -11
- package/dist/transfer/destination-store.d.ts +69 -0
- package/dist/transfer/destination-store.js +75 -0
- package/dist/transfer/index.d.ts +2 -0
- package/dist/transfer/index.js +2 -0
- package/dist/transfer/internal-ddl.d.ts +6 -2
- package/dist/transfer/internal-ddl.js +15 -15
- package/dist/transfer/postgres-ddl.js +2 -2
- package/dist/transfer/schema-catalog.d.ts +148 -0
- package/dist/transfer/schema-catalog.js +141 -0
- package/dist/transfer/sqlite-backup.d.ts +27 -0
- package/dist/transfer/sqlite-backup.js +31 -0
- package/dist/transfer/table-catalog.js +1 -0
- package/dist/watermark/kernel.d.ts +64 -0
- package/dist/watermark/kernel.js +45 -0
- package/package.json +104 -9
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import type { LedgerReadPort, LedgerRow } from "../tools/timeline.js";
|
|
2
|
+
import type { LedgerAppendPort } from "./migrate-forward-hooks.js";
|
|
3
|
+
import type { BootLedgerPort, MigrationRunsRepoPort } from "./reconcile-interrupted-migration.js";
|
|
4
|
+
import type { CreateRestorePointRepoPort } from "./restore-point-create.js";
|
|
5
|
+
import type { JournalKernel } from "./journal-kernel.js";
|
|
6
|
+
/** `database_ledger` adapter — implements both the Timeline's read port and the boot
|
|
7
|
+
* reconciliation's append port, siteId-scoped at construction. */
|
|
8
|
+
export declare class SqliteDatabaseLedgerRepo implements LedgerReadPort, BootLedgerPort {
|
|
9
|
+
private readonly deps;
|
|
10
|
+
constructor(deps: {
|
|
11
|
+
db: JournalKernel;
|
|
12
|
+
siteId: string;
|
|
13
|
+
});
|
|
14
|
+
/**
|
|
15
|
+
* REQ-01/REQ-04 — filtered, cursor-paginated read over `database_ledger`, newest-first. The
|
|
16
|
+
* cursor is an opaque `${createdAt}::${id}` composite (never a raw offset — stable under
|
|
17
|
+
* concurrent inserts).
|
|
18
|
+
*
|
|
19
|
+
* @complexity O(limit) via the `(site_id, created_at)` index; one extra row fetched to detect
|
|
20
|
+
* `nextCursor` presence without a second COUNT query.
|
|
21
|
+
* @overallScore 100
|
|
22
|
+
*/
|
|
23
|
+
query(filter: {
|
|
24
|
+
kind?: string;
|
|
25
|
+
fromDate?: string;
|
|
26
|
+
toDate?: string;
|
|
27
|
+
outcome?: string;
|
|
28
|
+
cursor?: string | null;
|
|
29
|
+
limit: number;
|
|
30
|
+
}): Promise<{
|
|
31
|
+
items: LedgerRow[];
|
|
32
|
+
nextCursor: string | null;
|
|
33
|
+
}>;
|
|
34
|
+
/** Appends one `database_ledger` row (ADR-041 §4). Never mutates or deletes an existing row —
|
|
35
|
+
* the ledger is append-only by construction. */
|
|
36
|
+
append(row: Parameters<LedgerAppendPort["append"]>[0]): Promise<void>;
|
|
37
|
+
/** SPEC-017 C-106 — converts a non-terminal `migration_runs` row into a `migration.interrupted`
|
|
38
|
+
* ledger row (ADR-041 §3's boot-time crash reconciliation).
|
|
39
|
+
*
|
|
40
|
+
* Round-5 re-audit (2026-07-16, TM-adr041-043-044-045-audit-001, codex `R5-F1-BLOCKED-RECOVERY-
|
|
41
|
+
* NOT-RESTART-SAFE` / Fable `R5-F1-INTERRUPTED-SECOND-BOOT-BRICK`, both independently confirmed
|
|
42
|
+
* by direct code inspection and Fable's empirical double-boot reproduction): `database_ledger.id`
|
|
43
|
+
* is the primary key, and this method's id (`interrupted-${migrationRunId}`) is
|
|
44
|
+
* deterministic BY DESIGN so a second boot re-detecting the SAME still-unresolved migration
|
|
45
|
+
* targets the same row. Before this fix, the plain insert this called through
|
|
46
|
+
* `append()` threw `UNIQUE constraint failed` on that second boot, which — because this is a
|
|
47
|
+
* CRITICAL boot module — failed the whole boot and `process.exit(1)`'d before `app.listen()`,
|
|
48
|
+
* making Recovery itself unreachable. `ON CONFLICT (id) DO NOTHING` makes the deterministic id do what
|
|
49
|
+
* it was always meant to: every boot re-detects and re-blocks idempotently. */
|
|
50
|
+
appendInterruptedRow(params: {
|
|
51
|
+
siteId: string;
|
|
52
|
+
migrationRunId: string;
|
|
53
|
+
}): Promise<void>;
|
|
54
|
+
}
|
|
55
|
+
/** `migration_runs` adapter — implements the boot-sequence's `MigrationRunsRepoPort`, plus the
|
|
56
|
+
* insert/status-update helpers the state machine's own persistence caller needs. */
|
|
57
|
+
export declare class SqliteMigrationRunsRepo implements MigrationRunsRepoPort {
|
|
58
|
+
private static readonly TERMINAL_STATUSES;
|
|
59
|
+
private readonly deps;
|
|
60
|
+
constructor(deps: {
|
|
61
|
+
db: JournalKernel;
|
|
62
|
+
siteId: string;
|
|
63
|
+
});
|
|
64
|
+
/**
|
|
65
|
+
* SPEC-017 C-106/C-107 (INV-08) — the single defensive read both boot-sequence steps consult:
|
|
66
|
+
* a non-null result means a crashed-mid-migration run has not yet been reconciled.
|
|
67
|
+
*
|
|
68
|
+
* @complexity O(1) via the `(site_id, status)` index.
|
|
69
|
+
* @overallScore 100
|
|
70
|
+
*/
|
|
71
|
+
findNonTerminalForSite(siteId: string): Promise<{
|
|
72
|
+
id: string;
|
|
73
|
+
status: string;
|
|
74
|
+
} | null>;
|
|
75
|
+
/** Round-5 re-audit (2026-07-16, TM-adr041-043-044-045-audit-001, R5-F1/R5-F2 fix) — terminalizes
|
|
76
|
+
* a run as `RESTORED` (a real member of `MIGRATION_RUN_TERMINAL_STATUSES`) so the next boot's
|
|
77
|
+
* `findNonTerminalForSite` no longer re-detects it. Thin wrapper over `updateState`, kept as its
|
|
78
|
+
* own port method so callers outside this file (the restore ceremony) don't need `updateState`'s
|
|
79
|
+
* full row shape. */
|
|
80
|
+
markResolved(params: {
|
|
81
|
+
id: string;
|
|
82
|
+
}): Promise<void>;
|
|
83
|
+
/** Inserts a new `migration_runs` row (state machine's initial `IDLE`/`PLANNED` write). */
|
|
84
|
+
insert(row: {
|
|
85
|
+
id: string;
|
|
86
|
+
dialect: "sqlite" | "postgres";
|
|
87
|
+
status: string;
|
|
88
|
+
correlationId?: string | null;
|
|
89
|
+
createdAt: string;
|
|
90
|
+
updatedAt: string;
|
|
91
|
+
}): Promise<void>;
|
|
92
|
+
/** Persists a state-machine transition's resulting fields against an existing row. A field left
|
|
93
|
+
* `undefined` is not written (an explicit `null` clears it). */
|
|
94
|
+
updateState(row: {
|
|
95
|
+
id: string;
|
|
96
|
+
status: string;
|
|
97
|
+
revisionSeqAtQuiesce?: number | null;
|
|
98
|
+
quiesceIntegrity?: string | null;
|
|
99
|
+
blueTouched?: boolean;
|
|
100
|
+
restorePointId?: string | null;
|
|
101
|
+
updatedAt: string;
|
|
102
|
+
}): Promise<void>;
|
|
103
|
+
}
|
|
104
|
+
/** What {@link SqliteRestorePointsRepo} is constructed with. `onPruneWarning` is the host's port for a
|
|
105
|
+
* failed cleanup of older restore-point copies: the host formats and redacts the error and decides where
|
|
106
|
+
* the warning goes, so this package never writes to a console or knows a host's secret shapes. */
|
|
107
|
+
export type RestorePointsRepoDeps = {
|
|
108
|
+
db: JournalKernel;
|
|
109
|
+
siteId: string;
|
|
110
|
+
protectedRestorePointIds?: () => Promise<ReadonlySet<string>>;
|
|
111
|
+
onPruneWarning: ({ error }: {
|
|
112
|
+
error: unknown;
|
|
113
|
+
}) => void;
|
|
114
|
+
};
|
|
115
|
+
/** `restore_points` adapter — implements `./restore-point-create.ts`'s
|
|
116
|
+
* `CreateRestorePointRepoPort`, plus the database-side persistence helper `db-ops`'s
|
|
117
|
+
* `captureRestorePoint()` result needs to become a durable row. */
|
|
118
|
+
export declare class SqliteRestorePointsRepo implements CreateRestorePointRepoPort {
|
|
119
|
+
private readonly deps;
|
|
120
|
+
constructor(deps: RestorePointsRepoDeps);
|
|
121
|
+
/** REQ-05 (recovery) / REQ-22 (database) — persists one `restore_points` row. */
|
|
122
|
+
save(row: {
|
|
123
|
+
restorePointId: string;
|
|
124
|
+
idempotencyKey: string;
|
|
125
|
+
trigger: string;
|
|
126
|
+
createdAt: string;
|
|
127
|
+
createdBy: string;
|
|
128
|
+
costClass?: string;
|
|
129
|
+
kind?: string;
|
|
130
|
+
artifactRef?: string;
|
|
131
|
+
watermarkAtCapture?: number | null;
|
|
132
|
+
capturedSchemaVersion?: number | null;
|
|
133
|
+
capturedSchemaTag?: string | null;
|
|
134
|
+
}): Promise<void>;
|
|
135
|
+
/** Row/file deletion stays in this repository; generic policy never learns the journal's schema.
|
|
136
|
+
* @complexity O(n log n) restore rows, plus two bounded-shape reference queries and one delete per expired row. */
|
|
137
|
+
private pruneCopies;
|
|
138
|
+
/** AC-11 (recovery) — `(site_id, idempotency_key)` single-row lookup. */
|
|
139
|
+
findByIdempotencyKey(key: string): Promise<{
|
|
140
|
+
restorePointId: string;
|
|
141
|
+
idempotencyKey: string;
|
|
142
|
+
} | null>;
|
|
143
|
+
/** Newest-first restore-point listing for the Recovery screen / Timeline. */
|
|
144
|
+
list(): Promise<Array<{
|
|
145
|
+
id: string;
|
|
146
|
+
trigger: string;
|
|
147
|
+
costClass: string;
|
|
148
|
+
kind: string;
|
|
149
|
+
watermarkAtCapture: number | null;
|
|
150
|
+
createdAt: string;
|
|
151
|
+
artifactRef: string;
|
|
152
|
+
}>>;
|
|
153
|
+
}
|
|
154
|
+
//# sourceMappingURL=journal-repo.sql.d.ts.map
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { decodeKeysetCursor, encodeKeysetCursor } from "@jini-ai/core/keyset-cursor";
|
|
4
|
+
import { pruneDatabaseCopies } from "../sqlite/backup-policy.js";
|
|
5
|
+
import { MIGRATION_RUN_TERMINAL_STATUSES } from "./journal-schema.js";
|
|
6
|
+
/**
|
|
7
|
+
* @file ADR-041 §2/§4 — the adapters over the sidecar `ops/database-journal.db`: Kysely queries on
|
|
8
|
+
* the journal's own kernel (`./journal-kernel.ts`), every one through `kernel.run` and awaited.
|
|
9
|
+
*
|
|
10
|
+
* Purpose:
|
|
11
|
+
* Every class here is a thin, siteId-scoped implementation of an ALREADY-DEFINED port from
|
|
12
|
+
* `../tools/` and this folder — no port shape changes, only real persistence behind
|
|
13
|
+
* them. `SqliteDatabaseLedgerRepo` doubles as `LedgerReadPort` (Timeline's read side) and
|
|
14
|
+
* `BootLedgerPort` (boot reconciliation's append side), since both operate on the same
|
|
15
|
+
* `database_ledger` table.
|
|
16
|
+
*
|
|
17
|
+
* How it relates to the project:
|
|
18
|
+
* The host's composition root constructs these against the journal kernel its journal driver binding
|
|
19
|
+
* opens alongside `content.db` (schema: `./journal-schema.ts`); the host's in-memory test composition uses
|
|
20
|
+
* simple in-process fakes instead (mirrors every other feature's app.ts/deps.ts split in the host).
|
|
21
|
+
*
|
|
22
|
+
* Architectural role:
|
|
23
|
+
* Infrastructure adapters. The journal is SQLite on every content dialect, so these keep their
|
|
24
|
+
* `Sqlite*` names.
|
|
25
|
+
*/
|
|
26
|
+
const DATE_ONLY = /^\d{4}-\d{2}-\d{2}$/;
|
|
27
|
+
/** `created_at` is a full ISO timestamp compared as a string, so a bare `2026-09-24` upper bound sorted
|
|
28
|
+
* before every row of that day and excluded it. A date-only bound means "through the end of that day".
|
|
29
|
+
* @complexity O(1). */
|
|
30
|
+
function inclusiveUpperBound({ toDate }, _optional = {}) {
|
|
31
|
+
return DATE_ONLY.test(toDate) ? `${toDate}T23:59:59.999Z` : toDate;
|
|
32
|
+
}
|
|
33
|
+
/** An optional port field that was left out is stored as SQL `NULL`, the same as an explicit `null`.
|
|
34
|
+
* @complexity O(1). */
|
|
35
|
+
function orNull({ value }, _optional = {}) {
|
|
36
|
+
return value ?? null;
|
|
37
|
+
}
|
|
38
|
+
/** `database_ledger` adapter — implements both the Timeline's read port and the boot
|
|
39
|
+
* reconciliation's append port, siteId-scoped at construction. */
|
|
40
|
+
export class SqliteDatabaseLedgerRepo {
|
|
41
|
+
deps;
|
|
42
|
+
constructor(deps) {
|
|
43
|
+
this.deps = deps;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* REQ-01/REQ-04 — filtered, cursor-paginated read over `database_ledger`, newest-first. The
|
|
47
|
+
* cursor is an opaque `${createdAt}::${id}` composite (never a raw offset — stable under
|
|
48
|
+
* concurrent inserts).
|
|
49
|
+
*
|
|
50
|
+
* @complexity O(limit) via the `(site_id, created_at)` index; one extra row fetched to detect
|
|
51
|
+
* `nextCursor` presence without a second COUNT query.
|
|
52
|
+
* @overallScore 100
|
|
53
|
+
*/
|
|
54
|
+
async query(filter) {
|
|
55
|
+
const decoded = filter.cursor ? decodeKeysetCursor({ cursor: filter.cursor }) : null;
|
|
56
|
+
const rows = await this.deps.db.run((db) => {
|
|
57
|
+
let query = db
|
|
58
|
+
.selectFrom("database_ledger")
|
|
59
|
+
.select(["id", "kind", "created_at", "restore_point_id", "outcome"])
|
|
60
|
+
.where("site_id", "=", this.deps.siteId);
|
|
61
|
+
if (filter.kind)
|
|
62
|
+
query = query.where("kind", "=", filter.kind);
|
|
63
|
+
if (filter.outcome)
|
|
64
|
+
query = query.where("outcome", "=", filter.outcome);
|
|
65
|
+
if (filter.fromDate)
|
|
66
|
+
query = query.where("created_at", ">=", filter.fromDate);
|
|
67
|
+
if (filter.toDate)
|
|
68
|
+
query = query.where("created_at", "<=", inclusiveUpperBound({ toDate: filter.toDate }));
|
|
69
|
+
if (decoded) {
|
|
70
|
+
query = query.where((eb) => eb.or([
|
|
71
|
+
eb("created_at", "<", decoded.createdAt),
|
|
72
|
+
eb.and([eb("created_at", "=", decoded.createdAt), eb("id", "<", decoded.id)]),
|
|
73
|
+
]));
|
|
74
|
+
}
|
|
75
|
+
return query.orderBy("created_at", "desc").orderBy("id", "desc").limit(filter.limit + 1).execute();
|
|
76
|
+
});
|
|
77
|
+
const page = rows.slice(0, filter.limit);
|
|
78
|
+
const items = page.map((row) => ({
|
|
79
|
+
id: row.id,
|
|
80
|
+
kind: row.kind,
|
|
81
|
+
createdAt: row.created_at,
|
|
82
|
+
restorePointId: row.restore_point_id,
|
|
83
|
+
outcome: row.outcome,
|
|
84
|
+
}));
|
|
85
|
+
const last = page[page.length - 1];
|
|
86
|
+
const nextCursor = rows.length > filter.limit && last ? encodeKeysetCursor({ createdAt: last.created_at, id: last.id }) : null;
|
|
87
|
+
return { items, nextCursor };
|
|
88
|
+
}
|
|
89
|
+
/** Appends one `database_ledger` row (ADR-041 §4). Never mutates or deletes an existing row —
|
|
90
|
+
* the ledger is append-only by construction. */
|
|
91
|
+
async append(row) {
|
|
92
|
+
await this.deps.db.run((db) => db
|
|
93
|
+
.insertInto("database_ledger")
|
|
94
|
+
.values({
|
|
95
|
+
id: row.id,
|
|
96
|
+
site_id: this.deps.siteId,
|
|
97
|
+
kind: row.kind,
|
|
98
|
+
correlation_id: orNull({ value: row.correlationId }),
|
|
99
|
+
restore_point_id: orNull({ value: row.restorePointId }),
|
|
100
|
+
schema_before_version: orNull({ value: row.schemaBeforeVersion }),
|
|
101
|
+
schema_before_tag: orNull({ value: row.schemaBeforeTag }),
|
|
102
|
+
schema_after_version: orNull({ value: row.schemaAfterVersion }),
|
|
103
|
+
schema_after_tag: orNull({ value: row.schemaAfterTag }),
|
|
104
|
+
drift_status: orNull({ value: row.driftStatus }),
|
|
105
|
+
outcome: row.outcome,
|
|
106
|
+
detail_json: orNull({ value: row.detailJson }),
|
|
107
|
+
actor_workspace_id: orNull({ value: row.actorWorkspaceId }),
|
|
108
|
+
actor_id: orNull({ value: row.actorId }),
|
|
109
|
+
delegated_by_workspace_id: orNull({ value: row.delegatedByWorkspaceId }),
|
|
110
|
+
delegated_by_id: orNull({ value: row.delegatedById }),
|
|
111
|
+
created_at: row.createdAt,
|
|
112
|
+
})
|
|
113
|
+
.execute());
|
|
114
|
+
}
|
|
115
|
+
/** SPEC-017 C-106 — converts a non-terminal `migration_runs` row into a `migration.interrupted`
|
|
116
|
+
* ledger row (ADR-041 §3's boot-time crash reconciliation).
|
|
117
|
+
*
|
|
118
|
+
* Round-5 re-audit (2026-07-16, TM-adr041-043-044-045-audit-001, codex `R5-F1-BLOCKED-RECOVERY-
|
|
119
|
+
* NOT-RESTART-SAFE` / Fable `R5-F1-INTERRUPTED-SECOND-BOOT-BRICK`, both independently confirmed
|
|
120
|
+
* by direct code inspection and Fable's empirical double-boot reproduction): `database_ledger.id`
|
|
121
|
+
* is the primary key, and this method's id (`interrupted-${migrationRunId}`) is
|
|
122
|
+
* deterministic BY DESIGN so a second boot re-detecting the SAME still-unresolved migration
|
|
123
|
+
* targets the same row. Before this fix, the plain insert this called through
|
|
124
|
+
* `append()` threw `UNIQUE constraint failed` on that second boot, which — because this is a
|
|
125
|
+
* CRITICAL boot module — failed the whole boot and `process.exit(1)`'d before `app.listen()`,
|
|
126
|
+
* making Recovery itself unreachable. `ON CONFLICT (id) DO NOTHING` makes the deterministic id do what
|
|
127
|
+
* it was always meant to: every boot re-detects and re-blocks idempotently. */
|
|
128
|
+
async appendInterruptedRow(params) {
|
|
129
|
+
await this.deps.db.run((db) => db
|
|
130
|
+
.insertInto("database_ledger")
|
|
131
|
+
.values({
|
|
132
|
+
id: `interrupted-${params.migrationRunId}`,
|
|
133
|
+
site_id: this.deps.siteId,
|
|
134
|
+
kind: "migration.interrupted",
|
|
135
|
+
restore_point_id: null,
|
|
136
|
+
outcome: "blocked_pending_recovery",
|
|
137
|
+
detail_json: JSON.stringify({ migrationRunId: params.migrationRunId }),
|
|
138
|
+
created_at: new Date().toISOString(),
|
|
139
|
+
})
|
|
140
|
+
.onConflict((oc) => oc.column("id").doNothing())
|
|
141
|
+
.execute());
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
/** `migration_runs` adapter — implements the boot-sequence's `MigrationRunsRepoPort`, plus the
|
|
145
|
+
* insert/status-update helpers the state machine's own persistence caller needs. */
|
|
146
|
+
export class SqliteMigrationRunsRepo {
|
|
147
|
+
static TERMINAL_STATUSES = new Set(MIGRATION_RUN_TERMINAL_STATUSES);
|
|
148
|
+
deps;
|
|
149
|
+
constructor(deps) {
|
|
150
|
+
this.deps = deps;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* SPEC-017 C-106/C-107 (INV-08) — the single defensive read both boot-sequence steps consult:
|
|
154
|
+
* a non-null result means a crashed-mid-migration run has not yet been reconciled.
|
|
155
|
+
*
|
|
156
|
+
* @complexity O(1) via the `(site_id, status)` index.
|
|
157
|
+
* @overallScore 100
|
|
158
|
+
*/
|
|
159
|
+
async findNonTerminalForSite(siteId) {
|
|
160
|
+
const rows = await this.deps.db.run((db) => db.selectFrom("migration_runs").select(["id", "status"]).where("site_id", "=", siteId).execute());
|
|
161
|
+
const nonTerminal = rows.find((row) => !SqliteMigrationRunsRepo.TERMINAL_STATUSES.has(row.status));
|
|
162
|
+
return nonTerminal ?? null;
|
|
163
|
+
}
|
|
164
|
+
/** Round-5 re-audit (2026-07-16, TM-adr041-043-044-045-audit-001, R5-F1/R5-F2 fix) — terminalizes
|
|
165
|
+
* a run as `RESTORED` (a real member of `MIGRATION_RUN_TERMINAL_STATUSES`) so the next boot's
|
|
166
|
+
* `findNonTerminalForSite` no longer re-detects it. Thin wrapper over `updateState`, kept as its
|
|
167
|
+
* own port method so callers outside this file (the restore ceremony) don't need `updateState`'s
|
|
168
|
+
* full row shape. */
|
|
169
|
+
async markResolved(params) {
|
|
170
|
+
await this.deps.db.run((db) => db
|
|
171
|
+
.updateTable("migration_runs")
|
|
172
|
+
.set({ status: "RESTORED", updated_at: new Date().toISOString() })
|
|
173
|
+
.where("id", "=", params.id)
|
|
174
|
+
.where("site_id", "=", this.deps.siteId)
|
|
175
|
+
.execute());
|
|
176
|
+
}
|
|
177
|
+
/** Inserts a new `migration_runs` row (state machine's initial `IDLE`/`PLANNED` write). */
|
|
178
|
+
async insert(row) {
|
|
179
|
+
await this.deps.db.run((db) => db
|
|
180
|
+
.insertInto("migration_runs")
|
|
181
|
+
.values({
|
|
182
|
+
id: row.id,
|
|
183
|
+
site_id: this.deps.siteId,
|
|
184
|
+
dialect: row.dialect,
|
|
185
|
+
status: row.status,
|
|
186
|
+
blue_touched: 0,
|
|
187
|
+
correlation_id: orNull({ value: row.correlationId }),
|
|
188
|
+
created_at: row.createdAt,
|
|
189
|
+
updated_at: row.updatedAt,
|
|
190
|
+
})
|
|
191
|
+
.execute());
|
|
192
|
+
}
|
|
193
|
+
/** Persists a state-machine transition's resulting fields against an existing row. A field left
|
|
194
|
+
* `undefined` is not written (an explicit `null` clears it). */
|
|
195
|
+
async updateState(row) {
|
|
196
|
+
const set = { status: row.status, updated_at: row.updatedAt };
|
|
197
|
+
if (row.revisionSeqAtQuiesce !== undefined)
|
|
198
|
+
set.revision_seq_at_quiesce = row.revisionSeqAtQuiesce;
|
|
199
|
+
if (row.quiesceIntegrity !== undefined)
|
|
200
|
+
set.quiesce_integrity = row.quiesceIntegrity;
|
|
201
|
+
if (row.blueTouched !== undefined)
|
|
202
|
+
set.blue_touched = row.blueTouched ? 1 : 0;
|
|
203
|
+
if (row.restorePointId !== undefined)
|
|
204
|
+
set.restore_point_id = row.restorePointId;
|
|
205
|
+
await this.deps.db.run((db) => db
|
|
206
|
+
.updateTable("migration_runs")
|
|
207
|
+
.set(set)
|
|
208
|
+
.where("site_id", "=", this.deps.siteId)
|
|
209
|
+
.where("id", "=", row.id)
|
|
210
|
+
.execute());
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
/** `restore_points` adapter — implements `./restore-point-create.ts`'s
|
|
214
|
+
* `CreateRestorePointRepoPort`, plus the database-side persistence helper `db-ops`'s
|
|
215
|
+
* `captureRestorePoint()` result needs to become a durable row. */
|
|
216
|
+
export class SqliteRestorePointsRepo {
|
|
217
|
+
deps;
|
|
218
|
+
constructor(deps) {
|
|
219
|
+
this.deps = deps;
|
|
220
|
+
}
|
|
221
|
+
/** REQ-05 (recovery) / REQ-22 (database) — persists one `restore_points` row. */
|
|
222
|
+
async save(row) {
|
|
223
|
+
await this.deps.db.run((db) => db
|
|
224
|
+
.insertInto("restore_points")
|
|
225
|
+
.values({
|
|
226
|
+
id: row.restorePointId,
|
|
227
|
+
site_id: this.deps.siteId,
|
|
228
|
+
trigger: row.trigger,
|
|
229
|
+
cost_class: row.costClass ?? "cheap",
|
|
230
|
+
kind: row.kind ?? "file-snapshot",
|
|
231
|
+
artifact_ref: row.artifactRef ?? "",
|
|
232
|
+
watermark_at_capture: orNull({ value: row.watermarkAtCapture }),
|
|
233
|
+
captured_schema_version: orNull({ value: row.capturedSchemaVersion }),
|
|
234
|
+
captured_schema_tag: orNull({ value: row.capturedSchemaTag }),
|
|
235
|
+
idempotency_key: row.idempotencyKey,
|
|
236
|
+
actor_id: row.createdBy,
|
|
237
|
+
created_at: row.createdAt,
|
|
238
|
+
})
|
|
239
|
+
.execute());
|
|
240
|
+
if (!row.artifactRef)
|
|
241
|
+
return;
|
|
242
|
+
try {
|
|
243
|
+
await this.pruneCopies({ justWritten: row.artifactRef });
|
|
244
|
+
}
|
|
245
|
+
catch (error) {
|
|
246
|
+
// The copy and its row are saved; cleanup must not turn the operation that needed them into an error.
|
|
247
|
+
this.deps.onPruneWarning({ error });
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
/** Row/file deletion stays in this repository; generic policy never learns the journal's schema.
|
|
251
|
+
* @complexity O(n log n) restore rows, plus two bounded-shape reference queries and one delete per expired row. */
|
|
252
|
+
async pruneCopies({ justWritten }) {
|
|
253
|
+
const rows = (await this.list()).filter(row => /^restore-point-[A-Za-z0-9_-]+-wm\d+-\d+\.db$/.test(path.basename(row.artifactRef)));
|
|
254
|
+
// In-flight publishes and unfinished migrations may still roll back to their copy.
|
|
255
|
+
const protectedIds = new Set(await this.deps.protectedRestorePointIds?.());
|
|
256
|
+
const migrations = await this.deps.db.run(db => db.selectFrom("migration_runs").select("restore_point_id")
|
|
257
|
+
.where("site_id", "=", this.deps.siteId).where("status", "not in", [...MIGRATION_RUN_TERMINAL_STATUSES]).execute());
|
|
258
|
+
for (const row of migrations)
|
|
259
|
+
if (row.restore_point_id)
|
|
260
|
+
protectedIds.add(row.restore_point_id);
|
|
261
|
+
await pruneDatabaseCopies({ justWritten, copies: rows.map(row => ({ filePath: row.artifactRef, createdAt: Date.parse(row.createdAt) })) }, {
|
|
262
|
+
protectedPaths: new Set(rows.filter(row => protectedIds.has(row.id)).map(row => row.artifactRef)),
|
|
263
|
+
remove: async ({ filePath }) => {
|
|
264
|
+
// An unlink refusal leaves its row visible and retryable; never report a retained file as gone.
|
|
265
|
+
await fs.rm(filePath, { force: true });
|
|
266
|
+
await this.deps.db.run(db => db.deleteFrom("restore_points").where("site_id", "=", this.deps.siteId).where("artifact_ref", "=", filePath).execute());
|
|
267
|
+
},
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
/** AC-11 (recovery) — `(site_id, idempotency_key)` single-row lookup. */
|
|
271
|
+
async findByIdempotencyKey(key) {
|
|
272
|
+
const row = await this.deps.db.run((db) => db
|
|
273
|
+
.selectFrom("restore_points")
|
|
274
|
+
.select(["id", "idempotency_key"])
|
|
275
|
+
.where("site_id", "=", this.deps.siteId)
|
|
276
|
+
.where("idempotency_key", "=", key)
|
|
277
|
+
.limit(1)
|
|
278
|
+
.executeTakeFirst());
|
|
279
|
+
return row && row.idempotency_key ? { restorePointId: row.id, idempotencyKey: row.idempotency_key } : null;
|
|
280
|
+
}
|
|
281
|
+
/** Newest-first restore-point listing for the Recovery screen / Timeline. */
|
|
282
|
+
async list() {
|
|
283
|
+
const rows = await this.deps.db.run((db) => db
|
|
284
|
+
.selectFrom("restore_points")
|
|
285
|
+
// `artifact_ref` was once never selected — see `save()` for the matching write side and
|
|
286
|
+
// `./restore-hooks.ts`'s `buildRestoreHooks` for why the omission mattered
|
|
287
|
+
// (the restore ceremony had no way to know which file to restore from).
|
|
288
|
+
.select(["id", "trigger", "cost_class", "kind", "watermark_at_capture", "created_at", "artifact_ref"])
|
|
289
|
+
.where("site_id", "=", this.deps.siteId)
|
|
290
|
+
.orderBy("created_at", "desc")
|
|
291
|
+
.execute());
|
|
292
|
+
return rows.map((row) => ({
|
|
293
|
+
id: row.id,
|
|
294
|
+
trigger: row.trigger,
|
|
295
|
+
costClass: row.cost_class,
|
|
296
|
+
kind: row.kind,
|
|
297
|
+
watermarkAtCapture: row.watermark_at_capture,
|
|
298
|
+
createdAt: row.created_at,
|
|
299
|
+
artifactRef: row.artifact_ref,
|
|
300
|
+
}));
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
//# sourceMappingURL=journal-repo.sql.js.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { JournalKernel } from "./journal-kernel.js";
|
|
2
|
+
/**
|
|
3
|
+
* @file DDL for the sidecar `ops/database-journal.db` (ADR-041 §2). SQLite by design: the journal
|
|
4
|
+
* is a local SQLite file on every dialect (see `./journal-kernel.ts`, which types these tables).
|
|
5
|
+
*
|
|
6
|
+
* Purpose:
|
|
7
|
+
* `database_ledger`, `migration_runs`, and `restore_points` — the three tables ADR-041 §2/§4
|
|
8
|
+
* requires to live OUTSIDE `content.db`, in a physically separate SQLite file, so that restoring
|
|
9
|
+
* `content.db` from a snapshot never erases the incident record that snapshot restore is supposed
|
|
10
|
+
* to narrate, and boot recovery can append a `migration.interrupted` row even when `content.db`
|
|
11
|
+
* itself won't open. Never merged into the `content.db` schema.
|
|
12
|
+
*
|
|
13
|
+
* The statements are exactly what the journal's former Drizzle migrations
|
|
14
|
+
* (`../drizzle-database-journal/` 0000 + 0001) left on disk — same columns, defaults and index
|
|
15
|
+
* names (the ledger's indexes kept their `idx_storage_ledger_*` names through the 0001 rename) —
|
|
16
|
+
* made idempotent, so a file those migrations already built is left as it is. A file only 0000
|
|
17
|
+
* ever touched still has `storage_ledger`; {@link applyDatabaseJournalSchema} renames it first.
|
|
18
|
+
*
|
|
19
|
+
* Composite actor identity (`actor_workspace_id`/`actor_id`, `delegated_by_workspace_id`/
|
|
20
|
+
* `delegated_by_id`) is a soft, value-join reference only — SQLite has no cross-database FK, so this
|
|
21
|
+
* is NOT a DB-enforced foreign key against `content.db`'s `principals` table (ADR-041 §4).
|
|
22
|
+
*
|
|
23
|
+
* `SITE_SCOPE_EXEMPT_TABLES` (ADR-041 §4, extending ADR-007 Decision 2's workspace-less-events
|
|
24
|
+
* escape hatch to these three tables): every row here carries `site_id` (never `workspace_id`) — a
|
|
25
|
+
* deliberate, disclosed extension, not a silent gap.
|
|
26
|
+
*/
|
|
27
|
+
/** Terminal `migration_runs.status` values a row is never found by `findNonTerminalForSite`. */
|
|
28
|
+
export declare const MIGRATION_RUN_TERMINAL_STATUSES: readonly ["DONE", "ABORTED_SAFE", "RESTORED", "RESTORE_FAILED", "ROLLBACK_TO_BLUE"];
|
|
29
|
+
/**
|
|
30
|
+
* Brings the journal file behind `kernel` to the current schema, in one transaction: renames a
|
|
31
|
+
* pre-0001 `storage_ledger` to `database_ledger`, then creates whatever is missing. Idempotent.
|
|
32
|
+
* Called on the kernel's own (ungated) connection before any repo query runs.
|
|
33
|
+
*/
|
|
34
|
+
export declare function applyDatabaseJournalSchema({ kernel }: {
|
|
35
|
+
kernel: JournalKernel;
|
|
36
|
+
}, _optional?: Record<string, never>): Promise<void>;
|
|
37
|
+
//# sourceMappingURL=journal-schema.d.ts.map
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { sql } from "kysely";
|
|
2
|
+
/**
|
|
3
|
+
* @file DDL for the sidecar `ops/database-journal.db` (ADR-041 §2). SQLite by design: the journal
|
|
4
|
+
* is a local SQLite file on every dialect (see `./journal-kernel.ts`, which types these tables).
|
|
5
|
+
*
|
|
6
|
+
* Purpose:
|
|
7
|
+
* `database_ledger`, `migration_runs`, and `restore_points` — the three tables ADR-041 §2/§4
|
|
8
|
+
* requires to live OUTSIDE `content.db`, in a physically separate SQLite file, so that restoring
|
|
9
|
+
* `content.db` from a snapshot never erases the incident record that snapshot restore is supposed
|
|
10
|
+
* to narrate, and boot recovery can append a `migration.interrupted` row even when `content.db`
|
|
11
|
+
* itself won't open. Never merged into the `content.db` schema.
|
|
12
|
+
*
|
|
13
|
+
* The statements are exactly what the journal's former Drizzle migrations
|
|
14
|
+
* (`../drizzle-database-journal/` 0000 + 0001) left on disk — same columns, defaults and index
|
|
15
|
+
* names (the ledger's indexes kept their `idx_storage_ledger_*` names through the 0001 rename) —
|
|
16
|
+
* made idempotent, so a file those migrations already built is left as it is. A file only 0000
|
|
17
|
+
* ever touched still has `storage_ledger`; {@link applyDatabaseJournalSchema} renames it first.
|
|
18
|
+
*
|
|
19
|
+
* Composite actor identity (`actor_workspace_id`/`actor_id`, `delegated_by_workspace_id`/
|
|
20
|
+
* `delegated_by_id`) is a soft, value-join reference only — SQLite has no cross-database FK, so this
|
|
21
|
+
* is NOT a DB-enforced foreign key against `content.db`'s `principals` table (ADR-041 §4).
|
|
22
|
+
*
|
|
23
|
+
* `SITE_SCOPE_EXEMPT_TABLES` (ADR-041 §4, extending ADR-007 Decision 2's workspace-less-events
|
|
24
|
+
* escape hatch to these three tables): every row here carries `site_id` (never `workspace_id`) — a
|
|
25
|
+
* deliberate, disclosed extension, not a silent gap.
|
|
26
|
+
*/
|
|
27
|
+
/** Terminal `migration_runs.status` values a row is never found by `findNonTerminalForSite`. */
|
|
28
|
+
// MigrationRunStatus (features/database/migrate-forward/state-machine.ts) was deleted 2026-10-03: unused; this schema owns the persisted terminal values; see the host's development/DELETED-CODE.md.
|
|
29
|
+
export const MIGRATION_RUN_TERMINAL_STATUSES = ["DONE", "ABORTED_SAFE", "RESTORED", "RESTORE_FAILED", "ROLLBACK_TO_BLUE"];
|
|
30
|
+
/**
|
|
31
|
+
* `database_ledger` is the never-brick ledger (ADR-041 §1/§4): append-only; `restore_point_id` is
|
|
32
|
+
* NULL only for `index.provision`/`index.drop` rows (the ADR-023 §4 carve-out). `migration_runs` has
|
|
33
|
+
* one row per migrate-forward attempt (ADR-041 §3). `restore_points` has one row per restore-point
|
|
34
|
+
* artifact (ADR-041 §2); `watermark_at_capture` is nullable so a legacy row needs no fabricated value.
|
|
35
|
+
*/
|
|
36
|
+
const DATABASE_JOURNAL_DDL = [
|
|
37
|
+
sql `CREATE TABLE IF NOT EXISTS migration_runs (
|
|
38
|
+
id text PRIMARY KEY NOT NULL,
|
|
39
|
+
site_id text NOT NULL,
|
|
40
|
+
dialect text NOT NULL,
|
|
41
|
+
status text NOT NULL,
|
|
42
|
+
revision_seq_at_quiesce integer,
|
|
43
|
+
quiesce_integrity text,
|
|
44
|
+
blue_touched integer DEFAULT 0 NOT NULL,
|
|
45
|
+
correlation_id text,
|
|
46
|
+
restore_point_id text,
|
|
47
|
+
actor_workspace_id text,
|
|
48
|
+
actor_id text,
|
|
49
|
+
delegated_by_workspace_id text,
|
|
50
|
+
delegated_by_id text,
|
|
51
|
+
created_at text NOT NULL,
|
|
52
|
+
updated_at text NOT NULL
|
|
53
|
+
)`,
|
|
54
|
+
sql `CREATE INDEX IF NOT EXISTS idx_migration_runs_site_status ON migration_runs (site_id, status)`,
|
|
55
|
+
sql `CREATE TABLE IF NOT EXISTS restore_points (
|
|
56
|
+
id text PRIMARY KEY NOT NULL,
|
|
57
|
+
site_id text NOT NULL,
|
|
58
|
+
trigger text NOT NULL,
|
|
59
|
+
cost_class text NOT NULL,
|
|
60
|
+
kind text NOT NULL,
|
|
61
|
+
artifact_ref text NOT NULL,
|
|
62
|
+
watermark_at_capture integer,
|
|
63
|
+
captured_schema_version integer,
|
|
64
|
+
captured_schema_tag text,
|
|
65
|
+
size_bytes integer,
|
|
66
|
+
idempotency_key text,
|
|
67
|
+
actor_workspace_id text,
|
|
68
|
+
actor_id text,
|
|
69
|
+
created_at text NOT NULL
|
|
70
|
+
)`,
|
|
71
|
+
sql `CREATE INDEX IF NOT EXISTS idx_restore_points_site_created ON restore_points (site_id, created_at)`,
|
|
72
|
+
sql `CREATE UNIQUE INDEX IF NOT EXISTS idx_restore_points_site_idempotency_key ON restore_points (site_id, idempotency_key)`,
|
|
73
|
+
sql `CREATE TABLE IF NOT EXISTS database_ledger (
|
|
74
|
+
id text PRIMARY KEY NOT NULL,
|
|
75
|
+
site_id text NOT NULL,
|
|
76
|
+
kind text NOT NULL,
|
|
77
|
+
correlation_id text,
|
|
78
|
+
restore_point_id text,
|
|
79
|
+
schema_before_version integer,
|
|
80
|
+
schema_before_tag text,
|
|
81
|
+
schema_after_version integer,
|
|
82
|
+
schema_after_tag text,
|
|
83
|
+
drift_status text,
|
|
84
|
+
outcome text NOT NULL,
|
|
85
|
+
detail_json text,
|
|
86
|
+
actor_workspace_id text,
|
|
87
|
+
actor_id text,
|
|
88
|
+
delegated_by_workspace_id text,
|
|
89
|
+
delegated_by_id text,
|
|
90
|
+
created_at text NOT NULL
|
|
91
|
+
)`,
|
|
92
|
+
sql `CREATE INDEX IF NOT EXISTS idx_storage_ledger_site_created ON database_ledger (site_id, created_at)`,
|
|
93
|
+
sql `CREATE INDEX IF NOT EXISTS idx_storage_ledger_site_kind ON database_ledger (site_id, kind)`,
|
|
94
|
+
];
|
|
95
|
+
/**
|
|
96
|
+
* Brings the journal file behind `kernel` to the current schema, in one transaction: renames a
|
|
97
|
+
* pre-0001 `storage_ledger` to `database_ledger`, then creates whatever is missing. Idempotent.
|
|
98
|
+
* Called on the kernel's own (ungated) connection before any repo query runs.
|
|
99
|
+
*/
|
|
100
|
+
export async function applyDatabaseJournalSchema({ kernel }, _optional = {}) {
|
|
101
|
+
await kernel.transaction(async () => {
|
|
102
|
+
const tables = new Set((await kernel.run((db) => db.introspection.getTables())).map((table) => table.name));
|
|
103
|
+
if (tables.has("storage_ledger") && !tables.has("database_ledger")) {
|
|
104
|
+
await kernel.execute(sql `ALTER TABLE storage_ledger RENAME TO database_ledger`);
|
|
105
|
+
}
|
|
106
|
+
for (const statement of DATABASE_JOURNAL_DDL)
|
|
107
|
+
await kernel.execute(statement);
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=journal-schema.js.map
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Clock as ClockPort, IdGenerator as IdGeneratorPort } from "@jini-ai/core/primitives";
|
|
2
|
+
import type { MutationActor } from "@jini-ai/core/contracts/events";
|
|
2
3
|
import type { GatedMutationHooks } from "@jini-ai/core/gated-mutations";
|
|
3
4
|
import type { RecoveryHookPolicy } from "./hook-policy.js";
|
|
4
5
|
/**
|
|
@@ -52,7 +53,7 @@ export interface MigrateForwardDbOpsPort {
|
|
|
52
53
|
}
|
|
53
54
|
export interface BuildMigrateForwardHooksInput extends RecoveryHookPolicy {
|
|
54
55
|
workspaceId: string;
|
|
55
|
-
|
|
56
|
+
actor: MutationActor;
|
|
56
57
|
clock: ClockPort;
|
|
57
58
|
idGen: IdGeneratorPort;
|
|
58
59
|
dbOps: MigrateForwardDbOpsPort;
|
|
@@ -61,7 +61,7 @@ export function buildMigrateForwardHooks(input, _optional = {}) {
|
|
|
61
61
|
idempotencyKey: restorePointId,
|
|
62
62
|
trigger: "migrate-forward",
|
|
63
63
|
createdAt: now,
|
|
64
|
-
createdBy: input.
|
|
64
|
+
createdBy: input.actor.id,
|
|
65
65
|
costClass: capabilities.restorePoint.costClass,
|
|
66
66
|
kind: capabilities.restorePoint.kind,
|
|
67
67
|
watermarkAtCapture: captured.watermarkAtCapture,
|
|
@@ -72,9 +72,9 @@ export function buildMigrateForwardHooks(input, _optional = {}) {
|
|
|
72
72
|
kind: "core.migration",
|
|
73
73
|
restorePointId,
|
|
74
74
|
outcome: "success",
|
|
75
|
-
detailJson: JSON.stringify({ artifactRef: captured.artifactRef }),
|
|
75
|
+
detailJson: JSON.stringify({ artifactRef: captured.artifactRef, actor: { id: input.actor.id, kind: input.actor.kind } }),
|
|
76
76
|
actorWorkspaceId: input.workspaceId,
|
|
77
|
-
actorId: input.
|
|
77
|
+
actorId: input.actor.id,
|
|
78
78
|
createdAt: now,
|
|
79
79
|
});
|
|
80
80
|
return { migrated: true };
|