@objectstack/metadata 17.2.0 → 17.4.0
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/CHANGELOG.md +1967 -0
- package/README.md +6 -4
- package/dist/errors.cjs +1 -85
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.cts +1 -22
- package/dist/errors.d.ts +1 -22
- package/dist/errors.js +2 -84
- package/dist/errors.js.map +1 -1
- package/dist/index.cjs +1014 -302
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +496 -29
- package/dist/index.d.ts +496 -29
- package/dist/index.js +1013 -299
- package/dist/index.js.map +1 -1
- package/dist/migrations/index.cjs +175 -67
- package/dist/migrations/index.cjs.map +1 -1
- package/dist/migrations/index.d.cts +97 -15
- package/dist/migrations/index.d.ts +97 -15
- package/dist/migrations/index.js +178 -67
- package/dist/migrations/index.js.map +1 -1
- package/dist/node.cjs +1014 -302
- package/dist/node.cjs.map +1 -1
- package/dist/node.d.cts +156 -3
- package/dist/node.d.ts +156 -3
- package/dist/node.js +1013 -299
- package/dist/node.js.map +1 -1
- package/dist/view-container.cjs +37 -0
- package/dist/view-container.cjs.map +1 -0
- package/dist/view-container.d.cts +76 -0
- package/dist/view-container.d.ts +76 -0
- package/dist/view-container.js +12 -0
- package/dist/view-container.js.map +1 -0
- package/package.json +52 -21
|
@@ -27,23 +27,37 @@ __export(migrations_exports, {
|
|
|
27
27
|
});
|
|
28
28
|
module.exports = __toCommonJS(migrations_exports);
|
|
29
29
|
|
|
30
|
+
// src/migrations/driver-exec.ts
|
|
31
|
+
function resolveDriverExec(driver) {
|
|
32
|
+
const candidate = driver;
|
|
33
|
+
if (!candidate) return void 0;
|
|
34
|
+
if (typeof candidate.execute === "function") {
|
|
35
|
+
return (sql, bindings) => candidate.execute(sql, bindings ? [...bindings] : []);
|
|
36
|
+
}
|
|
37
|
+
if (typeof candidate.raw === "function") {
|
|
38
|
+
return (sql, bindings) => candidate.raw(sql, bindings ? [...bindings] : []);
|
|
39
|
+
}
|
|
40
|
+
return void 0;
|
|
41
|
+
}
|
|
42
|
+
function driverExecRefusal(helper) {
|
|
43
|
+
return `${helper}: driver must expose an .execute(sql, bindings?) or .raw(sql, bindings?) method. SqlDriver (better-sqlite3/knex) exposes .execute(), as does its SqliteWasmDriver subclass; cloud-side TursoDriver also conforms.`;
|
|
44
|
+
}
|
|
45
|
+
|
|
30
46
|
// src/migrations/migrate-env-id-to-project-id.ts
|
|
31
47
|
var AFFECTED_TABLES = [
|
|
32
48
|
"sys_metadata",
|
|
33
49
|
"sys_metadata_history"
|
|
34
50
|
];
|
|
35
51
|
async function migrateEnvIdToProjectId(driver) {
|
|
36
|
-
const
|
|
37
|
-
if (
|
|
38
|
-
throw new Error(
|
|
39
|
-
"migrateEnvIdToProjectId: driver must expose a .raw(sql, bindings?) method. SqlDriver (better-sqlite3/knex) supports this; cloud-side TursoDriver also conforms."
|
|
40
|
-
);
|
|
52
|
+
const exec = resolveDriverExec(driver);
|
|
53
|
+
if (!exec) {
|
|
54
|
+
throw new Error(driverExecRefusal("migrateEnvIdToProjectId"));
|
|
41
55
|
}
|
|
42
56
|
const results = [];
|
|
43
57
|
for (const table of AFFECTED_TABLES) {
|
|
44
58
|
try {
|
|
45
|
-
const hasColumn = await _columnExists(
|
|
46
|
-
const alreadyMigrated = await _columnExists(
|
|
59
|
+
const hasColumn = await _columnExists(exec, table, "env_id");
|
|
60
|
+
const alreadyMigrated = await _columnExists(exec, table, "project_id");
|
|
47
61
|
if (alreadyMigrated && !hasColumn) {
|
|
48
62
|
results.push({ table, status: "already_done" });
|
|
49
63
|
continue;
|
|
@@ -52,7 +66,7 @@ async function migrateEnvIdToProjectId(driver) {
|
|
|
52
66
|
results.push({ table, status: "table_missing" });
|
|
53
67
|
continue;
|
|
54
68
|
}
|
|
55
|
-
await
|
|
69
|
+
await exec(`ALTER TABLE "${table}" RENAME COLUMN env_id TO project_id`);
|
|
56
70
|
results.push({ table, status: "renamed" });
|
|
57
71
|
} catch (err) {
|
|
58
72
|
results.push({ table, status: "error", error: err?.message ?? String(err) });
|
|
@@ -60,14 +74,14 @@ async function migrateEnvIdToProjectId(driver) {
|
|
|
60
74
|
}
|
|
61
75
|
return results;
|
|
62
76
|
}
|
|
63
|
-
async function _columnExists(
|
|
77
|
+
async function _columnExists(exec, table, column) {
|
|
64
78
|
try {
|
|
65
|
-
const rows = await
|
|
79
|
+
const rows = await exec(`PRAGMA table_info("${table}")`);
|
|
66
80
|
if (Array.isArray(rows) && rows.length > 0) {
|
|
67
81
|
const list2 = Array.isArray(rows[0]) ? rows[0] : rows;
|
|
68
82
|
return list2.some((r) => r?.name === column);
|
|
69
83
|
}
|
|
70
|
-
const result = await
|
|
84
|
+
const result = await exec(
|
|
71
85
|
`SELECT column_name FROM information_schema.columns WHERE table_name = ? AND column_name = ?`,
|
|
72
86
|
[table, column]
|
|
73
87
|
);
|
|
@@ -79,22 +93,29 @@ async function _columnExists(driver, table, column) {
|
|
|
79
93
|
}
|
|
80
94
|
|
|
81
95
|
// src/migrations/migrate-project-id-to-environment-id.ts
|
|
82
|
-
var
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
];
|
|
96
|
+
var import_metadata_core = require("@objectstack/metadata-core");
|
|
97
|
+
var SOURCE_COLUMN = "project_id";
|
|
98
|
+
var TARGET_COLUMN = "environment_id";
|
|
99
|
+
var CANDIDATE_OBJECTS = [import_metadata_core.SysMetadataObject, import_metadata_core.SysMetadataHistoryObject];
|
|
100
|
+
function declaresColumn(object, column) {
|
|
101
|
+
return Object.prototype.hasOwnProperty.call(object.fields ?? {}, column);
|
|
102
|
+
}
|
|
103
|
+
var CANDIDATE_TABLES = CANDIDATE_OBJECTS.map((o) => o.name);
|
|
104
|
+
var AFFECTED_TABLES2 = CANDIDATE_OBJECTS.filter((o) => declaresColumn(o, TARGET_COLUMN)).map((o) => o.name);
|
|
86
105
|
async function migrateProjectIdToEnvironmentId(driver) {
|
|
87
|
-
const
|
|
88
|
-
if (
|
|
89
|
-
throw new Error(
|
|
90
|
-
"migrateProjectIdToEnvironmentId: driver must expose a .raw(sql, bindings?) method. migrateProjectIdToEnvironmentId: driver must expose a .raw(sql, bindings?) method. SqlDriver (better-sqlite3/knex) supports this; cloud-side TursoDriver also conforms."
|
|
91
|
-
);
|
|
106
|
+
const exec = resolveDriverExec(driver);
|
|
107
|
+
if (!exec) {
|
|
108
|
+
throw new Error(driverExecRefusal("migrateProjectIdToEnvironmentId"));
|
|
92
109
|
}
|
|
93
110
|
const results = [];
|
|
94
|
-
for (const table of
|
|
111
|
+
for (const table of CANDIDATE_TABLES) {
|
|
112
|
+
if (!AFFECTED_TABLES2.includes(table)) {
|
|
113
|
+
results.push({ table, status: "skipped_not_declared" });
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
95
116
|
try {
|
|
96
|
-
const hasColumn = await _columnExists2(
|
|
97
|
-
const alreadyMigrated = await _columnExists2(
|
|
117
|
+
const hasColumn = await _columnExists2(exec, table, SOURCE_COLUMN);
|
|
118
|
+
const alreadyMigrated = await _columnExists2(exec, table, TARGET_COLUMN);
|
|
98
119
|
if (alreadyMigrated && !hasColumn) {
|
|
99
120
|
results.push({ table, status: "already_done" });
|
|
100
121
|
continue;
|
|
@@ -103,8 +124,8 @@ async function migrateProjectIdToEnvironmentId(driver) {
|
|
|
103
124
|
results.push({ table, status: "table_missing" });
|
|
104
125
|
continue;
|
|
105
126
|
}
|
|
106
|
-
await
|
|
107
|
-
`ALTER TABLE "${table}" RENAME COLUMN
|
|
127
|
+
await exec(
|
|
128
|
+
`ALTER TABLE "${table}" RENAME COLUMN ${SOURCE_COLUMN} TO ${TARGET_COLUMN}`
|
|
108
129
|
);
|
|
109
130
|
results.push({ table, status: "renamed" });
|
|
110
131
|
} catch (err) {
|
|
@@ -113,14 +134,14 @@ async function migrateProjectIdToEnvironmentId(driver) {
|
|
|
113
134
|
}
|
|
114
135
|
return results;
|
|
115
136
|
}
|
|
116
|
-
async function _columnExists2(
|
|
137
|
+
async function _columnExists2(exec, table, column) {
|
|
117
138
|
try {
|
|
118
|
-
const rows = await
|
|
139
|
+
const rows = await exec(`PRAGMA table_info("${table}")`);
|
|
119
140
|
if (Array.isArray(rows) && rows.length > 0) {
|
|
120
141
|
const list2 = Array.isArray(rows[0]) ? rows[0] : rows;
|
|
121
142
|
return list2.some((r) => r?.name === column);
|
|
122
143
|
}
|
|
123
|
-
const result = await
|
|
144
|
+
const result = await exec(
|
|
124
145
|
`SELECT column_name FROM information_schema.columns WHERE table_name = ? AND column_name = ?`,
|
|
125
146
|
[table, column]
|
|
126
147
|
);
|
|
@@ -140,14 +161,14 @@ var DEPRECATED_TABLES = [
|
|
|
140
161
|
"sys_tool"
|
|
141
162
|
];
|
|
142
163
|
async function dropProjectionTables(driver) {
|
|
143
|
-
const
|
|
144
|
-
if (
|
|
145
|
-
throw new Error("dropProjectionTables
|
|
164
|
+
const exec = resolveDriverExec(driver);
|
|
165
|
+
if (!exec) {
|
|
166
|
+
throw new Error(driverExecRefusal("dropProjectionTables"));
|
|
146
167
|
}
|
|
147
168
|
const results = [];
|
|
148
169
|
for (const table of DEPRECATED_TABLES) {
|
|
149
170
|
try {
|
|
150
|
-
await
|
|
171
|
+
await exec(`DROP TABLE IF EXISTS ${table}`);
|
|
151
172
|
results.push({ table, status: "dropped" });
|
|
152
173
|
} catch (error) {
|
|
153
174
|
results.push({
|
|
@@ -161,9 +182,11 @@ async function dropProjectionTables(driver) {
|
|
|
161
182
|
}
|
|
162
183
|
|
|
163
184
|
// src/migrations/migrate-sys-notification-to-event.ts
|
|
185
|
+
var import_system = require("@objectstack/spec/system");
|
|
164
186
|
var EVENT_OBJECT = "sys_notification";
|
|
165
187
|
var INBOX_OBJECT = "sys_inbox_message";
|
|
166
188
|
var RECEIPT_OBJECT = "sys_notification_receipt";
|
|
189
|
+
var HISTORICAL_IMPORT = { context: { preserveAudit: true } };
|
|
167
190
|
var LEGACY_COLUMNS = [
|
|
168
191
|
"recipient_id",
|
|
169
192
|
"type",
|
|
@@ -175,57 +198,70 @@ var LEGACY_COLUMNS = [
|
|
|
175
198
|
"read_at"
|
|
176
199
|
];
|
|
177
200
|
async function migrateSysNotificationToEvent(opts) {
|
|
178
|
-
const driver = opts.driver;
|
|
179
|
-
const { data } = opts;
|
|
180
201
|
const now = opts.now ?? (() => (/* @__PURE__ */ new Date()).toISOString());
|
|
181
|
-
|
|
202
|
+
const outcome = await runNotificationEventMigration(opts, now);
|
|
203
|
+
const receipt = await recordNotificationEventReceipt(opts.data, outcome.status, now());
|
|
204
|
+
return { ...outcome, receipt };
|
|
205
|
+
}
|
|
206
|
+
async function runNotificationEventMigration(opts, now) {
|
|
207
|
+
const { data } = opts;
|
|
208
|
+
const exec = resolveDriverExec(opts.driver);
|
|
209
|
+
if (!exec) {
|
|
182
210
|
return {
|
|
183
211
|
status: "error",
|
|
184
212
|
migrated: 0,
|
|
185
|
-
error: "migrateSysNotificationToEvent
|
|
213
|
+
error: driverExecRefusal("migrateSysNotificationToEvent")
|
|
186
214
|
};
|
|
187
215
|
}
|
|
188
|
-
if (!await columnExists(
|
|
216
|
+
if (!await columnExists(exec, EVENT_OBJECT, "recipient_id")) {
|
|
189
217
|
return { status: "not_applicable", migrated: 0 };
|
|
190
218
|
}
|
|
191
219
|
const presentLegacy = [];
|
|
192
220
|
for (const col of LEGACY_COLUMNS) {
|
|
193
|
-
if (await columnExists(
|
|
221
|
+
if (await columnExists(exec, EVENT_OBJECT, col)) presentLegacy.push(col);
|
|
194
222
|
}
|
|
195
223
|
let migrated = 0;
|
|
196
224
|
try {
|
|
197
|
-
const rows = await selectLegacyRows(
|
|
225
|
+
const rows = await selectLegacyRows(exec);
|
|
198
226
|
if (rows.length === 0) return { status: "already_done", migrated: 0 };
|
|
199
227
|
for (const row of rows) {
|
|
200
228
|
const id = String(row.id);
|
|
201
229
|
const recipientId = row.recipient_id != null ? String(row.recipient_id) : null;
|
|
202
230
|
if (!recipientId) continue;
|
|
203
231
|
const orgId = row.organization_id != null ? String(row.organization_id) : null;
|
|
204
|
-
const createdAt = row.created_at != null ?
|
|
232
|
+
const createdAt = row.created_at != null ? canonicalTimestampText(row.created_at) : now();
|
|
205
233
|
const title = row.title != null ? String(row.title) : row.type != null ? String(row.type) : "Notification";
|
|
206
234
|
const isRead = row.is_read === true || row.is_read === 1 || row.is_read === "1";
|
|
207
235
|
const eventTopic = row.type != null && String(row.type).length > 0 ? String(row.type) : "legacy";
|
|
208
|
-
await data.insert(
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
236
|
+
await data.insert(
|
|
237
|
+
INBOX_OBJECT,
|
|
238
|
+
{
|
|
239
|
+
user_id: recipientId,
|
|
240
|
+
notification_id: id,
|
|
241
|
+
topic: eventTopic,
|
|
242
|
+
title,
|
|
243
|
+
body_md: row.body ?? null,
|
|
244
|
+
severity: "info",
|
|
245
|
+
action_url: row.url ?? null,
|
|
246
|
+
organization_id: orgId,
|
|
247
|
+
created_at: createdAt
|
|
248
|
+
},
|
|
249
|
+
HISTORICAL_IMPORT
|
|
250
|
+
);
|
|
251
|
+
await data.insert(
|
|
252
|
+
RECEIPT_OBJECT,
|
|
253
|
+
{
|
|
254
|
+
notification_id: id,
|
|
255
|
+
delivery_id: null,
|
|
256
|
+
user_id: recipientId,
|
|
257
|
+
channel: "inbox",
|
|
258
|
+
state: isRead ? "read" : "delivered",
|
|
259
|
+
at: isRead && row.read_at != null ? canonicalTimestampText(row.read_at) : createdAt,
|
|
260
|
+
organization_id: orgId,
|
|
261
|
+
created_at: createdAt
|
|
262
|
+
},
|
|
263
|
+
HISTORICAL_IMPORT
|
|
264
|
+
);
|
|
229
265
|
await data.update(
|
|
230
266
|
EVENT_OBJECT,
|
|
231
267
|
{
|
|
@@ -243,7 +279,7 @@ async function migrateSysNotificationToEvent(opts) {
|
|
|
243
279
|
);
|
|
244
280
|
if (presentLegacy.length > 0) {
|
|
245
281
|
const setClause = presentLegacy.map((c) => `"${c}" = NULL`).join(", ");
|
|
246
|
-
await
|
|
282
|
+
await exec(`UPDATE "${EVENT_OBJECT}" SET ${setClause} WHERE id = ?`, [id]);
|
|
247
283
|
}
|
|
248
284
|
migrated += 1;
|
|
249
285
|
}
|
|
@@ -252,8 +288,80 @@ async function migrateSysNotificationToEvent(opts) {
|
|
|
252
288
|
return { status: "error", migrated, error: err?.message ?? String(err) };
|
|
253
289
|
}
|
|
254
290
|
}
|
|
255
|
-
|
|
256
|
-
|
|
291
|
+
var LEDGER_CLAIM = {
|
|
292
|
+
migrated: { claims: true, appliesBackfill: true },
|
|
293
|
+
already_done: { claims: true, appliesBackfill: false },
|
|
294
|
+
not_applicable: { claims: true, appliesBackfill: false },
|
|
295
|
+
// An `error` run writes NO ledger claim at all — it does not know what it
|
|
296
|
+
// did, so it may not say.
|
|
297
|
+
error: { claims: false, appliesBackfill: false }
|
|
298
|
+
};
|
|
299
|
+
var LEDGER_METHODS = ["getObject", "find", "insert", "update"];
|
|
300
|
+
function resolveMigrationLedger(data) {
|
|
301
|
+
const candidate = data;
|
|
302
|
+
for (const method of LEDGER_METHODS) {
|
|
303
|
+
if (typeof candidate[method] !== "function") return void 0;
|
|
304
|
+
}
|
|
305
|
+
return candidate;
|
|
306
|
+
}
|
|
307
|
+
function buildNotificationEventClaim(status, now, exists) {
|
|
308
|
+
const claim = LEDGER_CLAIM[status];
|
|
309
|
+
const row = {
|
|
310
|
+
id: import_system.NOTIFICATION_EVENT_MIGRATION_ID,
|
|
311
|
+
last_run_at: now,
|
|
312
|
+
blocking: 0,
|
|
313
|
+
details: JSON.stringify({ outcome: status }),
|
|
314
|
+
updated_at: now
|
|
315
|
+
};
|
|
316
|
+
if (claim.appliesBackfill) row.applied_at = now;
|
|
317
|
+
if (!exists) {
|
|
318
|
+
row.applied_at = claim.appliesBackfill ? now : null;
|
|
319
|
+
row.verified_at = null;
|
|
320
|
+
row.created_at = now;
|
|
321
|
+
}
|
|
322
|
+
return row;
|
|
323
|
+
}
|
|
324
|
+
async function recordNotificationEventReceipt(data, status, now) {
|
|
325
|
+
if (!LEDGER_CLAIM[status].claims) return { outcome: "not-claimed" };
|
|
326
|
+
const ledger = resolveMigrationLedger(data);
|
|
327
|
+
if (!ledger) {
|
|
328
|
+
return {
|
|
329
|
+
outcome: "no-ledger",
|
|
330
|
+
reason: `the \`data\` engine carries no object registry (${LEDGER_METHODS.join("/")}), so ${import_system.DATA_MIGRATION_FLAG_OBJECT} cannot be reached from here`
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
try {
|
|
334
|
+
if (!ledger.getObject(import_system.DATA_MIGRATION_FLAG_OBJECT)) {
|
|
335
|
+
return {
|
|
336
|
+
outcome: "no-ledger",
|
|
337
|
+
reason: `${import_system.DATA_MIGRATION_FLAG_OBJECT} is not registered on this kernel \u2014 compose PlatformObjectsPlugin, which carries the deployment ledger`
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
const context = { isSystem: true };
|
|
341
|
+
const rows = await ledger.find(
|
|
342
|
+
import_system.DATA_MIGRATION_FLAG_OBJECT,
|
|
343
|
+
{ where: { id: import_system.NOTIFICATION_EVENT_MIGRATION_ID }, limit: 1 },
|
|
344
|
+
{ context }
|
|
345
|
+
);
|
|
346
|
+
const exists = rows?.[0]?.id === import_system.NOTIFICATION_EVENT_MIGRATION_ID;
|
|
347
|
+
const row = buildNotificationEventClaim(status, now, exists);
|
|
348
|
+
if (exists) {
|
|
349
|
+
await ledger.update(import_system.DATA_MIGRATION_FLAG_OBJECT, row, { context });
|
|
350
|
+
return { outcome: "updated" };
|
|
351
|
+
}
|
|
352
|
+
await ledger.insert(import_system.DATA_MIGRATION_FLAG_OBJECT, row, { context });
|
|
353
|
+
return { outcome: "inserted" };
|
|
354
|
+
} catch (err) {
|
|
355
|
+
return { outcome: "failed", reason: err?.message ?? String(err) };
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
function canonicalTimestampText(value) {
|
|
359
|
+
if (typeof value === "string") return value;
|
|
360
|
+
if (value instanceof Date) return value.toISOString();
|
|
361
|
+
return String(value);
|
|
362
|
+
}
|
|
363
|
+
async function selectLegacyRows(exec) {
|
|
364
|
+
const result = await exec(
|
|
257
365
|
`SELECT id, recipient_id, type, title, body, url, actor_name, is_read, read_at, created_at, organization_id FROM "${EVENT_OBJECT}" WHERE recipient_id IS NOT NULL`
|
|
258
366
|
);
|
|
259
367
|
if (Array.isArray(result) && result.length > 0 && Array.isArray(result[0])) {
|
|
@@ -261,9 +369,9 @@ async function selectLegacyRows(driver) {
|
|
|
261
369
|
}
|
|
262
370
|
return Array.isArray(result) ? result : [];
|
|
263
371
|
}
|
|
264
|
-
async function columnExists(
|
|
372
|
+
async function columnExists(exec, table, column) {
|
|
265
373
|
try {
|
|
266
|
-
const rows = await
|
|
374
|
+
const rows = await exec(`PRAGMA table_info("${table}")`);
|
|
267
375
|
const list = Array.isArray(rows) ? Array.isArray(rows[0]) ? rows[0] : rows : [];
|
|
268
376
|
if (list.length > 0 && list.some((r) => r?.name != null)) {
|
|
269
377
|
return list.some((r) => r?.name === column);
|
|
@@ -271,7 +379,7 @@ async function columnExists(driver, table, column) {
|
|
|
271
379
|
} catch {
|
|
272
380
|
}
|
|
273
381
|
try {
|
|
274
|
-
const result = await
|
|
382
|
+
const result = await exec(
|
|
275
383
|
`SELECT column_name FROM information_schema.columns WHERE table_name = ? AND column_name = ?`,
|
|
276
384
|
[table, column]
|
|
277
385
|
);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/migrations/index.ts","../../src/migrations/migrate-env-id-to-project-id.ts","../../src/migrations/migrate-project-id-to-environment-id.ts","../../src/migrations/drop-projection-tables.ts","../../src/migrations/migrate-sys-notification-to-event.ts"],"sourcesContent":["// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.\n\n/**\n * @objectstack/metadata/migrations\n *\n * One-off database migrations for the metadata storage layer.\n */\n\nexport { migrateEnvIdToProjectId, type MigrationResult } from './migrate-env-id-to-project-id.js';\nexport {\n migrateProjectIdToEnvironmentId,\n type ProjectIdToEnvironmentIdResult,\n} from './migrate-project-id-to-environment-id.js';\nexport { dropProjectionTables, type DropProjectionResult } from './drop-projection-tables.js';\n\n/**\n * ⚰️ TOMBSTONE — `addSysMetadataOverlayIndex` / `add-sys-metadata-overlay-index.ts`\n * was REMOVED in #6771. Do not reintroduce a producer for\n * `idx_sys_metadata_overlay_active` in this package.\n *\n * It was the second producer of that ONE index name, and it still spelled the\n * PRE-ADR-0048 key `(type, name, organization_id, environment_id, scope)` —\n * `environment_id` is retired (always NULL on new rows, and SQL UNIQUE treats\n * NULLs as DISTINCT, so the index constrained nothing) and `scope` is not in\n * the current discriminator. Because both producers used `IF NOT EXISTS`,\n * whichever ran first claimed the name and the other silently no-opped.\n *\n * Measured on real SQLite before removal (#6771):\n * - on a normal boot the DECLARED index (metadata-core's\n * `sys-metadata.object.ts`, materialized by `SqlDriver.syncDeclaredIndexes`)\n * already holds the name with the CURRENT key\n * `(type, name, organization_id, package_id)`, so this function was a no-op\n * that nevertheless reported `status: 'created'`;\n * - in the only window where it was NOT a no-op (table present, declared\n * indexes not yet materialized) it installed the RETIRED key, and\n * `syncDeclaredIndexes` — which skips by name — then never repaired it.\n * So it could only ever do nothing or do harm.\n *\n * The two producers that remain are both correctly keyed and deliberate:\n * - `metadata-protocol`'s `ensureMetadataOverlayIndexes` (runtime, raw SQL):\n * the partial, NULL-safe form `(type, name, organization_id,\n * COALESCE(package_id, '')) WHERE state = 'active'`;\n * - the declaration in `metadata-core`'s `sys-metadata.object.ts`: the\n * coarser unrestricted UNIQUE that a driver without that runtime migration\n * gets, as that file's own comment states.\n */\n\n\nexport {\n migrateSysNotificationToEvent,\n type SysNotificationMigrationResult,\n type SysNotificationMigrationOptions,\n} from './migrate-sys-notification-to-event.js';\n","// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.\n\n/**\n * Migration: env_id → project_id\n *\n * Renames the `env_id` column to `project_id` on the metadata storage tables:\n * - sys_metadata\n * - sys_metadata_history\n *\n * (The per-type projection tables `sys_object` / `sys_view` / `sys_flow` /\n * `sys_agent` / `sys_tool` were removed in 2026-05 along with the projection\n * pipeline — see ADR 0005 addendum. They are intentionally not included.)\n *\n * Safe to run multiple times (idempotent): checks for column existence before\n * attempting to rename. If `project_id` already exists, the step is skipped.\n *\n * Usage:\n * import { migrateEnvIdToProjectId } from '@objectstack/metadata/migrations';\n * await migrateEnvIdToProjectId(driver);\n */\n\nimport type { IDataDriver } from '@objectstack/spec/contracts';\n\nconst AFFECTED_TABLES = [\n 'sys_metadata',\n 'sys_metadata_history',\n] as const;\n\nexport interface MigrationResult {\n table: string;\n status: 'renamed' | 'already_done' | 'table_missing' | 'error';\n error?: string;\n}\n\n/**\n * Rename `env_id` → `project_id` on all metadata tables.\n *\n * @param driver An IDataDriver with access to the target database.\n * Must expose a raw query method: `driver.raw(sql, bindings?)`.\n * @returns Per-table migration results.\n */\nexport async function migrateEnvIdToProjectId(driver: IDataDriver): Promise<MigrationResult[]> {\n const driverAny = driver as any;\n\n if (typeof driverAny.raw !== 'function') {\n throw new Error(\n 'migrateEnvIdToProjectId: driver must expose a .raw(sql, bindings?) method. ' +\n 'SqlDriver (better-sqlite3/knex) supports this; cloud-side TursoDriver also conforms.'\n );\n }\n\n const results: MigrationResult[] = [];\n\n for (const table of AFFECTED_TABLES) {\n try {\n // Detect dialect: SQLite uses PRAGMA, others use information_schema.\n const hasColumn = await _columnExists(driverAny, table, 'env_id');\n const alreadyMigrated = await _columnExists(driverAny, table, 'project_id');\n\n if (alreadyMigrated && !hasColumn) {\n results.push({ table, status: 'already_done' });\n continue;\n }\n\n if (!hasColumn) {\n // Neither column exists — table might not exist yet.\n results.push({ table, status: 'table_missing' });\n continue;\n }\n\n // Perform the rename. SQLite ≥ 3.25.0 supports ALTER TABLE RENAME COLUMN.\n await driverAny.raw(`ALTER TABLE \"${table}\" RENAME COLUMN env_id TO project_id`);\n\n results.push({ table, status: 'renamed' });\n } catch (err: any) {\n results.push({ table, status: 'error', error: err?.message ?? String(err) });\n }\n }\n\n return results;\n}\n\n// ---------------------------------------------------------------------------\n// Internal helpers\n// ---------------------------------------------------------------------------\n\nasync function _columnExists(driver: any, table: string, column: string): Promise<boolean> {\n try {\n // SQLite: PRAGMA table_info returns rows with `name` column.\n const rows: any[] = await driver.raw(`PRAGMA table_info(\"${table}\")`);\n if (Array.isArray(rows) && rows.length > 0) {\n // knex wraps PRAGMA result; handle both `rows` and `rows[0]` shapes.\n const list: any[] = Array.isArray(rows[0]) ? rows[0] : rows;\n return list.some((r: any) => r?.name === column);\n }\n\n // Fallback for non-SQLite: query information_schema.\n const result: any[] = await driver.raw(\n `SELECT column_name FROM information_schema.columns WHERE table_name = ? AND column_name = ?`,\n [table, column]\n );\n const list: any[] = Array.isArray(result[0]) ? result[0] : result;\n return list.length > 0;\n } catch {\n return false;\n }\n}\n","// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.\n\n/**\n * Migration: project_id → environment_id\n *\n * Renames the `project_id` column to `environment_id` on the metadata\n * storage tables:\n * - sys_metadata\n * - sys_metadata_history\n *\n * Forward counterpart of {@link migrateEnvIdToProjectId} (which performed the\n * earlier `env_id → project_id` rename). Together they let an operator walk an\n * old schema all the way forward in two steps:\n *\n * migrateEnvIdToProjectId(driver); // env_id → project_id (legacy)\n * migrateProjectIdToEnvironmentId(driver); // project_id → environment_id (v5)\n *\n * (The per-type projection tables `sys_object` / `sys_view` / `sys_flow` /\n * `sys_agent` / `sys_tool` were removed in 2026-05 along with the projection\n * pipeline — see ADR 0005 addendum. They are intentionally not included.)\n *\n * Safe to run multiple times (idempotent): checks for column existence before\n * attempting to rename. If `environment_id` already exists, the step is\n * skipped.\n *\n * Usage:\n * import { migrateProjectIdToEnvironmentId } from '@objectstack/metadata/migrations';\n * await migrateProjectIdToEnvironmentId(driver);\n */\n\nimport type { IDataDriver } from '@objectstack/spec/contracts';\n\nconst AFFECTED_TABLES = [\n 'sys_metadata',\n 'sys_metadata_history',\n] as const;\n\nexport interface ProjectIdToEnvironmentIdResult {\n table: string;\n status: 'renamed' | 'already_done' | 'table_missing' | 'error';\n error?: string;\n}\n\n/**\n * Rename `project_id` → `environment_id` on all metadata tables.\n *\n * @param driver An IDataDriver with access to the target database.\n * Must expose a raw query method: `driver.raw(sql, bindings?)`.\n * @returns Per-table migration results.\n */\nexport async function migrateProjectIdToEnvironmentId(\n driver: IDataDriver,\n): Promise<ProjectIdToEnvironmentIdResult[]> {\n const driverAny = driver as any;\n\n if (typeof driverAny.raw !== 'function') {\n throw new Error(\n 'migrateProjectIdToEnvironmentId: driver must expose a .raw(sql, bindings?) method. ' +\n 'migrateProjectIdToEnvironmentId: driver must expose a .raw(sql, bindings?) method. ' +\n 'SqlDriver (better-sqlite3/knex) supports this; cloud-side TursoDriver also conforms.'\n );\n }\n\n const results: ProjectIdToEnvironmentIdResult[] = [];\n\n for (const table of AFFECTED_TABLES) {\n try {\n const hasColumn = await _columnExists(driverAny, table, 'project_id');\n const alreadyMigrated = await _columnExists(driverAny, table, 'environment_id');\n\n if (alreadyMigrated && !hasColumn) {\n results.push({ table, status: 'already_done' });\n continue;\n }\n\n if (!hasColumn) {\n results.push({ table, status: 'table_missing' });\n continue;\n }\n\n await driverAny.raw(\n `ALTER TABLE \"${table}\" RENAME COLUMN project_id TO environment_id`,\n );\n\n results.push({ table, status: 'renamed' });\n } catch (err: any) {\n results.push({ table, status: 'error', error: err?.message ?? String(err) });\n }\n }\n\n return results;\n}\n\n// ---------------------------------------------------------------------------\n// Internal helpers\n// ---------------------------------------------------------------------------\n\nasync function _columnExists(driver: any, table: string, column: string): Promise<boolean> {\n try {\n const rows: any[] = await driver.raw(`PRAGMA table_info(\"${table}\")`);\n if (Array.isArray(rows) && rows.length > 0) {\n const list: any[] = Array.isArray(rows[0]) ? rows[0] : rows;\n return list.some((r: any) => r?.name === column);\n }\n\n const result: any[] = await driver.raw(\n `SELECT column_name FROM information_schema.columns WHERE table_name = ? AND column_name = ?`,\n [table, column],\n );\n const list: any[] = Array.isArray(result[0]) ? result[0] : result;\n return list.length > 0;\n } catch {\n return false;\n }\n}\n","// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.\n\n/**\n * Migration: drop deprecated metadata projection tables.\n *\n * In 2026-05 the per-type projection tables (`sys_object` / `sys_view` /\n * `sys_flow` / `sys_agent` / `sys_tool`) and the corresponding\n * `MetadataProjector` were removed (see ADR 0005 addendum). All metadata\n * now lives as JSON inside `sys_metadata` — these projection tables are\n * dead weight on any existing database.\n *\n * This migration drops them if present. It is idempotent and safe to run\n * on databases that never had them (the `DROP TABLE IF EXISTS` is a no-op).\n *\n * Usage:\n * import { dropProjectionTables } from '@objectstack/metadata/migrations';\n * await dropProjectionTables(driver);\n */\n\nimport type { IDataDriver } from '@objectstack/spec/contracts';\n\nconst DEPRECATED_TABLES = [\n 'sys_object',\n 'sys_view',\n 'sys_flow',\n 'sys_agent',\n 'sys_tool',\n] as const;\n\nexport interface DropProjectionResult {\n table: string;\n status: 'dropped' | 'not_present' | 'error';\n error?: string;\n}\n\n/**\n * Drop the deprecated per-type metadata projection tables.\n *\n * @param driver An `IDataDriver` with `driver.raw(sql, bindings?)` access.\n * @returns Per-table results.\n */\nexport async function dropProjectionTables(driver: IDataDriver): Promise<DropProjectionResult[]> {\n const driverAny = driver as any;\n if (typeof driverAny.raw !== 'function') {\n throw new Error('dropProjectionTables: driver must expose a raw(sql) method');\n }\n\n const results: DropProjectionResult[] = [];\n for (const table of DEPRECATED_TABLES) {\n try {\n await driverAny.raw(`DROP TABLE IF EXISTS ${table}`);\n results.push({ table, status: 'dropped' });\n } catch (error) {\n results.push({\n table,\n status: 'error',\n error: error instanceof Error ? error.message : String(error),\n });\n }\n }\n return results;\n}\n","// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.\n\n/**\n * Migration: sys_notification (per-user inbox) → notification event (ADR-0030)\n *\n * ADR-0030 re-models `sys_notification` from a per-user *inbox* into the L2\n * *event* (one row per `emit`). This migration preserves users' existing bell\n * notifications across the cut-over by splitting each legacy row into the new\n * layered model:\n *\n * legacy sys_notification row (recipient_id, type, title, body, url,\n * actor_name, is_read, read_at, …)\n * │\n * ├─► sys_inbox_message (L5 in-app materialization, keyed by user)\n * ├─► sys_notification_receipt (L5 read-state: 'read' if is_read else 'delivered')\n * └─► the sys_notification row itself is rewritten to the event shape\n * (topic ← type, payload ← {title,body,url,actor_name}) and its legacy\n * inbox columns are cleared.\n *\n * Idempotent: it acts only on rows that still carry the legacy shape\n * (`recipient_id IS NOT NULL`); a second run is a no-op. Safe when the legacy\n * columns were never present (a fresh install created directly in the new\n * shape) — it reports `not_applicable`.\n *\n * Usage:\n * import { migrateSysNotificationToEvent } from '@objectstack/metadata/migrations';\n * await migrateSysNotificationToEvent({ driver, data });\n *\n * `driver` provides raw access to read legacy columns the re-modeled schema no\n * longer projects and to clear them; `data` (IDataEngine) performs the\n * structured inbox/receipt writes and the event rewrite so ids, JSON fields and\n * tenant stamping are handled uniformly across drivers.\n */\n\nimport type { IDataDriver, IDataEngine } from '@objectstack/spec/contracts';\n\nconst EVENT_OBJECT = 'sys_notification';\nconst INBOX_OBJECT = 'sys_inbox_message';\nconst RECEIPT_OBJECT = 'sys_notification_receipt';\n\n/** Legacy inbox columns cleared once a row is rewritten to the event shape. */\nconst LEGACY_COLUMNS = [\n 'recipient_id',\n 'type',\n 'title',\n 'body',\n 'url',\n 'actor_name',\n 'is_read',\n 'read_at',\n] as const;\n\nexport interface SysNotificationMigrationResult {\n status: 'migrated' | 'already_done' | 'not_applicable' | 'error';\n /** Number of legacy rows split into inbox + receipt + event. */\n migrated: number;\n error?: string;\n}\n\nexport interface SysNotificationMigrationOptions {\n driver: IDataDriver;\n data: IDataEngine;\n /** Defaults to `() => new Date().toISOString()`. */\n now?(): string;\n}\n\nexport async function migrateSysNotificationToEvent(\n opts: SysNotificationMigrationOptions,\n): Promise<SysNotificationMigrationResult> {\n const driver = opts.driver as any;\n const { data } = opts;\n const now = opts.now ?? (() => new Date().toISOString());\n\n if (typeof driver?.raw !== 'function') {\n return {\n status: 'error',\n migrated: 0,\n error: 'migrateSysNotificationToEvent: driver must expose a .raw(sql, bindings?) method.',\n };\n }\n\n // No legacy `recipient_id` column → the table never held the inbox shape.\n if (!(await columnExists(driver, EVENT_OBJECT, 'recipient_id'))) {\n return { status: 'not_applicable', migrated: 0 };\n }\n\n // Only null-out columns that actually exist on this deployment.\n const presentLegacy: string[] = [];\n for (const col of LEGACY_COLUMNS) {\n if (await columnExists(driver, EVENT_OBJECT, col)) presentLegacy.push(col);\n }\n\n let migrated = 0;\n try {\n const rows = await selectLegacyRows(driver);\n if (rows.length === 0) return { status: 'already_done', migrated: 0 };\n\n for (const row of rows) {\n const id = String(row.id);\n const recipientId = row.recipient_id != null ? String(row.recipient_id) : null;\n if (!recipientId) continue; // defensive — guarded by the SELECT filter\n const orgId = row.organization_id != null ? String(row.organization_id) : null;\n const createdAt = row.created_at != null ? String(row.created_at) : now();\n const title = row.title != null ? String(row.title) : (row.type != null ? String(row.type) : 'Notification');\n const isRead = row.is_read === true || row.is_read === 1 || row.is_read === '1';\n // One topic for both the inbox row and the rewritten event, so the\n // materialization and its L2 event never disagree (empty/null legacy\n // `type` → 'legacy').\n const eventTopic = row.type != null && String(row.type).length > 0 ? String(row.type) : 'legacy';\n\n // L5 in-app materialization.\n await data.insert(INBOX_OBJECT, {\n user_id: recipientId,\n notification_id: id,\n topic: eventTopic,\n title,\n body_md: row.body ?? null,\n severity: 'info',\n action_url: row.url ?? null,\n organization_id: orgId,\n created_at: createdAt,\n });\n\n // L5 receipt (read-state spine).\n await data.insert(RECEIPT_OBJECT, {\n notification_id: id,\n delivery_id: null,\n user_id: recipientId,\n channel: 'inbox',\n state: isRead ? 'read' : 'delivered',\n at: isRead && row.read_at != null ? String(row.read_at) : createdAt,\n organization_id: orgId,\n created_at: createdAt,\n });\n\n // Rewrite the row itself to the L2 event shape (engine handles JSON).\n await data.update(\n EVENT_OBJECT,\n {\n id,\n topic: eventTopic,\n severity: 'info',\n payload: {\n title: row.title ?? null,\n body: row.body ?? null,\n url: row.url ?? null,\n actorName: row.actor_name ?? null,\n },\n },\n { where: { id } },\n );\n\n // Clear the legacy inbox columns so the row no longer matches the\n // migration filter (idempotency) and carries no stale recipient.\n if (presentLegacy.length > 0) {\n const setClause = presentLegacy.map((c) => `\"${c}\" = NULL`).join(', ');\n await driver.raw(`UPDATE \"${EVENT_OBJECT}\" SET ${setClause} WHERE id = ?`, [id]);\n }\n\n migrated += 1;\n }\n\n return { status: 'migrated', migrated };\n } catch (err: any) {\n return { status: 'error', migrated, error: err?.message ?? String(err) };\n }\n}\n\n// ---------------------------------------------------------------------------\n// Internal helpers\n// ---------------------------------------------------------------------------\n\nasync function selectLegacyRows(driver: any): Promise<any[]> {\n const result: any[] = await driver.raw(\n `SELECT id, recipient_id, type, title, body, url, actor_name, is_read, read_at, created_at, organization_id ` +\n `FROM \"${EVENT_OBJECT}\" WHERE recipient_id IS NOT NULL`,\n );\n // knex wraps some results as `[rows]`; normalize both shapes.\n if (Array.isArray(result) && result.length > 0 && Array.isArray(result[0])) {\n return result[0];\n }\n return Array.isArray(result) ? result : [];\n}\n\nasync function columnExists(driver: any, table: string, column: string): Promise<boolean> {\n // SQLite path: PRAGMA table_info. On Postgres/others this raises a syntax\n // error — swallow it *locally* and fall through to information_schema (the\n // outer-catch version of this would never reach the fallback, making the\n // migration silently no-op on every non-SQLite DB).\n try {\n const rows: any = await driver.raw(`PRAGMA table_info(\"${table}\")`);\n const list: any[] = Array.isArray(rows)\n ? (Array.isArray(rows[0]) ? rows[0] : rows)\n : [];\n if (list.length > 0 && list.some((r: any) => r?.name != null)) {\n return list.some((r: any) => r?.name === column);\n }\n } catch {\n /* not SQLite — fall through to information_schema */\n }\n // Postgres / others.\n try {\n const result: any = await driver.raw(\n `SELECT column_name FROM information_schema.columns WHERE table_name = ? AND column_name = ?`,\n [table, column],\n );\n const list: any[] = Array.isArray(result)\n ? (Array.isArray(result[0]) ? result[0] : result)\n : [];\n return list.length > 0;\n } catch {\n return false;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACuBA,IAAM,kBAAkB;AAAA,EACpB;AAAA,EACA;AACJ;AAeA,eAAsB,wBAAwB,QAAiD;AAC3F,QAAM,YAAY;AAElB,MAAI,OAAO,UAAU,QAAQ,YAAY;AACrC,UAAM,IAAI;AAAA,MACN;AAAA,IAEJ;AAAA,EACJ;AAEA,QAAM,UAA6B,CAAC;AAEpC,aAAW,SAAS,iBAAiB;AACjC,QAAI;AAEA,YAAM,YAAY,MAAM,cAAc,WAAW,OAAO,QAAQ;AAChE,YAAM,kBAAkB,MAAM,cAAc,WAAW,OAAO,YAAY;AAE1E,UAAI,mBAAmB,CAAC,WAAW;AAC/B,gBAAQ,KAAK,EAAE,OAAO,QAAQ,eAAe,CAAC;AAC9C;AAAA,MACJ;AAEA,UAAI,CAAC,WAAW;AAEZ,gBAAQ,KAAK,EAAE,OAAO,QAAQ,gBAAgB,CAAC;AAC/C;AAAA,MACJ;AAGA,YAAM,UAAU,IAAI,gBAAgB,KAAK,sCAAsC;AAE/E,cAAQ,KAAK,EAAE,OAAO,QAAQ,UAAU,CAAC;AAAA,IAC7C,SAAS,KAAU;AACf,cAAQ,KAAK,EAAE,OAAO,QAAQ,SAAS,OAAO,KAAK,WAAW,OAAO,GAAG,EAAE,CAAC;AAAA,IAC/E;AAAA,EACJ;AAEA,SAAO;AACX;AAMA,eAAe,cAAc,QAAa,OAAe,QAAkC;AACvF,MAAI;AAEA,UAAM,OAAc,MAAM,OAA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eAAe,iBAAiB,QAA6B;AACzD,QAAM,SAAgB,MAAM,OAAO;AAAA,IAC/B,oHACa,YAAY;AAAA,EAC7B;AAEA,MAAI,MAAM,QAAQ,MAAM,KAAK,OAAO,SAAS,KAAK,MAAM,QAAQ,OAAO,CAAC,CAAC,GAAG;AACxE,WAAO,OAAO,CAAC;AAAA,EACnB;AACA,SAAO,MAAM,QAAQ,MAAM,IAAI,SAAS,CAAC;AAC7C;AAEA,eAAe,aAAa,QAAa,OAAe,QAAkC;AAKtF,MAAI;AACA,UAAM,OAAY,MAAM,OAAO,IAAI,sBAAsB,KAAK,IAAI;AAClE,UAAM,OAAc,MAAM,QAAQ,IAAI,IAC/B,MAAM,QAAQ,KAAK,CAAC,CAAC,IAAI,KAAK,CAAC,IAAI,OACpC,CAAC;AACP,QAAI,KAAK,SAAS,KAAK,KAAK,KAAK,CAAC,MAAW,GAAG,QAAQ,IAAI,GAAG;AAC3D,aAAO,KAAK,KAAK,CAAC,MAAW,GAAG,SAAS,MAAM;AAAA,IACnD;AAAA,EACJ,QAAQ;AAAA,EAER;AAEA,MAAI;AACA,UAAM,SAAc,MAAM,OAAO;AAAA,MAC7B;AAAA,MACA,CAAC,OAAO,MAAM;AAAA,IAClB;AACA,UAAM,OAAc,MAAM,QAAQ,MAAM,IACjC,MAAM,QAAQ,OAAO,CAAC,CAAC,IAAI,OAAO,CAAC,IAAI,SACxC,CAAC;AACP,WAAO,KAAK,SAAS;AAAA,EACzB,QAAQ;AACJ,WAAO;AAAA,EACX;AACJ;","names":["list","AFFECTED_TABLES","_columnExists","list"]}
|
|
1
|
+
{"version":3,"sources":["../../src/migrations/index.ts","../../src/migrations/driver-exec.ts","../../src/migrations/migrate-env-id-to-project-id.ts","../../src/migrations/migrate-project-id-to-environment-id.ts","../../src/migrations/drop-projection-tables.ts","../../src/migrations/migrate-sys-notification-to-event.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA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I,SACxC,CAAC;AACP,WAAO,KAAK,SAAS;AAAA,EACzB,QAAQ;AACJ,WAAO;AAAA,EACX;AACJ;","names":["list","AFFECTED_TABLES","_columnExists","list"]}
|
|
@@ -27,8 +27,10 @@ interface MigrationResult {
|
|
|
27
27
|
/**
|
|
28
28
|
* Rename `env_id` → `project_id` on all metadata tables.
|
|
29
29
|
*
|
|
30
|
-
* @param driver An IDataDriver with access to the target database.
|
|
31
|
-
*
|
|
30
|
+
* @param driver An IDataDriver with access to the target database. Raw SQL is
|
|
31
|
+
* issued through the surface `IDataDriver` declares —
|
|
32
|
+
* `execute(sql, bindings?)` — falling back to
|
|
33
|
+
* `raw(sql, bindings?)`; see `./driver-exec.ts`.
|
|
32
34
|
* @returns Per-table migration results.
|
|
33
35
|
*/
|
|
34
36
|
declare function migrateEnvIdToProjectId(driver: IDataDriver): Promise<MigrationResult[]>;
|
|
@@ -36,10 +38,9 @@ declare function migrateEnvIdToProjectId(driver: IDataDriver): Promise<Migration
|
|
|
36
38
|
/**
|
|
37
39
|
* Migration: project_id → environment_id
|
|
38
40
|
*
|
|
39
|
-
* Renames the `project_id` column to `environment_id` on the metadata
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
* - sys_metadata_history
|
|
41
|
+
* Renames the `project_id` column to `environment_id` on the metadata storage
|
|
42
|
+
* tables — but only on the tables whose CURRENT declaration actually knows
|
|
43
|
+
* `environment_id`.
|
|
43
44
|
*
|
|
44
45
|
* Forward counterpart of {@link migrateEnvIdToProjectId} (which performed the
|
|
45
46
|
* earlier `env_id → project_id` rename). Together they let an operator walk an
|
|
@@ -48,6 +49,35 @@ declare function migrateEnvIdToProjectId(driver: IDataDriver): Promise<Migration
|
|
|
48
49
|
* migrateEnvIdToProjectId(driver); // env_id → project_id (legacy)
|
|
49
50
|
* migrateProjectIdToEnvironmentId(driver); // project_id → environment_id (v5)
|
|
50
51
|
*
|
|
52
|
+
* ─────────────────────────────────────────────────────────────────────
|
|
53
|
+
* Why the table list is DERIVED and not written out (#13205)
|
|
54
|
+
*
|
|
55
|
+
* This migration is the terminal step of that chain: its target column is
|
|
56
|
+
* the CURRENT declared shape, so "should this table be renamed?" is not an
|
|
57
|
+
* independent fact — it is `does this object still declare environment_id?`.
|
|
58
|
+
* Written out by hand, the two drifted apart: `sys_metadata_history` stayed
|
|
59
|
+
* on the list after the branch/project-removal amendment (M1) removed
|
|
60
|
+
* `environment_id` from its declaration, so against a database whose
|
|
61
|
+
* physical `sys_metadata_history` still carried `project_id` this migration
|
|
62
|
+
* renamed it to a column NO declaration knows about — minting exactly the
|
|
63
|
+
* orphan column class the metadata drift audit exists to remove.
|
|
64
|
+
*
|
|
65
|
+
* The old guard could not catch it: the loop gates on `project_id` existing
|
|
66
|
+
* PHYSICALLY (`_columnExists`), which says nothing about the target column
|
|
67
|
+
* being DECLARED. So the list is now computed from the declarations in
|
|
68
|
+
* `@objectstack/metadata-core` (already a dependency of this package — no
|
|
69
|
+
* new edge), and a candidate that does not declare the target column is
|
|
70
|
+
* reported as `skipped_not_declared` rather than dropped silently: an
|
|
71
|
+
* operator reading the result sees the table was considered and why nothing
|
|
72
|
+
* happened, instead of having to guess whether it was forgotten again.
|
|
73
|
+
*
|
|
74
|
+
* ⚠️ The sibling `migrate-env-id-to-project-id.ts` is deliberately NOT
|
|
75
|
+
* changed this way. Its target (`project_id`) is an INTERMEDIATE column that
|
|
76
|
+
* no current declaration carries by design — gating it on today's
|
|
77
|
+
* declarations would disable the chain's first step entirely. The rule
|
|
78
|
+
* "target must be declared" is sound only for the terminal migration.
|
|
79
|
+
* ─────────────────────────────────────────────────────────────────────
|
|
80
|
+
*
|
|
51
81
|
* (The per-type projection tables `sys_object` / `sys_view` / `sys_flow` /
|
|
52
82
|
* `sys_agent` / `sys_tool` were removed in 2026-05 along with the projection
|
|
53
83
|
* pipeline — see ADR 0005 addendum. They are intentionally not included.)
|
|
@@ -63,15 +93,24 @@ declare function migrateEnvIdToProjectId(driver: IDataDriver): Promise<Migration
|
|
|
63
93
|
|
|
64
94
|
interface ProjectIdToEnvironmentIdResult {
|
|
65
95
|
table: string;
|
|
66
|
-
|
|
96
|
+
/**
|
|
97
|
+
* `skipped_not_declared` — the table is a known metadata storage table, but
|
|
98
|
+
* its current declaration has no `environment_id`, so renaming into it
|
|
99
|
+
* would create a column nothing declares. Nothing was executed.
|
|
100
|
+
*/
|
|
101
|
+
status: 'renamed' | 'already_done' | 'table_missing' | 'skipped_not_declared' | 'error';
|
|
67
102
|
error?: string;
|
|
68
103
|
}
|
|
69
104
|
/**
|
|
70
|
-
* Rename `project_id` → `environment_id` on all metadata tables
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
105
|
+
* Rename `project_id` → `environment_id` on all metadata tables that still
|
|
106
|
+
* declare `environment_id`.
|
|
107
|
+
*
|
|
108
|
+
* @param driver An IDataDriver with access to the target database. Raw SQL is
|
|
109
|
+
* issued through the surface `IDataDriver` declares —
|
|
110
|
+
* `execute(sql, bindings?)` — falling back to
|
|
111
|
+
* `raw(sql, bindings?)`; see `./driver-exec.ts`.
|
|
112
|
+
* @returns Per-table migration results — one entry per candidate table,
|
|
113
|
+
* including the ones skipped for lacking the declared target.
|
|
75
114
|
*/
|
|
76
115
|
declare function migrateProjectIdToEnvironmentId(driver: IDataDriver): Promise<ProjectIdToEnvironmentIdResult[]>;
|
|
77
116
|
|
|
@@ -100,7 +139,9 @@ interface DropProjectionResult {
|
|
|
100
139
|
/**
|
|
101
140
|
* Drop the deprecated per-type metadata projection tables.
|
|
102
141
|
*
|
|
103
|
-
* @param driver An `IDataDriver
|
|
142
|
+
* @param driver An `IDataDriver`. Raw SQL is issued through the surface
|
|
143
|
+
* `IDataDriver` declares — `execute(sql, bindings?)` — falling
|
|
144
|
+
* back to `raw(sql, bindings?)`; see `./driver-exec.ts`.
|
|
104
145
|
* @returns Per-table results.
|
|
105
146
|
*/
|
|
106
147
|
declare function dropProjectionTables(driver: IDataDriver): Promise<DropProjectionResult[]>;
|
|
@@ -132,16 +173,57 @@ declare function dropProjectionTables(driver: IDataDriver): Promise<DropProjecti
|
|
|
132
173
|
* await migrateSysNotificationToEvent({ driver, data });
|
|
133
174
|
*
|
|
134
175
|
* `driver` provides raw access to read legacy columns the re-modeled schema no
|
|
135
|
-
* longer projects and to clear them
|
|
176
|
+
* longer projects and to clear them — through the surface `IDataDriver`
|
|
177
|
+
* declares, `execute(sql, bindings?)`, falling back to `raw(sql, bindings?)`
|
|
178
|
+
* (see `./driver-exec.ts`); `data` (IDataEngine) performs the
|
|
136
179
|
* structured inbox/receipt writes and the event rewrite so ids, JSON fields and
|
|
137
180
|
* tenant stamping are handled uniformly across drivers.
|
|
181
|
+
*
|
|
182
|
+
* A completed run also records itself in the `sys_migration` deployment ledger
|
|
183
|
+
* under `NOTIFICATION_EVENT_MIGRATION_ID`, per the ruled claim matrix carried
|
|
184
|
+
* on that constant (#16100) — see "The run receipt" below. That row is a
|
|
185
|
+
* RECEIPT an operator reads, never a gate.
|
|
138
186
|
*/
|
|
139
187
|
|
|
188
|
+
/**
|
|
189
|
+
* What one run recorded in the `sys_migration` deployment ledger (#16100).
|
|
190
|
+
*
|
|
191
|
+
* This directory reports to its CALLER and to nobody else — no module under
|
|
192
|
+
* `packages/metadata/src/migrations` takes a logger — so the ledger claim's
|
|
193
|
+
* own fate is reported the same way the migration's is. That is also the third
|
|
194
|
+
* legal answer to AGENTS.md's degradation rule: a failure handed to the caller
|
|
195
|
+
* does not "look normal from the outside", because the caller was told.
|
|
196
|
+
*
|
|
197
|
+
* - `inserted` / `updated` — the claim landed, as a new row or over the row
|
|
198
|
+
* that was already there.
|
|
199
|
+
* - `not-claimed` — nothing was owed. An `error` run writes no ledger claim
|
|
200
|
+
* at all (the ruled matrix), so this is the correct, complete outcome for
|
|
201
|
+
* it and never a failure.
|
|
202
|
+
* - `no-ledger` — a claim was owed and there is nowhere to put it: the host
|
|
203
|
+
* is not an engine that carries the ledger, or `sys_migration` is not
|
|
204
|
+
* registered on this kernel. `reason` says which.
|
|
205
|
+
* - `failed` — a claim was owed, the write was attempted, and it threw. The
|
|
206
|
+
* data migration itself still did what `status` says it did; what is
|
|
207
|
+
* missing is the durable record that it ran. `reason` carries the error.
|
|
208
|
+
*/
|
|
209
|
+
interface SysNotificationMigrationReceipt {
|
|
210
|
+
outcome: 'inserted' | 'updated' | 'not-claimed' | 'no-ledger' | 'failed';
|
|
211
|
+
/** Why no claim landed — present on `no-ledger` and `failed` only. */
|
|
212
|
+
reason?: string;
|
|
213
|
+
}
|
|
140
214
|
interface SysNotificationMigrationResult {
|
|
141
215
|
status: 'migrated' | 'already_done' | 'not_applicable' | 'error';
|
|
142
216
|
/** Number of legacy rows split into inbox + receipt + event. */
|
|
143
217
|
migrated: number;
|
|
144
218
|
error?: string;
|
|
219
|
+
/**
|
|
220
|
+
* What this run claimed in the `sys_migration` ledger under
|
|
221
|
+
* {@link NOTIFICATION_EVENT_MIGRATION_ID}. Always present: writing the
|
|
222
|
+
* receipt is part of what a run DOES, and a caller that cannot tell "the
|
|
223
|
+
* claim landed" from "the claim was never attempted" is the unanswerable
|
|
224
|
+
* state the ledger row exists to remove.
|
|
225
|
+
*/
|
|
226
|
+
receipt: SysNotificationMigrationReceipt;
|
|
145
227
|
}
|
|
146
228
|
interface SysNotificationMigrationOptions {
|
|
147
229
|
driver: IDataDriver;
|
|
@@ -151,4 +233,4 @@ interface SysNotificationMigrationOptions {
|
|
|
151
233
|
}
|
|
152
234
|
declare function migrateSysNotificationToEvent(opts: SysNotificationMigrationOptions): Promise<SysNotificationMigrationResult>;
|
|
153
235
|
|
|
154
|
-
export { type DropProjectionResult, type MigrationResult, type ProjectIdToEnvironmentIdResult, type SysNotificationMigrationOptions, type SysNotificationMigrationResult, dropProjectionTables, migrateEnvIdToProjectId, migrateProjectIdToEnvironmentId, migrateSysNotificationToEvent };
|
|
236
|
+
export { type DropProjectionResult, type MigrationResult, type ProjectIdToEnvironmentIdResult, type SysNotificationMigrationOptions, type SysNotificationMigrationReceipt, type SysNotificationMigrationResult, dropProjectionTables, migrateEnvIdToProjectId, migrateProjectIdToEnvironmentId, migrateSysNotificationToEvent };
|