@voltro/database 0.43.0 → 0.43.1
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 +69 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +734 -718
- package/dist/sql.js +699 -670
- package/package.json +2 -2
package/dist/sql.js
CHANGED
|
@@ -94,67 +94,67 @@ var ae = (e, t, n, r = 400) => {
|
|
|
94
94
|
}, be = (e) => {
|
|
95
95
|
let t = me(e);
|
|
96
96
|
return t === void 0 ? pe : ye(`voltro_migration_lock:${t}`) & 9223372036854775807n;
|
|
97
|
-
},
|
|
97
|
+
}, xe = (e) => {
|
|
98
98
|
let t = `voltro_migration_${pe.toString(36)}`, n = me(e);
|
|
99
99
|
if (n === void 0) return t;
|
|
100
100
|
let r = `${t}_${n}`;
|
|
101
101
|
return /^[A-Za-z0-9_]+$/.test(n) && r.length <= 64 ? r : `${t}_h${(ye(`voltro_migration_lock:${n}`) & ve).toString(16)}`;
|
|
102
|
-
},
|
|
102
|
+
}, Se = 250, Ce = () => {
|
|
103
103
|
let e = Number(process.env.VOLTRO_MIGRATION_LOCK_TIMEOUT_MS);
|
|
104
104
|
return Number.isFinite(e) && e > 0 ? e : 3e4;
|
|
105
|
-
},
|
|
106
|
-
let n =
|
|
105
|
+
}, we = (e, t) => x.gen(function* () {
|
|
106
|
+
let n = Ce(), r = Date.now();
|
|
107
107
|
for (;;) {
|
|
108
108
|
if ((yield* e`
|
|
109
109
|
SELECT pg_try_advisory_lock(${t.toString()}::bigint) AS got`)[0]?.got) return;
|
|
110
|
-
Date.now() - r >= n && (yield* x.die(/* @__PURE__ */ Error(`could not acquire the postgres migration advisory lock within ${Math.round(n / 1e3)}s. Another migration is in progress, or a prior boot crashed while holding it. (A crashed process's session-level advisory lock is released once its DB connection closes; if this persists, find + terminate the holder via pg_stat_activity, or raise VOLTRO_MIGRATION_LOCK_TIMEOUT_MS.)`))), yield* x.sleep(`${
|
|
110
|
+
Date.now() - r >= n && (yield* x.die(/* @__PURE__ */ Error(`could not acquire the postgres migration advisory lock within ${Math.round(n / 1e3)}s. Another migration is in progress, or a prior boot crashed while holding it. (A crashed process's session-level advisory lock is released once its DB connection closes; if this persists, find + terminate the holder via pg_stat_activity, or raise VOLTRO_MIGRATION_LOCK_TIMEOUT_MS.)`))), yield* x.sleep(`${Se} millis`);
|
|
111
111
|
}
|
|
112
|
-
}),
|
|
112
|
+
}), Te = (e, t) => x.gen(function* () {
|
|
113
113
|
yield* e`SELECT pg_advisory_unlock(${t.toString()}::bigint)`;
|
|
114
|
-
}),
|
|
114
|
+
}), Ee = 30, De = (e, t) => x.gen(function* () {
|
|
115
115
|
(yield* e`
|
|
116
|
-
SELECT GET_LOCK(${t}, ${
|
|
117
|
-
}),
|
|
116
|
+
SELECT GET_LOCK(${t}, ${Ee}) AS got`)[0]?.got !== 1 && (yield* x.die(/* @__PURE__ */ Error(`could not acquire the migration lock '${t}' within ${Ee}s (another migration is in progress, or a prior one left it held).`)));
|
|
117
|
+
}), Oe = (e, t) => x.gen(function* () {
|
|
118
118
|
yield* e`SELECT RELEASE_LOCK(${t})`;
|
|
119
|
-
}),
|
|
119
|
+
}), ke = 3e4, Ae = (e, t) => x.gen(function* () {
|
|
120
120
|
let n = yield* e`
|
|
121
121
|
DECLARE @res int;
|
|
122
122
|
EXEC @res = sp_getapplock @Resource = ${t}, @LockMode = 'Exclusive',
|
|
123
|
-
@LockOwner = 'Session', @LockTimeout = ${
|
|
123
|
+
@LockOwner = 'Session', @LockTimeout = ${ke};
|
|
124
124
|
SELECT @res AS res`;
|
|
125
125
|
(n[0]?.res ?? -999) < 0 && (yield* x.die(/* @__PURE__ */ Error(`could not acquire the migration lock '${t}' (sp_getapplock returned ${n[0]?.res ?? "no row"}; another migration is in progress).`)));
|
|
126
|
-
}),
|
|
126
|
+
}), je = (e, t) => x.gen(function* () {
|
|
127
127
|
yield* e`EXEC sp_releaseapplock @Resource = ${t}, @LockOwner = 'Session'`;
|
|
128
|
-
}),
|
|
128
|
+
}), Me = x.void, T = (e, t) => {
|
|
129
129
|
let n = he(t);
|
|
130
130
|
return e.onDialectOrElse({
|
|
131
|
-
mysql: () =>
|
|
132
|
-
mssql: () =>
|
|
133
|
-
sqlite: () =>
|
|
134
|
-
orElse: () =>
|
|
131
|
+
mysql: () => De(e, xe(n)),
|
|
132
|
+
mssql: () => Ae(e, xe(n)),
|
|
133
|
+
sqlite: () => Me,
|
|
134
|
+
orElse: () => we(e, be(n))
|
|
135
135
|
});
|
|
136
|
-
},
|
|
136
|
+
}, E = (e, t) => {
|
|
137
137
|
let n = he(t);
|
|
138
138
|
return e.onDialectOrElse({
|
|
139
|
-
mysql: () =>
|
|
140
|
-
mssql: () =>
|
|
141
|
-
sqlite: () =>
|
|
142
|
-
orElse: () =>
|
|
139
|
+
mysql: () => Oe(e, xe(n)),
|
|
140
|
+
mssql: () => je(e, xe(n)),
|
|
141
|
+
sqlite: () => Me,
|
|
142
|
+
orElse: () => Te(e, be(n))
|
|
143
143
|
});
|
|
144
|
-
},
|
|
144
|
+
}, Ne = (e, t, n) => x.acquireUseRelease(T(e, n), () => t, () => E(e, n).pipe(x.orDie)), Pe = (e) => e.onDialectOrElse({
|
|
145
145
|
pg: () => "postgres",
|
|
146
146
|
mysql: () => "mysql",
|
|
147
147
|
mssql: () => "mssql",
|
|
148
148
|
sqlite: () => "sqlite",
|
|
149
149
|
orElse: () => "sqlite"
|
|
150
|
-
}),
|
|
150
|
+
}), Fe = {
|
|
151
151
|
postgres: "plan-transactional",
|
|
152
152
|
mssql: "plan-transactional",
|
|
153
153
|
mysql: "per-operation",
|
|
154
154
|
mariadb: "per-operation",
|
|
155
155
|
sqlite: "per-operation",
|
|
156
156
|
turso: "per-operation"
|
|
157
|
-
},
|
|
157
|
+
}, Ie = (e) => Fe[e], D = "_voltro_migration_ops", Le = y(D, {
|
|
158
158
|
id: t({ prefix: "mop" }),
|
|
159
159
|
runId: e(),
|
|
160
160
|
planFingerprint: e(),
|
|
@@ -167,7 +167,7 @@ var ae = (e, t, n, r = 400) => {
|
|
|
167
167
|
appliedAt: a().nullable(),
|
|
168
168
|
durationMs: r().nullable(),
|
|
169
169
|
createdAt: a().default("now")
|
|
170
|
-
}),
|
|
170
|
+
}), Re = (e) => {
|
|
171
171
|
switch (e.kind) {
|
|
172
172
|
case "create-table": return /* @__PURE__ */ new Set([
|
|
173
173
|
`table:${e.table}`,
|
|
@@ -194,11 +194,11 @@ var ae = (e, t, n, r = 400) => {
|
|
|
194
194
|
case "add-unique-composite":
|
|
195
195
|
case "drop-unique-composite": return /* @__PURE__ */ new Set([`unique:${e.table}.${e.name}`]);
|
|
196
196
|
}
|
|
197
|
-
},
|
|
198
|
-
let n =
|
|
199
|
-
for (let t of
|
|
197
|
+
}, ze = (e) => [...Re(e)].join(" "), Be = (e, t) => {
|
|
198
|
+
let n = Re(t);
|
|
199
|
+
for (let t of Re(e)) if (n.has(t)) return !0;
|
|
200
200
|
return !1;
|
|
201
|
-
},
|
|
201
|
+
}, Ve = (e, t) => e.operations.some((e) => Be(e.op, t)), He = "__voltro_rebuild", Ue = "__shadow", We = "__old", Ge = /* @__PURE__ */ new Set([
|
|
202
202
|
"add-unique",
|
|
203
203
|
"drop-unique",
|
|
204
204
|
"add-unique-composite",
|
|
@@ -210,16 +210,16 @@ var ae = (e, t, n, r = 400) => {
|
|
|
210
210
|
"alter-column-nullability",
|
|
211
211
|
"alter-column-type",
|
|
212
212
|
"alter-column-default"
|
|
213
|
-
]),
|
|
213
|
+
]), Ke = /* @__PURE__ */ new Set(["alter-column-default", "alter-column-nullability"]), qe = (e, t, n) => {
|
|
214
214
|
let r = n === "sqlite" || n === "turso";
|
|
215
|
-
return e.kind === "alter-column-type" && t === "online-required" || r &&
|
|
215
|
+
return e.kind === "alter-column-type" && t === "online-required" || r && Ge.has(e.kind) ? "artefact-repair" : Ke.has(e.kind) ? "idempotent" : "probe-then-replay";
|
|
216
216
|
};
|
|
217
|
-
Object.keys(
|
|
217
|
+
Object.keys(Fe);
|
|
218
218
|
//#endregion
|
|
219
219
|
//#region src/migrations/reactiveTriggerName.ts
|
|
220
|
-
var
|
|
221
|
-
|
|
222
|
-
},
|
|
220
|
+
var O = "framework_changes", Je = "framework_changes_", Ye = (e, t) => t === "framework_changes" ? `${Je}${e}` : `${Je}${t}_${e}`, Xe = (e) => e === "framework_changes" ? "framework_notify_change" : `framework_notify_change_${e}`, Ze = "voltro:notify:v2", Qe = ee({ scope: "voltro:migrate" }), k = (e) => {
|
|
221
|
+
Qe.warn(e.replace(/^\[voltro:migrate\]\s*/, ""));
|
|
222
|
+
}, A = (e, t) => {
|
|
223
223
|
let n = e.type;
|
|
224
224
|
if (e.spatial) {
|
|
225
225
|
if (t === "postgres") return `${e.spatial.kind}(${e.spatial.geomKind},${e.spatial.srid})`;
|
|
@@ -230,7 +230,7 @@ var k = "framework_changes", qe = "framework_changes_", Je = (e, t) => t === "fr
|
|
|
230
230
|
return e.rawDdl;
|
|
231
231
|
}
|
|
232
232
|
if (n === "array" && e.arrayElement) {
|
|
233
|
-
if (t === "postgres") return `${
|
|
233
|
+
if (t === "postgres") return `${A({
|
|
234
234
|
...e,
|
|
235
235
|
type: e.arrayElement,
|
|
236
236
|
arrayElement: void 0
|
|
@@ -330,22 +330,22 @@ var k = "framework_changes", qe = "framework_changes_", Je = (e, t) => t === "fr
|
|
|
330
330
|
case "array": return "TEXT[]";
|
|
331
331
|
case "interval": return "INTERVAL";
|
|
332
332
|
}
|
|
333
|
-
},
|
|
333
|
+
}, $e = (e, t) => {
|
|
334
334
|
if (!e.hasDefault || e.defaultFactory !== void 0) return null;
|
|
335
335
|
let n = e.defaultValue;
|
|
336
|
-
return n === "now" ? o(t) ? "DEFAULT CURRENT_TIMESTAMP" : t === "mssql" ? "DEFAULT SYSUTCDATETIME()" : t === "mysql" || t === "mariadb" ? "DEFAULT CURRENT_TIMESTAMP(6)" : "DEFAULT now()" : typeof n == "boolean" ? t === "postgres" ? `DEFAULT ${n}` : `DEFAULT ${+!!n}` : typeof n == "number" ? `DEFAULT ${n}` : typeof n == "string" ? `DEFAULT '${n.replace(/'/g, "''")}'` : Array.isArray(n) ?
|
|
337
|
-
},
|
|
338
|
-
if (n !== "postgres" || t.type !== "array" || t.arrayElement === void 0) return
|
|
339
|
-
let r =
|
|
336
|
+
return n === "now" ? o(t) ? "DEFAULT CURRENT_TIMESTAMP" : t === "mssql" ? "DEFAULT SYSUTCDATETIME()" : t === "mysql" || t === "mariadb" ? "DEFAULT CURRENT_TIMESTAMP(6)" : "DEFAULT now()" : typeof n == "boolean" ? t === "postgres" ? `DEFAULT ${n}` : `DEFAULT ${+!!n}` : typeof n == "number" ? `DEFAULT ${n}` : typeof n == "string" ? `DEFAULT '${n.replace(/'/g, "''")}'` : Array.isArray(n) ? et(n, e, t) : typeof n == "object" && n ? j(n, t) : null;
|
|
337
|
+
}, et = (e, t, n) => {
|
|
338
|
+
if (n !== "postgres" || t.type !== "array" || t.arrayElement === void 0) return j(e, n);
|
|
339
|
+
let r = A({
|
|
340
340
|
...t,
|
|
341
341
|
type: t.arrayElement,
|
|
342
342
|
arrayElement: void 0
|
|
343
343
|
}, n);
|
|
344
344
|
return `DEFAULT '{${e.map((e) => typeof e == "number" || typeof e == "boolean" ? String(e) : `"${String(e).replace(/\\/g, "\\\\").replace(/"/g, "\\\"")}"`).join(",").replace(/'/g, "''")}}'::${r}[]`;
|
|
345
|
-
},
|
|
345
|
+
}, j = (e, t) => {
|
|
346
346
|
let n = JSON.stringify(e).replace(/'/g, "''");
|
|
347
347
|
return t === "postgres" ? `DEFAULT '${n}'::jsonb` : t === "mysql" || t === "mariadb" ? `DEFAULT (CONVERT('${n}' USING utf8mb4))` : `DEFAULT '${n}'`;
|
|
348
|
-
},
|
|
348
|
+
}, M = (e, t) => {
|
|
349
349
|
switch (t) {
|
|
350
350
|
case "postgres": return `"${e}" BIGSERIAL PRIMARY KEY`;
|
|
351
351
|
case "mysql":
|
|
@@ -354,7 +354,7 @@ var k = "framework_changes", qe = "framework_changes_", Je = (e, t) => t === "fr
|
|
|
354
354
|
case "sqlite": return `"${e}" INTEGER PRIMARY KEY AUTOINCREMENT`;
|
|
355
355
|
case "turso": return `"${e}" INTEGER PRIMARY KEY`;
|
|
356
356
|
}
|
|
357
|
-
},
|
|
357
|
+
}, N = (e, t) => {
|
|
358
358
|
if (e === "restrict" && t === "mssql") return "NO ACTION";
|
|
359
359
|
switch (e) {
|
|
360
360
|
case "cascade": return "CASCADE";
|
|
@@ -362,42 +362,42 @@ var k = "framework_changes", qe = "framework_changes_", Je = (e, t) => t === "fr
|
|
|
362
362
|
case "setNull": return "SET NULL";
|
|
363
363
|
case "noAction": return "NO ACTION";
|
|
364
364
|
}
|
|
365
|
-
},
|
|
365
|
+
}, tt = (e, t, r) => r === null ? n(e, t) : `${n(r, t)}.${n(e, t)}`, nt = 191, rt = (e, t) => {
|
|
366
366
|
if (!e || t !== "mysql" && t !== "mariadb") return !1;
|
|
367
|
-
let n =
|
|
367
|
+
let n = A(e, t).toUpperCase();
|
|
368
368
|
return n.endsWith("TEXT") || n.endsWith("BLOB");
|
|
369
|
-
},
|
|
369
|
+
}, it = (e, t, r) => {
|
|
370
370
|
let i = n(e, r);
|
|
371
371
|
if (r !== "mysql" && r !== "mariadb") return i;
|
|
372
372
|
let a = t[e];
|
|
373
373
|
if (!a) return i;
|
|
374
|
-
let o =
|
|
375
|
-
return o.endsWith("TEXT") || o.endsWith("BLOB") ? `${i}(${
|
|
376
|
-
},
|
|
374
|
+
let o = A(a, r).toUpperCase();
|
|
375
|
+
return o.endsWith("TEXT") || o.endsWith("BLOB") ? `${i}(${nt})` : i;
|
|
376
|
+
}, at = (e, t) => {
|
|
377
377
|
if (!e.generatedAs) return null;
|
|
378
378
|
let { expr: n, stored: r } = e.generatedAs;
|
|
379
|
-
if (t === "postgres") return r ||
|
|
379
|
+
if (t === "postgres") return r || k("[voltro:migrate] generated column requested as VIRTUAL but postgres only supports STORED — promoting"), `GENERATED ALWAYS AS (${n}) STORED`;
|
|
380
380
|
if (t === "mysql" || t === "mariadb") return `GENERATED ALWAYS AS (${n}) ${r ? "STORED" : "VIRTUAL"}`;
|
|
381
381
|
if (t === "mssql") return `AS (${n})${r ? " PERSISTED" : ""}`;
|
|
382
382
|
if (t === "turso") throw Error("@voltro/sql-turso: generated columns (.generatedAs(...)) are not supported — Turso's MVCC mode (journal_mode=experimental_mvcc) rejects them. Drop the generated column, or use the 'sqlite' / 'postgres' dialect for this table.");
|
|
383
383
|
return `GENERATED ALWAYS AS (${n}) ${r ? "STORED" : "VIRTUAL"}`;
|
|
384
|
-
},
|
|
385
|
-
if (t.type === "id" && t.idScheme?.kind === "numeric") return
|
|
386
|
-
let l = r === "mssql" && t.type === "text" && !t.generatedAs && t.maxLength === void 0 && a?.has(e) ? "NVARCHAR(450)" :
|
|
384
|
+
}, ot = (e, t, r, a, s = !1, c = !1) => {
|
|
385
|
+
if (t.type === "id" && t.idScheme?.kind === "numeric") return M(e, r);
|
|
386
|
+
let l = r === "mssql" && t.type === "text" && !t.generatedAs && t.maxLength === void 0 && a?.has(e) ? "NVARCHAR(450)" : A(t, r), u = [n(e, r), l];
|
|
387
387
|
t.type === "id" && !c && u.push("PRIMARY KEY");
|
|
388
|
-
let d =
|
|
388
|
+
let d = at(t, r);
|
|
389
389
|
if (d) u.push(d);
|
|
390
390
|
else {
|
|
391
|
-
t.nullable || u.push("NOT NULL"), t.unique && t.type !== "id" && !
|
|
392
|
-
let e =
|
|
391
|
+
t.nullable || u.push("NOT NULL"), t.unique && t.type !== "id" && !rt(t, r) && u.push("UNIQUE");
|
|
392
|
+
let e = $e(t, r);
|
|
393
393
|
e && u.push(e);
|
|
394
394
|
}
|
|
395
395
|
if (t.type === "reference" && t.references && !s && !i(r)) {
|
|
396
396
|
let e = t.references();
|
|
397
397
|
u.push(`REFERENCES ${n(e.tableName, r)} (${n("id", r)})`);
|
|
398
|
-
let i =
|
|
398
|
+
let i = N(t.onDelete ?? "restrict", r);
|
|
399
399
|
u.push(`ON DELETE ${i}`);
|
|
400
|
-
let a =
|
|
400
|
+
let a = N(t.refOnUpdate ?? "noAction", r);
|
|
401
401
|
a !== "NO ACTION" && u.push(`ON UPDATE ${a}`);
|
|
402
402
|
}
|
|
403
403
|
if (t.oneOf && t.oneOf.length > 0) {
|
|
@@ -414,23 +414,23 @@ var k = "framework_changes", qe = "framework_changes_", Je = (e, t) => t === "fr
|
|
|
414
414
|
o(r) ? u.push(`CHECK (${t} IS NULL OR json_valid(${t}))`) : r === "mssql" && u.push(`CHECK (${t} IS NULL OR ISJSON(${t}) = 1)`);
|
|
415
415
|
}
|
|
416
416
|
return u.join(" ");
|
|
417
|
-
},
|
|
417
|
+
}, st = (e, t, r = null, a) => {
|
|
418
418
|
let o = /* @__PURE__ */ new Set();
|
|
419
419
|
for (let t of e.appliedIndexes ?? []) for (let e of t.fields) typeof e == "string" && o.add(e);
|
|
420
420
|
for (let t of e.appliedUniques ?? []) for (let e of t.fields) typeof e == "string" && o.add(e);
|
|
421
|
-
let s = e.appliedPrimaryKey ?? [], c = s.length > 0, l = Object.entries(e.fields).map(([e, n]) => ` ${
|
|
422
|
-
let i = r.fields.map((n) =>
|
|
421
|
+
let s = e.appliedPrimaryKey ?? [], c = s.length > 0, l = Object.entries(e.fields).map(([e, n]) => ` ${ot(e, n, t, o, a?.has(e) ?? !1, c)}`).join(",\n"), u = (e.appliedUniques ?? []).map((r) => {
|
|
422
|
+
let i = r.fields.map((n) => it(n, e.fields, t)).join(", ");
|
|
423
423
|
return ` CONSTRAINT ${n(r.name, t)} UNIQUE (${i})`;
|
|
424
|
-
}), d = (e.appliedChecks ?? []).map((e) => ` CONSTRAINT ${n(e.name, t)} CHECK (${e.expr})`), f = c ? [` PRIMARY KEY (${s.map((n) =>
|
|
424
|
+
}), d = (e.appliedChecks ?? []).map((e) => ` CONSTRAINT ${n(e.name, t)} CHECK (${e.expr})`), f = c ? [` PRIMARY KEY (${s.map((n) => it(n, e.fields, t)).join(", ")})`] : [], p = i(t) ? Object.entries(e.fields).flatMap(([i, o]) => {
|
|
425
425
|
if (o.type !== "reference" || !o.references || (a?.has(i) ?? !1)) return [];
|
|
426
|
-
let s = o.references(), c =
|
|
427
|
-
return [` CONSTRAINT ${n(`${e.tableName}_${i}_fkey`, t)} FOREIGN KEY (${n(i, t)}) REFERENCES ${
|
|
426
|
+
let s = o.references(), c = N(o.onDelete ?? "restrict", t), l = N(o.refOnUpdate ?? "noAction", t);
|
|
427
|
+
return [` CONSTRAINT ${n(`${e.tableName}_${i}_fkey`, t)} FOREIGN KEY (${n(i, t)}) REFERENCES ${tt(s.tableName, t, r)} (${n("id", t)}) ON DELETE ${c}${l === "NO ACTION" ? "" : ` ON UPDATE ${l}`}`];
|
|
428
428
|
}) : [], m = [
|
|
429
429
|
...f,
|
|
430
430
|
...u,
|
|
431
431
|
...d,
|
|
432
432
|
...p
|
|
433
|
-
], h = m.length > 0 ? `${l},\n${m.join(",\n")}` : l, g =
|
|
433
|
+
], h = m.length > 0 ? `${l},\n${m.join(",\n")}` : l, g = tt(e.tableName, t, r);
|
|
434
434
|
if (t === "mssql") {
|
|
435
435
|
let t = r === null ? e.tableName : `${r}.${e.tableName}`, n = `CREATE TABLE ${g} (\n${h}\n)`;
|
|
436
436
|
return `IF OBJECT_ID('${t.replace(/'/g, "''")}', 'U') IS NULL EXEC(N'${n.replace(/'/g, "''")}');`;
|
|
@@ -440,10 +440,10 @@ var k = "framework_changes", qe = "framework_changes_", Je = (e, t) => t === "fr
|
|
|
440
440
|
h,
|
|
441
441
|
");"
|
|
442
442
|
].join("\n");
|
|
443
|
-
},
|
|
443
|
+
}, ct = (e, t, r) => {
|
|
444
444
|
let i = `${e}_${t.name}_fts`, a = (e) => n(e, r), o = t.columns.map(a).join(", "), s = t.columns.map((e) => `new.${a(e)}`).join(", "), c = [];
|
|
445
445
|
return c.push(`CREATE VIRTUAL TABLE IF NOT EXISTS ${a(i)} USING fts5(${o}, row_id UNINDEXED, tokenize='porter');`), c.push(`CREATE TRIGGER IF NOT EXISTS ${a(`${i}_ai`)} AFTER INSERT ON ${a(e)} BEGIN\n INSERT INTO ${a(i)} (${o}, row_id) VALUES (${s}, new.${a("id")});\nEND;`), c.push(`CREATE TRIGGER IF NOT EXISTS ${a(`${i}_ad`)} AFTER DELETE ON ${a(e)} BEGIN\n DELETE FROM ${a(i)} WHERE row_id = old.${a("id")};\nEND;`), c.push(`CREATE TRIGGER IF NOT EXISTS ${a(`${i}_au`)} AFTER UPDATE ON ${a(e)} BEGIN\n DELETE FROM ${a(i)} WHERE row_id = old.${a("id")};\n INSERT INTO ${a(i)} (${o}, row_id) VALUES (${s}, new.${a("id")});\nEND;`), c;
|
|
446
|
-
},
|
|
446
|
+
}, lt = (e, t, r = null) => {
|
|
447
447
|
let i = [], a = /* @__PURE__ */ new Set(), o = (e) => e.join("\0"), s = (e, n, r, i) => {
|
|
448
448
|
let a = {
|
|
449
449
|
using: "",
|
|
@@ -455,21 +455,21 @@ var k = "framework_changes", qe = "framework_changes_", Je = (e, t) => t === "fr
|
|
|
455
455
|
using: " USING GIST",
|
|
456
456
|
withSuffix: "",
|
|
457
457
|
skip: !1
|
|
458
|
-
} : (
|
|
458
|
+
} : (k(`[voltro:migrate] index '${e}' on '${n}': ${t} doesn't support GiST — falling back to btree. Spatial queries on this column will fall back to sequential scan.`), a);
|
|
459
459
|
if (r === "gin") return t === "postgres" ? {
|
|
460
460
|
using: " USING GIN",
|
|
461
461
|
withSuffix: "",
|
|
462
462
|
skip: !1
|
|
463
|
-
} : t === "mysql" || t === "mariadb" ? (
|
|
463
|
+
} : t === "mysql" || t === "mariadb" ? (k(`[voltro:migrate] gin index '${e}' on '${n}': ${t} has no GIN access method — skipping (a btree on a JSON/array column can't serve containment/membership queries). Add a generated column for the specific path you query, then index that with .expressionIndex(...).`), {
|
|
464
464
|
using: "",
|
|
465
465
|
withSuffix: "",
|
|
466
466
|
skip: !0
|
|
467
|
-
}) : (
|
|
467
|
+
}) : (k(`[voltro:migrate] gin index '${e}' on '${n}': ${t} has no GIN access method — falling back to btree. Containment/membership queries won't use this index efficiently.`), a);
|
|
468
468
|
if (r === "brin") return t === "postgres" ? {
|
|
469
469
|
using: " USING BRIN",
|
|
470
470
|
withSuffix: "",
|
|
471
471
|
skip: !1
|
|
472
|
-
} : (
|
|
472
|
+
} : (k(`[voltro:migrate] brin index '${e}' on '${n}': ${t} has no BRIN access method — falling back to btree (larger on disk, but the range scan still works).`), a);
|
|
473
473
|
if (r === "hnsw") {
|
|
474
474
|
if (t === "postgres") {
|
|
475
475
|
let e = i?.hnsw?.m ?? 16, t = i?.hnsw?.efConstruction ?? 64, n = i?.hnsw?.opclass ?? h(i?.hnsw?.distance);
|
|
@@ -480,7 +480,7 @@ var k = "framework_changes", qe = "framework_changes_", Je = (e, t) => t === "fr
|
|
|
480
480
|
skip: !1
|
|
481
481
|
};
|
|
482
482
|
}
|
|
483
|
-
return
|
|
483
|
+
return k(`[voltro:migrate] hnsw index '${e}' on '${n}': ${t} has no pgvector / HNSW access method — skipping. Nearest-neighbour queries on this column fall back to a sequential scan.`), {
|
|
484
484
|
using: "",
|
|
485
485
|
withSuffix: "",
|
|
486
486
|
skip: !0
|
|
@@ -489,7 +489,7 @@ var k = "framework_changes", qe = "framework_changes_", Je = (e, t) => t === "fr
|
|
|
489
489
|
return a;
|
|
490
490
|
}, c = (n, r) => {
|
|
491
491
|
let i = n.map((n) => {
|
|
492
|
-
if (typeof n == "string") return
|
|
492
|
+
if (typeof n == "string") return it(n, e.fields, t);
|
|
493
493
|
if ("jsonPath" in n) {
|
|
494
494
|
let { column: e, path: r, numeric: i } = n.jsonPath;
|
|
495
495
|
return `(${_(e, r, t, { numeric: i })})`;
|
|
@@ -500,11 +500,11 @@ var k = "framework_changes", qe = "framework_changes_", Je = (e, t) => t === "fr
|
|
|
500
500
|
}, l = (e, i, a, o, l, u = "", d = !1) => {
|
|
501
501
|
let f = s(e, i, o, l);
|
|
502
502
|
if (f.skip) return "";
|
|
503
|
-
let p = c(a, f.opclass), m = `${f.withSuffix}${u}`, h =
|
|
503
|
+
let p = c(a, f.opclass), m = `${f.withSuffix}${u}`, h = tt(i, t, r), g = d ? "UNIQUE " : "";
|
|
504
504
|
return t === "mssql" ? `IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = '${e}') CREATE ${g}INDEX ${n(e, t)} ON ${h}${f.using} (${p})${m};` : t === "mysql" ? `CREATE ${g}INDEX ${n(e, t)} ON ${h}${f.using} (${p})${m};` : `CREATE ${g}INDEX IF NOT EXISTS ${n(e, t)} ON ${h}${f.using} (${p})${m};`;
|
|
505
505
|
};
|
|
506
506
|
if (t === "mysql" || t === "mariadb") for (let [n, r] of Object.entries(e.fields)) {
|
|
507
|
-
if (!r.unique || r.type === "id" || !
|
|
507
|
+
if (!r.unique || r.type === "id" || !rt(r, t)) continue;
|
|
508
508
|
let a = l(`${e.tableName}_${n}_key`, e.tableName, [n], void 0, void 0, "", !0);
|
|
509
509
|
a && i.push(a);
|
|
510
510
|
}
|
|
@@ -518,15 +518,15 @@ var k = "framework_changes", qe = "framework_changes_", Je = (e, t) => t === "fr
|
|
|
518
518
|
let a = r.columns.map((e) => n(e, t)).join(", ");
|
|
519
519
|
i.push(`CREATE FULLTEXT INDEX ${n(r.name, t)} ON ${n(e.tableName, t)} (${a});`);
|
|
520
520
|
} else if (t === "turso") throw Error(`@voltro/sql-turso: full-text index '${r.name}' on '${e.tableName}' is not supported — Turso's MVCC mode has no FTS5 virtual tables. Drop .fullTextIndex(), or use the 'sqlite' / 'postgres' dialect for this table.`);
|
|
521
|
-
else t === "sqlite" ? i.push(...
|
|
521
|
+
else t === "sqlite" ? i.push(...ct(e.tableName, r, t)) : k(`[voltro:migrate] full-text index '${r.name}' on '${e.tableName}': ${t} uses a ranked LIKE search at query time (no native FTS catalog required).`);
|
|
522
522
|
for (let n of e.appliedIndexes) {
|
|
523
523
|
if ((t === "mariadb" || t === "mssql") && n.fields.some((e) => typeof e != "string" && "jsonPath" in e)) {
|
|
524
|
-
|
|
524
|
+
k(`[voltro:migrate] json-path index '${n.name}' on '${e.tableName}': ${t} cannot index a JSON expression directly — skipping. For an indexed JSON path on ${t}, add a generated column for the path (text().generatedAs(...) / .stored()) and .index([...]) it, then filter on that column instead of jsonField(...).`);
|
|
525
525
|
continue;
|
|
526
526
|
}
|
|
527
527
|
if (n.unique && n.where !== void 0 && n.where.length > 0 && (t === "mysql" || t === "mariadb")) throw Error(`@voltro/migrate: uniqueActive index '${n.name}' on '${e.tableName}' cannot be expressed on ${t} — it has no partial (WHERE) index support, and a full UNIQUE index would forbid re-creating a soft-deleted row. Use a generated STORED column (text().generatedAs("CASE WHEN \`deletedAt\` IS NULL THEN <key> ELSE NULL END", { stored: true })) + .unique([...]) on ${t}, or move this table to postgres/sqlite/mssql.`);
|
|
528
528
|
let r = "";
|
|
529
|
-
n.where !== void 0 && n.where.length > 0 && (t === "mysql" || t === "mariadb" ?
|
|
529
|
+
n.where !== void 0 && n.where.length > 0 && (t === "mysql" || t === "mariadb" ? k(`[voltro:migrate] partial index '${n.name}' on '${e.tableName}': ${t} does not support WHERE clauses on indexes — emitting a full index`) : r = ` WHERE ${n.where}`);
|
|
530
530
|
let s = l(n.name, e.tableName, n.fields, n.kind, n.kindOptions, r, n.unique === !0);
|
|
531
531
|
s !== "" && i.push(s), n.fields.every((e) => typeof e == "string") && a.add(o(n.fields));
|
|
532
532
|
}
|
|
@@ -536,17 +536,17 @@ var k = "framework_changes", qe = "framework_changes_", Je = (e, t) => t === "fr
|
|
|
536
536
|
i.push(l(r, e.tableName, [t])), a.add(o([t]));
|
|
537
537
|
}
|
|
538
538
|
return i.join("\n");
|
|
539
|
-
},
|
|
539
|
+
}, ut = (e, t, n = O) => {
|
|
540
540
|
if (t !== "postgres") return [];
|
|
541
541
|
let r = e.filter((e) => e.isReactive !== !1);
|
|
542
|
-
return r.length === 0 ? [] : [
|
|
543
|
-
},
|
|
544
|
-
CREATE OR REPLACE FUNCTION ${
|
|
542
|
+
return r.length === 0 ? [] : [dt(n), ...r.map((e) => pt(e, n))];
|
|
543
|
+
}, dt = (e) => `
|
|
544
|
+
CREATE OR REPLACE FUNCTION ${Xe(e)}() RETURNS trigger AS $$
|
|
545
545
|
DECLARE
|
|
546
546
|
payload TEXT;
|
|
547
547
|
pk JSONB;
|
|
548
548
|
BEGIN
|
|
549
|
-
-- ${
|
|
549
|
+
-- ${Ze}
|
|
550
550
|
payload := json_build_object(
|
|
551
551
|
'table', TG_TABLE_NAME,
|
|
552
552
|
-- The schema the write landed in. Under namespace isolation this is
|
|
@@ -600,21 +600,21 @@ BEGIN
|
|
|
600
600
|
RETURN COALESCE(NEW, OLD);
|
|
601
601
|
END;
|
|
602
602
|
$$ LANGUAGE plpgsql;
|
|
603
|
-
`.trim(),
|
|
604
|
-
let n =
|
|
603
|
+
`.trim(), ft = (e, t) => {
|
|
604
|
+
let n = Ye(e.tableName, t);
|
|
605
605
|
return [
|
|
606
606
|
`ALTER TABLE "${e.tableName}" REPLICA IDENTITY FULL`,
|
|
607
607
|
`DROP TRIGGER IF EXISTS ${n} ON "${e.tableName}"`,
|
|
608
|
-
`CREATE TRIGGER ${n}\nAFTER INSERT OR UPDATE OR DELETE ON "${e.tableName}"\nFOR EACH ROW EXECUTE FUNCTION ${
|
|
608
|
+
`CREATE TRIGGER ${n}\nAFTER INSERT OR UPDATE OR DELETE ON "${e.tableName}"\nFOR EACH ROW EXECUTE FUNCTION ${Xe(t)}()`
|
|
609
609
|
];
|
|
610
|
-
},
|
|
610
|
+
}, pt = (e, t) => ft(e, t).map((e) => `${e};`).join("\n"), mt = (e) => {
|
|
611
611
|
if (e.dialect !== "postgres") return [];
|
|
612
612
|
let t = e.channel ?? "framework_changes", n = new Map(e.tables.map((e) => [e.tableName, e])), r = [], i = e.missing.filter((e) => n.has(e));
|
|
613
|
-
(i.length > 0 || e.functionOutdated === !0) && r.push(
|
|
614
|
-
for (let e of i) r.push(...
|
|
615
|
-
for (let n of e.stale) r.push(`DROP TRIGGER IF EXISTS ${
|
|
613
|
+
(i.length > 0 || e.functionOutdated === !0) && r.push(dt(t));
|
|
614
|
+
for (let e of i) r.push(...ft(n.get(e), t));
|
|
615
|
+
for (let n of e.stale) r.push(`DROP TRIGGER IF EXISTS ${Ye(n, t)} ON "${n}"`), r.push(`ALTER TABLE "${n}" REPLICA IDENTITY DEFAULT`);
|
|
616
616
|
return r;
|
|
617
|
-
},
|
|
617
|
+
}, ht = (e) => e.some((e) => Object.values(e.fields).some((e) => e.type === "vector")), gt = (e) => e.some((e) => Object.values(e.fields).some((e) => e.spatial !== void 0)), _t = (e) => {
|
|
618
618
|
let t = new Map(e.map((e) => [e.tableName, e])), n = fe(e.map((e) => e.tableName), (e) => {
|
|
619
619
|
let n = t.get(e);
|
|
620
620
|
return n ? Object.entries(n.fields).flatMap(([e, n]) => {
|
|
@@ -651,8 +651,8 @@ $$ LANGUAGE plpgsql;
|
|
|
651
651
|
sorted: o,
|
|
652
652
|
cyclic: r
|
|
653
653
|
};
|
|
654
|
-
},
|
|
655
|
-
let i = (e) => r ? `${n(r, t)}.${n(e, t)}` : n(e, t), a = `${e.table}_${e.column}_fkey`, o =
|
|
654
|
+
}, vt = (e, t, r = null) => {
|
|
655
|
+
let i = (e) => r ? `${n(r, t)}.${n(e, t)}` : n(e, t), a = `${e.table}_${e.column}_fkey`, o = N(e.onDelete, t), s = N(e.onUpdate, t), c = ` ON DELETE ${o}${s === "NO ACTION" ? "" : ` ON UPDATE ${s}`}`, l = (r) => `ADD CONSTRAINT ${n(a, t)} FOREIGN KEY ${r ? "IF NOT EXISTS " : ""}(${n(e.column, t)}) REFERENCES ${i(e.targetTable)} (${n("id", t)})${c}`;
|
|
656
656
|
switch (t) {
|
|
657
657
|
case "postgres": return [
|
|
658
658
|
"DO $$ BEGIN",
|
|
@@ -666,7 +666,7 @@ $$ LANGUAGE plpgsql;
|
|
|
666
666
|
case "mariadb": return `ALTER TABLE ${i(e.table)} ${l(!0)};`;
|
|
667
667
|
default: return `ALTER TABLE ${i(e.table)} ${l(!1)};`;
|
|
668
668
|
}
|
|
669
|
-
},
|
|
669
|
+
}, yt = (e, t) => {
|
|
670
670
|
let n = /* @__PURE__ */ new Map();
|
|
671
671
|
if (o(t)) return n;
|
|
672
672
|
for (let t of e) {
|
|
@@ -674,7 +674,7 @@ $$ LANGUAGE plpgsql;
|
|
|
674
674
|
e.add(t.column), n.set(t.table, e);
|
|
675
675
|
}
|
|
676
676
|
return n;
|
|
677
|
-
},
|
|
677
|
+
}, bt = (e, t) => {
|
|
678
678
|
if (t !== "postgres") return "";
|
|
679
679
|
let n = /* @__PURE__ */ new Map();
|
|
680
680
|
for (let t of e) for (let e of Object.values(t.fields)) {
|
|
@@ -690,7 +690,7 @@ $$ LANGUAGE plpgsql;
|
|
|
690
690
|
r.push(`DO $$ BEGIN\n IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = '${e.replace(/'/g, "''")}') THEN\n CREATE TYPE "${e}" AS ENUM (${n});\n END IF;\nEND $$;`);
|
|
691
691
|
}
|
|
692
692
|
return r.join("\n\n");
|
|
693
|
-
},
|
|
693
|
+
}, xt = (e, t) => {
|
|
694
694
|
if (t !== "postgres") return "";
|
|
695
695
|
let n = /* @__PURE__ */ new Set();
|
|
696
696
|
for (let t of e) for (let e of Object.values(t.fields)) e.type === "enum" && e.enumName && n.add(e.enumName);
|
|
@@ -704,30 +704,30 @@ BEGIN
|
|
|
704
704
|
SELECT oid INTO type_oid FROM pg_type WHERE typname = '${i}';\n IF type_oid IS NOT NULL\n AND EXISTS (SELECT 1 FROM pg_enum WHERE enumtypid = type_oid AND enumlabel = '${a}')\n AND NOT EXISTS (SELECT 1 FROM pg_enum WHERE enumtypid = type_oid AND enumlabel = '${o}') THEN\n IF current_setting('server_version_num')::int >= 140000 THEN\n EXECUTE format('ALTER TYPE %I RENAME VALUE %L TO %L', '${i}', '${a}', '${o}');\n ELSE\n UPDATE pg_enum SET enumlabel = '${o}' WHERE enumtypid = type_oid AND enumlabel = '${a}';\n END IF;\n END IF;\nEND $$;`);
|
|
705
705
|
}
|
|
706
706
|
return r.join("\n\n");
|
|
707
|
-
},
|
|
707
|
+
}, St = (e) => {
|
|
708
708
|
let t = [], n = [];
|
|
709
709
|
for (let r of e) p(r) ? n.push(r) : t.push(r);
|
|
710
710
|
return {
|
|
711
711
|
tables: t,
|
|
712
712
|
views: n
|
|
713
713
|
};
|
|
714
|
-
},
|
|
715
|
-
let { tables: r, views: i } =
|
|
716
|
-
t === "postgres" &&
|
|
717
|
-
let d =
|
|
714
|
+
}, Ct = (e, t, n = O) => {
|
|
715
|
+
let { tables: r, views: i } = St(e), { sorted: a, cyclic: c } = _t(r.map((e) => de(e, t))), l = yt(c, t), u = [];
|
|
716
|
+
t === "postgres" && ht(a) && u.push("CREATE EXTENSION IF NOT EXISTS vector;"), t === "postgres" && gt(a) && u.push("CREATE EXTENSION IF NOT EXISTS postgis;");
|
|
717
|
+
let d = xt(a, t);
|
|
718
718
|
d && u.push(d);
|
|
719
|
-
let f =
|
|
719
|
+
let f = bt(a, t);
|
|
720
720
|
f && u.push(f);
|
|
721
|
-
for (let e of a) u.push(
|
|
722
|
-
if (!o(t)) for (let e of c) u.push(
|
|
721
|
+
for (let e of a) u.push(st(e, t, null, l.get(e.tableName)));
|
|
722
|
+
if (!o(t)) for (let e of c) u.push(vt(e, t));
|
|
723
723
|
for (let e of a) {
|
|
724
|
-
let n =
|
|
724
|
+
let n = lt(e, t);
|
|
725
725
|
n && u.push(n);
|
|
726
726
|
}
|
|
727
|
-
u.push(...
|
|
727
|
+
u.push(...ut(a, t, n));
|
|
728
728
|
for (let e of i) u.push(s(e, t));
|
|
729
729
|
return u.join("\n\n") + "\n";
|
|
730
|
-
},
|
|
730
|
+
}, wt = (e, t, r) => {
|
|
731
731
|
let i = n(e, t);
|
|
732
732
|
switch (t) {
|
|
733
733
|
case "postgres": return `CREATE SCHEMA IF NOT EXISTS ${i};`;
|
|
@@ -737,62 +737,62 @@ BEGIN
|
|
|
737
737
|
case "turso":
|
|
738
738
|
case "sqlite": return `ATTACH DATABASE '${(r ?? `${e}.db`).replace(/'/g, "''")}' AS ${i};`;
|
|
739
739
|
}
|
|
740
|
-
},
|
|
741
|
-
let a =
|
|
742
|
-
if (t === "postgres") return `${a}\n\nSET search_path TO ${s};\n\n${
|
|
743
|
-
if (t === "mysql" || t === "mariadb") return `${a}\n\nUSE ${s};\n\n${
|
|
744
|
-
let { sorted: c, cyclic: l } =
|
|
745
|
-
for (let e of c) d.push(
|
|
746
|
-
if (!o(t)) for (let e of l) d.push(
|
|
740
|
+
}, Tt = (e, t, r, i) => {
|
|
741
|
+
let a = wt(r, t, i), s = n(r, t);
|
|
742
|
+
if (t === "postgres") return `${a}\n\nSET search_path TO ${s};\n\n${Ct(e, t)}`;
|
|
743
|
+
if (t === "mysql" || t === "mariadb") return `${a}\n\nUSE ${s};\n\n${Ct(e, t)}`;
|
|
744
|
+
let { sorted: c, cyclic: l } = _t(e), u = yt(l, t), d = [a];
|
|
745
|
+
for (let e of c) d.push(st(e, t, r, u.get(e.tableName)));
|
|
746
|
+
if (!o(t)) for (let e of l) d.push(vt(e, t, r));
|
|
747
747
|
for (let e of c) {
|
|
748
|
-
let n =
|
|
748
|
+
let n = lt(e, t, r);
|
|
749
749
|
n && d.push(n);
|
|
750
750
|
}
|
|
751
751
|
return d.join("\n\n") + "\n";
|
|
752
|
-
},
|
|
753
|
-
let { sorted: r, cyclic: i } =
|
|
752
|
+
}, Et = (e, t, n = O) => {
|
|
753
|
+
let { sorted: r, cyclic: i } = _t(e), a = yt(i, t), o = [], s = xt(r, t);
|
|
754
754
|
s && o.push(s);
|
|
755
|
-
let c =
|
|
755
|
+
let c = bt(r, t);
|
|
756
756
|
c && o.push(c);
|
|
757
|
-
for (let e of r) o.push(
|
|
758
|
-
for (let e of i) o.push(
|
|
759
|
-
return o.push(...
|
|
760
|
-
},
|
|
757
|
+
for (let e of r) o.push(st(e, t, null, a.get(e.tableName)));
|
|
758
|
+
for (let e of i) o.push(vt(e, t));
|
|
759
|
+
return o.push(...ut(r, t, n)), o.join("\n\n") + "\n";
|
|
760
|
+
}, Dt = (e, t = "postgres", n = O, r = {}) => x.gen(function* () {
|
|
761
761
|
let i = yield* C.SqlClient;
|
|
762
|
-
yield*
|
|
763
|
-
}),
|
|
762
|
+
yield* Ne(i, Pt(i, Ct(e, t, n), t, r.retryFilter), { schema: r.lockSchema }).pipe(x.orDie);
|
|
763
|
+
}), Ot = (e, t) => {
|
|
764
764
|
let n = t.cause ?? {};
|
|
765
765
|
return (n.errno === 1061 || n.code === "ER_DUP_KEYNAME") && /^\s*CREATE\s+(UNIQUE\s+|FULLTEXT\s+)?INDEX\b/i.test(e);
|
|
766
|
-
},
|
|
766
|
+
}, kt = (e, t) => {
|
|
767
767
|
let n = e.trimStart();
|
|
768
768
|
return !!(/\bIF NOT EXISTS\b/i.test(n) || /^CREATE OR REPLACE\b/i.test(n) || /^DROP\s[\s\S]*?\bIF EXISTS\b/i.test(n) || /^SET search_path\b/i.test(n) || /^USE[\s`"[]/i.test(n) || /^IF\s/i.test(n) || (t === "mysql" || t === "mariadb") && /^CREATE\s+(UNIQUE\s+|FULLTEXT\s+)?INDEX\b/i.test(n));
|
|
769
|
-
},
|
|
769
|
+
}, At = () => {
|
|
770
770
|
let e = Number(process.env.VOLTRO_MIGRATION_DDL_RETRIES);
|
|
771
771
|
return Number.isInteger(e) && e >= 0 ? e : 4;
|
|
772
|
-
},
|
|
772
|
+
}, jt = (e) => ({
|
|
773
773
|
while: e,
|
|
774
|
-
times:
|
|
774
|
+
times: At(),
|
|
775
775
|
schedule: S.jittered(S.exponential("50 millis"))
|
|
776
|
-
}),
|
|
776
|
+
}), Mt = class {
|
|
777
777
|
statement;
|
|
778
778
|
error;
|
|
779
779
|
_tag = "DdlStatementFailed";
|
|
780
780
|
constructor(e, t) {
|
|
781
781
|
this.statement = e, this.error = t;
|
|
782
782
|
}
|
|
783
|
-
},
|
|
784
|
-
let r = yield* C.SqlClient, i = n !== void 0 &&
|
|
785
|
-
for (let a of
|
|
786
|
-
process.env.VOLTRO_MIGRATE_DEBUG === "1" &&
|
|
787
|
-
let e = r.unsafe(a).pipe(x.catchIf((e) =>
|
|
788
|
-
|
|
783
|
+
}, Nt = (e, t, n) => x.gen(function* () {
|
|
784
|
+
let r = yield* C.SqlClient, i = n !== void 0 && Ie(t) === "per-operation";
|
|
785
|
+
for (let a of Ft(e)) {
|
|
786
|
+
process.env.VOLTRO_MIGRATE_DEBUG === "1" && Qe.debug(`EXEC: ${a.replace(/\s+/g, " ").slice(0, 180)}`);
|
|
787
|
+
let e = r.unsafe(a).pipe(x.catchIf((e) => Ot(a, e), () => x.succeed([])), x.tapError((e) => x.sync(() => {
|
|
788
|
+
Qe.error(ae("migrate: statement failed", a, e, 200));
|
|
789
789
|
})));
|
|
790
|
-
yield* (i && n !== void 0 &&
|
|
790
|
+
yield* (i && n !== void 0 && kt(a, t) ? e.pipe(x.retry(jt((e) => n(e) === "retry"))) : e).pipe(x.mapError((e) => new Mt(a, e)));
|
|
791
791
|
}
|
|
792
|
-
}),
|
|
793
|
-
let i = n === "turso" ?
|
|
794
|
-
return (r !== void 0 &&
|
|
795
|
-
},
|
|
792
|
+
}), Pt = (e, t, n, r) => {
|
|
793
|
+
let i = n === "turso" ? Nt(t, n, r) : e.withTransaction(Nt(t, n, r)), a = (e) => e instanceof Mt ? e.error : e;
|
|
794
|
+
return (r !== void 0 && Ie(n) === "plan-transactional" ? i.pipe(x.retry(jt((e) => r(a(e)) === "retry"))) : i).pipe(x.orDieWith((e) => e instanceof Mt ? Error(ae("migrate: statement failed", e.statement, e.error, 400).trim()) : e));
|
|
795
|
+
}, Ft = (e) => {
|
|
796
796
|
let t = [], n = "", r = !1;
|
|
797
797
|
for (let i = 0; i < e.length; i++) {
|
|
798
798
|
if (e.slice(i, i + 2) === "$$") {
|
|
@@ -807,43 +807,43 @@ BEGIN
|
|
|
807
807
|
}
|
|
808
808
|
let i = n.trim();
|
|
809
809
|
return i.length > 0 && t.push(i), t;
|
|
810
|
-
},
|
|
811
|
-
await x.runPromise(
|
|
812
|
-
},
|
|
813
|
-
let i =
|
|
814
|
-
yield*
|
|
815
|
-
}),
|
|
816
|
-
await x.runPromise(
|
|
810
|
+
}, It = async (e, t, n = "postgres", r = {}) => {
|
|
811
|
+
await x.runPromise(Dt(e, n, void 0, r).pipe(x.provide(t)));
|
|
812
|
+
}, Lt = (e, t, n = "postgres", r = {}) => x.gen(function* () {
|
|
813
|
+
let i = Tt(e, n, t), a = yield* C.SqlClient;
|
|
814
|
+
yield* Ne(a, Pt(a, i, n, r.retryFilter), { schema: r.lockSchema }).pipe(x.orDie);
|
|
815
|
+
}), Rt = async (e, t, n, r = "postgres", i = {}) => {
|
|
816
|
+
await x.runPromise(Lt(e, t, r, i).pipe(x.provide(n))), await f({
|
|
817
817
|
namespace: t,
|
|
818
818
|
dialect: r
|
|
819
819
|
});
|
|
820
|
-
},
|
|
820
|
+
}, zt = async (e, t, n = "postgres", r = {}) => {
|
|
821
821
|
await x.runPromise(x.gen(function* () {
|
|
822
|
-
let t =
|
|
823
|
-
yield*
|
|
822
|
+
let t = Et(e, n), i = yield* C.SqlClient;
|
|
823
|
+
yield* Ne(i, Pt(i, t, n, r.retryFilter), { schema: r.lockSchema }).pipe(x.orDie);
|
|
824
824
|
}).pipe(x.provide(t)));
|
|
825
|
-
},
|
|
825
|
+
}, Bt = (e) => {
|
|
826
826
|
if (e == null) return e;
|
|
827
|
-
if (Array.isArray(e)) return e.map(
|
|
827
|
+
if (Array.isArray(e)) return e.map(Bt);
|
|
828
828
|
if (typeof e != "object") return e;
|
|
829
829
|
let t = {};
|
|
830
830
|
for (let n of Object.keys(e).sort()) {
|
|
831
831
|
let r = e[n];
|
|
832
|
-
r !== void 0 && (t[n] =
|
|
832
|
+
r !== void 0 && (t[n] = Bt(r));
|
|
833
833
|
}
|
|
834
834
|
return t;
|
|
835
|
-
},
|
|
835
|
+
}, Vt = (e) => {
|
|
836
836
|
if (!e.idScheme && !e.sensitive && !e.safe && !e.generatedAs) return e;
|
|
837
837
|
let { idScheme: t, sensitive: n, safe: r, generatedAs: i, ...a } = e;
|
|
838
838
|
return a;
|
|
839
|
-
},
|
|
839
|
+
}, Ht = (e) => [...e].map(Vt).sort((e, t) => e.name.localeCompare(t.name)), Ut = (e) => [...e].sort((e, t) => e.name.localeCompare(t.name)), Wt = (e) => [...e].map((e) => ({
|
|
840
840
|
name: e.name,
|
|
841
|
-
columns:
|
|
842
|
-
indexes:
|
|
843
|
-
})).sort((e, t) => e.name.localeCompare(t.name)),
|
|
844
|
-
let t = { tables:
|
|
841
|
+
columns: Ht(e.columns),
|
|
842
|
+
indexes: Ut(e.indexes)
|
|
843
|
+
})).sort((e, t) => e.name.localeCompare(t.name)), P = (e) => {
|
|
844
|
+
let t = { tables: Wt(e.tables) }, n = JSON.stringify(Bt(t));
|
|
845
845
|
return te("sha256").update(n).digest("hex");
|
|
846
|
-
},
|
|
846
|
+
}, Gt = (e) => e.slice(0, 16), Kt = (e, t) => {
|
|
847
847
|
let n = t.references ? {
|
|
848
848
|
table: t.references().tableName,
|
|
849
849
|
column: "id",
|
|
@@ -882,7 +882,7 @@ BEGIN
|
|
|
882
882
|
...t.enumValues === void 0 ? {} : { enumValues: t.enumValues },
|
|
883
883
|
...t.spatial === void 0 ? {} : { spatial: t.spatial }
|
|
884
884
|
};
|
|
885
|
-
},
|
|
885
|
+
}, qt = (e) => {
|
|
886
886
|
let t = [], n = /* @__PURE__ */ new Set(), r = (e) => {
|
|
887
887
|
n.has(e.name) || (n.add(e.name), t.push(e));
|
|
888
888
|
}, i = e.appliedPrimaryKey ?? [];
|
|
@@ -930,11 +930,11 @@ BEGIN
|
|
|
930
930
|
});
|
|
931
931
|
}
|
|
932
932
|
return t;
|
|
933
|
-
},
|
|
933
|
+
}, Jt = (e) => {
|
|
934
934
|
let t = new Set((e.appliedUniques ?? []).filter((e) => e.fields.length === 1).map((e) => e.fields[0])), n = [];
|
|
935
935
|
for (let [r, i] of Object.entries(e.fields)) {
|
|
936
936
|
if (i.dropped) continue;
|
|
937
|
-
let e =
|
|
937
|
+
let e = Kt(r, i);
|
|
938
938
|
n.push(t.has(r) ? {
|
|
939
939
|
...e,
|
|
940
940
|
unique: !0
|
|
@@ -944,27 +944,27 @@ BEGIN
|
|
|
944
944
|
return {
|
|
945
945
|
name: e.tableName,
|
|
946
946
|
columns: n,
|
|
947
|
-
indexes:
|
|
947
|
+
indexes: qt(e),
|
|
948
948
|
...r.length > 0 ? { primaryKey: [...r] } : {},
|
|
949
949
|
...i === void 0 ? {} : { renamedFrom: i }
|
|
950
950
|
};
|
|
951
|
-
},
|
|
951
|
+
}, Yt = (e) => {
|
|
952
952
|
let t = /* @__PURE__ */ new Map();
|
|
953
953
|
for (let n of e) for (let e of n.indexes) {
|
|
954
954
|
let r = t.get(e.name);
|
|
955
955
|
if (r !== void 0 && r !== n.name) throw Error(`duplicate index name '${e.name}' across tables '${r}' and '${n.name}'. Index names must be unique per SCHEMA, not just per table — the DB creates only one, so the other never applies and 'db plan' re-emits it forever. Give each an explicit, table-prefixed name (e.g. '${n.name}_${e.name}').`);
|
|
956
956
|
t.set(e.name, n.name);
|
|
957
957
|
}
|
|
958
|
-
},
|
|
959
|
-
let n = e.map((e) =>
|
|
960
|
-
return
|
|
961
|
-
},
|
|
958
|
+
}, F = (e, t) => {
|
|
959
|
+
let n = e.map((e) => Jt(de(e, t)));
|
|
960
|
+
return Yt(n), { tables: n };
|
|
961
|
+
}, Xt = (e, t, n = O) => x.gen(function* () {
|
|
962
962
|
let r = (yield* e`
|
|
963
963
|
SELECT p.prosrc
|
|
964
964
|
FROM pg_proc p
|
|
965
965
|
JOIN pg_namespace n ON n.oid = p.pronamespace
|
|
966
966
|
WHERE n.nspname = current_schema()
|
|
967
|
-
AND p.proname = ${
|
|
967
|
+
AND p.proname = ${Xe(n)}
|
|
968
968
|
`)[0]?.prosrc, i = r !== void 0 && !r.includes("voltro:notify:v2"), a = t.filter((e) => !e.tableName.startsWith("_voltro_"));
|
|
969
969
|
if (a.length === 0) return {
|
|
970
970
|
missing: [],
|
|
@@ -978,10 +978,10 @@ BEGIN
|
|
|
978
978
|
JOIN pg_namespace n ON n.oid = c.relnamespace
|
|
979
979
|
WHERE NOT t.tgisinternal
|
|
980
980
|
AND n.nspname = current_schema()
|
|
981
|
-
AND t.tgname LIKE ${`${
|
|
981
|
+
AND t.tgname LIKE ${`${Je}%`}
|
|
982
982
|
`, s = new Set(o.map((e) => e.tgname)), c = [], l = [];
|
|
983
983
|
for (let e of a) {
|
|
984
|
-
let t = s.has(
|
|
984
|
+
let t = s.has(Ye(e.tableName, n)), r = e.isReactive !== !1;
|
|
985
985
|
r && !t && c.push(e.tableName), !r && t && l.push(e.tableName);
|
|
986
986
|
}
|
|
987
987
|
return {
|
|
@@ -989,7 +989,7 @@ BEGIN
|
|
|
989
989
|
stale: l.sort(),
|
|
990
990
|
functionOutdated: i
|
|
991
991
|
};
|
|
992
|
-
}),
|
|
992
|
+
}), Zt = (e) => {
|
|
993
993
|
let t = [];
|
|
994
994
|
if (e.missing.length > 0) {
|
|
995
995
|
let n = e.missing.slice(0, 8).join(", "), r = e.missing.length > 8 ? `, … (+${e.missing.length - 8})` : "";
|
|
@@ -1000,19 +1000,19 @@ BEGIN
|
|
|
1000
1000
|
t.push(`${e.stale.length} .nonReactive() table(s) still carry a change trigger — ${n}. They keep paying REPLICA IDENTITY FULL and a NOTIFY on every write for a subscription nobody receives. \`voltro db apply\` removes them.`);
|
|
1001
1001
|
}
|
|
1002
1002
|
return e.functionOutdated && t.push("The change-notify function in this database is OLDER than the framework installed here. Its triggers fire, so nothing looks wrong — but a row too large for a NOTIFY payload (postgres caps it at 8000 bytes) is emitted without its primary key, and a change that carries no key cannot be re-read: it reaches subscriptions as a re-query and reaches every TAP — search index, analytics mirror, cdc-out, row history — as nothing at all. Run `voltro db apply` to replace it."), t.length > 0 ? t.join("\n") : void 0;
|
|
1003
|
-
},
|
|
1003
|
+
}, Qt = {
|
|
1004
1004
|
postgres: !0,
|
|
1005
1005
|
mysql: !0,
|
|
1006
1006
|
mariadb: !0,
|
|
1007
1007
|
mssql: !0,
|
|
1008
1008
|
sqlite: !0
|
|
1009
|
-
},
|
|
1009
|
+
}, $t = {
|
|
1010
1010
|
postgres: !0,
|
|
1011
1011
|
mysql: !1,
|
|
1012
1012
|
mariadb: !1,
|
|
1013
1013
|
mssql: !0,
|
|
1014
1014
|
sqlite: !0
|
|
1015
|
-
},
|
|
1015
|
+
}, en = (e) => {
|
|
1016
1016
|
switch (e) {
|
|
1017
1017
|
case "add-column":
|
|
1018
1018
|
case "drop-column":
|
|
@@ -1022,47 +1022,47 @@ BEGIN
|
|
|
1022
1022
|
case "add-foreign-key":
|
|
1023
1023
|
case "add-unique":
|
|
1024
1024
|
case "add-unique-composite":
|
|
1025
|
-
case "add-check": return
|
|
1026
|
-
default: return
|
|
1025
|
+
case "add-check": return $t;
|
|
1026
|
+
default: return Qt;
|
|
1027
1027
|
}
|
|
1028
|
-
},
|
|
1028
|
+
}, tn = (e, t) => {
|
|
1029
1029
|
let n = new Map(t.tables.map((e) => [e.name, e]));
|
|
1030
1030
|
return new Map(e.map((e) => [e.tableName, {
|
|
1031
1031
|
table: e,
|
|
1032
1032
|
snapshot: n.get(e.tableName),
|
|
1033
1033
|
columnDefs: e.fields
|
|
1034
1034
|
}]));
|
|
1035
|
-
},
|
|
1035
|
+
}, I = (e) => {
|
|
1036
1036
|
if (typeof e != "object" || !e) return JSON.stringify(e);
|
|
1037
|
-
if (Array.isArray(e)) return `[${e.map(
|
|
1037
|
+
if (Array.isArray(e)) return `[${e.map(I).join(",")}]`;
|
|
1038
1038
|
let t = e;
|
|
1039
|
-
return `{${Object.keys(t).sort().map((e) => `${JSON.stringify(e)}:${
|
|
1040
|
-
},
|
|
1039
|
+
return `{${Object.keys(t).sort().map((e) => `${JSON.stringify(e)}:${I(t[e])}`).join(",")}}`;
|
|
1040
|
+
}, nn = (e) => {
|
|
1041
1041
|
if (!e.hasDefault || e.defaultValue === void 0 || e.defaultValue === null) return null;
|
|
1042
1042
|
let t = e.defaultValue;
|
|
1043
1043
|
if (typeof t == "boolean") return t ? "__BOOL_TRUE__" : "__BOOL_FALSE__";
|
|
1044
1044
|
if (typeof t == "number") return String(t);
|
|
1045
|
-
if (typeof t != "string") return
|
|
1045
|
+
if (typeof t != "string") return I(t);
|
|
1046
1046
|
let n = t.trim(), r = n.toLowerCase().replace(/\s+/g, "");
|
|
1047
1047
|
if (r === "now" || r === "now()" || /^current_timestamp(\(\d*\))?$/.test(r) || r === "sysutcdatetime()" || r === "sysdatetime()" || r === "getutcdate()" || r === "getdate()") return "__NOW__";
|
|
1048
1048
|
let i = n.replace(/::[a-zA-Z0-9_ "]+$/, "").trim(), a = /^'(.*)'$/.test(i) ? i.slice(1, -1).replace(/''/g, "'") : i, o = /^cast\(\s*(?:_\w+\s*)?\\?'(.*?)\\?'\s+as\s+json\s*\)$/i.exec(a);
|
|
1049
1049
|
if (o) try {
|
|
1050
|
-
return
|
|
1050
|
+
return I(JSON.parse(o[1]));
|
|
1051
1051
|
} catch {}
|
|
1052
1052
|
let s = /^convert\(\s*(?:_\w+\s*)?\\?'(.*?)\\?'\s+using\s+[\w]+\s*\)$/i.exec(a);
|
|
1053
1053
|
if (s) try {
|
|
1054
|
-
return
|
|
1054
|
+
return I(JSON.parse(s[1]));
|
|
1055
1055
|
} catch {}
|
|
1056
1056
|
if (a.startsWith("{") || a.startsWith("[")) try {
|
|
1057
|
-
return
|
|
1057
|
+
return I(JSON.parse(a));
|
|
1058
1058
|
} catch {}
|
|
1059
1059
|
return /^-?\d+(\.\d+)?$/.test(a) ? String(Number(a)) : a;
|
|
1060
|
-
},
|
|
1061
|
-
let n =
|
|
1060
|
+
}, rn = (e, t) => {
|
|
1061
|
+
let n = nn(e), r = nn(t);
|
|
1062
1062
|
if (n === r) return !0;
|
|
1063
1063
|
let i = (e) => e === "1" || e === "true" ? "__BOOL_TRUE__" : e === "0" || e === "false" ? "__BOOL_FALSE__" : e;
|
|
1064
1064
|
return i(n) === i(r);
|
|
1065
|
-
},
|
|
1065
|
+
}, an = (e) => {
|
|
1066
1066
|
if (!e) return null;
|
|
1067
1067
|
let t = (e) => e === "restrict" ? "noAction" : e;
|
|
1068
1068
|
return {
|
|
@@ -1071,25 +1071,25 @@ BEGIN
|
|
|
1071
1071
|
onDelete: t(e.onDelete),
|
|
1072
1072
|
onUpdate: t(e.onUpdate)
|
|
1073
1073
|
};
|
|
1074
|
-
},
|
|
1074
|
+
}, on = (e, t) => {
|
|
1075
1075
|
let n = e && e.length > 0 ? e : void 0, r = t && t.length > 0 ? t : void 0;
|
|
1076
1076
|
if (!n && !r) return !0;
|
|
1077
1077
|
if (!n || !r || n.length !== r.length) return !1;
|
|
1078
1078
|
let i = [...n].sort(), a = [...r].sort();
|
|
1079
1079
|
return i.every((e, t) => e === a[t]);
|
|
1080
|
-
},
|
|
1080
|
+
}, sn = (e, t) => {
|
|
1081
1081
|
try {
|
|
1082
|
-
let n = /\((\d+)\)/.exec(
|
|
1082
|
+
let n = /\((\d+)\)/.exec(A(e, t));
|
|
1083
1083
|
return n ? Number(n[1]) : void 0;
|
|
1084
1084
|
} catch {
|
|
1085
1085
|
return;
|
|
1086
1086
|
}
|
|
1087
|
-
},
|
|
1087
|
+
}, cn = (e, t, n) => n === void 0 || o(n) ? !0 : e.type !== "text" || t.type !== "text" || sn(e, n) === t.maxLength, ln = (e, t, n) => e.type === t.type && e.nullable === t.nullable && e.unique === t.unique && rn(e, t) && cn(e, t, n) && JSON.stringify(an(e.references)) === JSON.stringify(an(t.references)) && on(e.oneOf, t.oneOf), un = (e, t) => t.oneOf && t.oneOf.length > 0 ? L({
|
|
1088
1088
|
kind: "add-check",
|
|
1089
1089
|
table: e,
|
|
1090
1090
|
column: t.name,
|
|
1091
1091
|
values: t.oneOf
|
|
1092
|
-
}, "safe", `enum-membership CHECK on ${e}.${t.name}`) : void 0,
|
|
1092
|
+
}, "safe", `enum-membership CHECK on ${e}.${t.name}`) : void 0, dn = (e, t) => e.unique === t.unique && (e.expression || t.expression ? !0 : e.columns.length === t.columns.length && e.columns.every((e, n) => e === t.columns[n])), fn = (e, t, n) => {
|
|
1093
1093
|
let r = new Map(t.columns.map((e) => [e.name, e])), i = new Map(e.columns.map((e) => [e.name, e])), a = [], o = [], s = [];
|
|
1094
1094
|
for (let t of e.columns) {
|
|
1095
1095
|
let e = r.get(t.name);
|
|
@@ -1097,7 +1097,7 @@ BEGIN
|
|
|
1097
1097
|
a.push(t);
|
|
1098
1098
|
continue;
|
|
1099
1099
|
}
|
|
1100
|
-
|
|
1100
|
+
ln(t, e, n) || s.push({
|
|
1101
1101
|
declared: t,
|
|
1102
1102
|
live: e
|
|
1103
1103
|
});
|
|
@@ -1108,47 +1108,47 @@ BEGIN
|
|
|
1108
1108
|
removed: o,
|
|
1109
1109
|
changed: s
|
|
1110
1110
|
};
|
|
1111
|
-
},
|
|
1111
|
+
}, pn = (e, t) => {
|
|
1112
1112
|
let n = new Map(t.indexes.map((e) => [e.name, e])), r = new Map(e.indexes.map((e) => [e.name, e])), i = [], a = [];
|
|
1113
1113
|
for (let t of e.indexes) {
|
|
1114
1114
|
let e = n.get(t.name);
|
|
1115
|
-
(!e || !
|
|
1115
|
+
(!e || !dn(t, e)) && i.push(t);
|
|
1116
1116
|
}
|
|
1117
1117
|
for (let e of t.indexes) r.has(e.name) || a.push(e);
|
|
1118
1118
|
return {
|
|
1119
1119
|
added: i,
|
|
1120
1120
|
removed: a
|
|
1121
1121
|
};
|
|
1122
|
-
},
|
|
1122
|
+
}, L = (e, t, n, r) => ({
|
|
1123
1123
|
op: e,
|
|
1124
1124
|
classification: t,
|
|
1125
|
-
atomicByDialect:
|
|
1125
|
+
atomicByDialect: en(e.kind),
|
|
1126
1126
|
...n ? { reason: n } : {},
|
|
1127
1127
|
...r ? { blocked: r } : {}
|
|
1128
|
-
}),
|
|
1128
|
+
}), mn = (e, t, n) => {
|
|
1129
1129
|
let r = {
|
|
1130
1130
|
kind: "add-column",
|
|
1131
1131
|
table: e,
|
|
1132
1132
|
column: t
|
|
1133
1133
|
};
|
|
1134
|
-
return t.nullable ?
|
|
1135
|
-
},
|
|
1134
|
+
return t.nullable ? L(r, "safe", "nullable column add — no backfill needed") : t.hasDefault && t.defaultValue !== void 0 ? L(r, "needs-default", "NOT NULL with literal default — DDL DEFAULT will populate existing rows") : n?.backfill ? L(r, "needs-backfill", `backfill declared (kind=${n.backfill.kind}) — applier will run 3-step add/update/set-not-null`) : L(r, "needs-backfill", "NOT NULL column on a table whose row count is unknown", { fix: `declare \`${t.name}: <type>().backfill(sql\`...\`)\` OR \`.default(value)\` so existing rows survive the migration` });
|
|
1135
|
+
}, hn = (e, t, n) => {
|
|
1136
1136
|
let r = {
|
|
1137
1137
|
kind: "drop-column",
|
|
1138
1138
|
table: e,
|
|
1139
1139
|
column: t.name
|
|
1140
1140
|
};
|
|
1141
|
-
return n?.dropped ?
|
|
1142
|
-
},
|
|
1141
|
+
return n?.dropped ? L(r, "lossy", `column dropped via \`${t.name}: dropped()\` marker — intentional`) : L(r, "lossy", "column missing from declared schema", { fix: `if intentional, add \`${t.name}: dropped()\` to the schema. If a typo, restore the field` });
|
|
1142
|
+
}, gn = (e, t, n, r, i) => L({
|
|
1143
1143
|
kind: "create-table",
|
|
1144
1144
|
table: e,
|
|
1145
1145
|
columns: t,
|
|
1146
1146
|
indexes: n,
|
|
1147
1147
|
...r && r.length > 0 ? { primaryKey: r } : {}
|
|
1148
|
-
}, "safe", i ?? "new table — no data to preserve"),
|
|
1148
|
+
}, "safe", i ?? "new table — no data to preserve"), _n = (e) => L({
|
|
1149
1149
|
kind: "drop-table",
|
|
1150
1150
|
table: e
|
|
1151
|
-
}, "lossy", "table missing from declared schema", { fix: "if intentional, set VOLTRO_DESTRUCTIVE_OK=1 OR add a file-based migration. If a typo, restore the table declaration" }),
|
|
1151
|
+
}, "lossy", "table missing from declared schema", { fix: "if intentional, set VOLTRO_DESTRUCTIVE_OK=1 OR add a file-based migration. If a typo, restore the table declaration" }), vn = 5e4, yn = (e, t, n, r) => {
|
|
1152
1152
|
let i = (n ?? 0) >= r, a;
|
|
1153
1153
|
return a = t.unique ? t.columns.length === 1 ? {
|
|
1154
1154
|
kind: "add-unique",
|
|
@@ -1163,16 +1163,16 @@ BEGIN
|
|
|
1163
1163
|
kind: "add-index",
|
|
1164
1164
|
table: e,
|
|
1165
1165
|
index: t
|
|
1166
|
-
}, i ?
|
|
1167
|
-
},
|
|
1166
|
+
}, i ? L(a, "online-required", `online build on ${n} rows — CONCURRENTLY / INPLACE / WITH(ONLINE=ON) depending on dialect`) : L(a, "safe", t.unique ? t.columns.length === 1 ? "add unique constraint" : "add composite UNIQUE constraint" : "add B-tree index");
|
|
1167
|
+
}, bn = (e, t) => t.unique && t.columns.length > 1 ? L({
|
|
1168
1168
|
kind: "drop-unique-composite",
|
|
1169
1169
|
table: e,
|
|
1170
1170
|
name: t.name
|
|
1171
|
-
}, "safe", "drop composite UNIQUE constraint (no data loss — constraint is derived metadata)") :
|
|
1171
|
+
}, "safe", "drop composite UNIQUE constraint (no data loss — constraint is derived metadata)") : L({
|
|
1172
1172
|
kind: "drop-index",
|
|
1173
1173
|
table: e,
|
|
1174
1174
|
index: t.name
|
|
1175
|
-
}, "safe", "drop index (no data loss — index is derived data)"),
|
|
1175
|
+
}, "safe", "drop index (no data loss — index is derived data)"), xn = (e, t) => {
|
|
1176
1176
|
if (e === "reference") return "text";
|
|
1177
1177
|
switch (t) {
|
|
1178
1178
|
case "sqlite":
|
|
@@ -1180,10 +1180,10 @@ BEGIN
|
|
|
1180
1180
|
case "mssql": return e === "json" ? "text" : e;
|
|
1181
1181
|
default: return e;
|
|
1182
1182
|
}
|
|
1183
|
-
},
|
|
1183
|
+
}, Sn = (e, t, n) => {
|
|
1184
1184
|
let r = `acknowledge it on the column: \`.narrowedFrom('${e}')\``;
|
|
1185
1185
|
return n === "postgres" ? `${r} — add \`{ using: '${t.name}::${t.type}' }\` when the cast is not implicit, or use a file-based migration` : `${r} — ${n === void 0 ? "this dialect" : n} converts in place (\`using\` is postgres-only and is ignored here), so verify the conversion is value-preserving for your data, or use a file-based migration`;
|
|
1186
|
-
},
|
|
1186
|
+
}, Cn = (e, t, n, r, i, a) => {
|
|
1187
1187
|
let s = [];
|
|
1188
1188
|
if (t.nullable !== n.nullable) {
|
|
1189
1189
|
let n = {
|
|
@@ -1192,7 +1192,7 @@ BEGIN
|
|
|
1192
1192
|
column: t.name,
|
|
1193
1193
|
toNullable: t.nullable
|
|
1194
1194
|
};
|
|
1195
|
-
s.push(t.nullable ?
|
|
1195
|
+
s.push(t.nullable ? L(n, "safe", `loosen ${e}.${t.name} to nullable`) : L(n, "needs-backfill", `tighten ${e}.${t.name} to NOT NULL — existing rows must already be non-null`));
|
|
1196
1196
|
}
|
|
1197
1197
|
if (t.unique !== n.unique) {
|
|
1198
1198
|
if (t.unique) {
|
|
@@ -1201,14 +1201,14 @@ BEGIN
|
|
|
1201
1201
|
table: e,
|
|
1202
1202
|
column: t.name
|
|
1203
1203
|
}, r = (i ?? 0) >= a;
|
|
1204
|
-
s.push(r ?
|
|
1205
|
-
} else s.push(
|
|
1204
|
+
s.push(r ? L(n, "online-required", `online unique build on ${i} rows — CONCURRENTLY / INPLACE / WITH(ONLINE=ON) depending on dialect`) : L(n, "safe", `add unique constraint on ${e}.${t.name} — existing rows must already be distinct (else the DB rejects at migrate)`));
|
|
1205
|
+
} else s.push(L({
|
|
1206
1206
|
kind: "drop-unique",
|
|
1207
1207
|
table: e,
|
|
1208
1208
|
column: t.name
|
|
1209
1209
|
}, "safe", `drop unique constraint on ${e}.${t.name} — constraint is derived metadata, no data loss`));
|
|
1210
1210
|
}
|
|
1211
|
-
if (
|
|
1211
|
+
if (xn(t.type, r) !== xn(n.type, r)) {
|
|
1212
1212
|
let i = t.narrowedFrom;
|
|
1213
1213
|
if (i && i.from === n.type) {
|
|
1214
1214
|
let r = {
|
|
@@ -1219,7 +1219,7 @@ BEGIN
|
|
|
1219
1219
|
to: t.type,
|
|
1220
1220
|
...i.using === void 0 ? {} : { using: i.using }
|
|
1221
1221
|
};
|
|
1222
|
-
s.push(
|
|
1222
|
+
s.push(L(r, "needs-backfill", `type change ${n.type} → ${t.type} on ${e}.${t.name} — narrowedFrom('${i.from}') declared` + (i.using ? ` with USING ${i.using}` : " (implicit cast)")));
|
|
1223
1223
|
} else {
|
|
1224
1224
|
let i = {
|
|
1225
1225
|
kind: "alter-column-type",
|
|
@@ -1228,12 +1228,12 @@ BEGIN
|
|
|
1228
1228
|
from: n.type,
|
|
1229
1229
|
to: t.type
|
|
1230
1230
|
};
|
|
1231
|
-
s.push(
|
|
1231
|
+
s.push(L(i, "lossy", `type change ${n.type} → ${t.type} on ${e}.${t.name} may not be value-preserving`, { fix: Sn(n.type, t, r) }));
|
|
1232
1232
|
}
|
|
1233
1233
|
}
|
|
1234
1234
|
if (t.type === "text" && n.type === "text" && !o(r ?? "postgres") && t.maxLength !== n.maxLength) {
|
|
1235
1235
|
let r = t.maxLength === void 0 || n.maxLength !== void 0 && t.maxLength > n.maxLength, i = n.maxLength === void 0 ? "unbounded" : `varchar(${n.maxLength})`, a = t.maxLength === void 0 ? "unbounded" : `varchar(${t.maxLength})`;
|
|
1236
|
-
s.push(
|
|
1236
|
+
s.push(L({
|
|
1237
1237
|
kind: "alter-column-type",
|
|
1238
1238
|
table: e,
|
|
1239
1239
|
column: t.name,
|
|
@@ -1241,7 +1241,7 @@ BEGIN
|
|
|
1241
1241
|
to: "text"
|
|
1242
1242
|
}, r ? "safe" : "needs-backfill", r ? `text length ${i} → ${a} on ${e}.${t.name} — widening, no data can be lost` : `text length ${i} → ${a} on ${e}.${t.name} — NARROWING; the ALTER fails if any existing value is longer than ${String(t.maxLength)}. Check first: SELECT COUNT(*) FROM ${e} WHERE LENGTH(${t.name}) > ${String(t.maxLength)}`));
|
|
1243
1243
|
}
|
|
1244
|
-
if (!
|
|
1244
|
+
if (!rn(t, n)) {
|
|
1245
1245
|
let n = {
|
|
1246
1246
|
kind: "alter-column-default",
|
|
1247
1247
|
table: e,
|
|
@@ -1249,23 +1249,23 @@ BEGIN
|
|
|
1249
1249
|
hasDefault: t.hasDefault,
|
|
1250
1250
|
...t.defaultValue === void 0 ? {} : { defaultValue: t.defaultValue }
|
|
1251
1251
|
};
|
|
1252
|
-
s.push(
|
|
1252
|
+
s.push(L(n, "safe", `default change on ${e}.${t.name} affects only future inserts`));
|
|
1253
1253
|
}
|
|
1254
|
-
if (!
|
|
1255
|
-
n.oneOf && n.oneOf.length > 0 && s.push(
|
|
1254
|
+
if (!on(t.oneOf, n.oneOf)) {
|
|
1255
|
+
n.oneOf && n.oneOf.length > 0 && s.push(L({
|
|
1256
1256
|
kind: "drop-check",
|
|
1257
1257
|
table: e,
|
|
1258
1258
|
column: t.name
|
|
1259
1259
|
}, "safe", `drop stale enum CHECK on ${e}.${t.name}`));
|
|
1260
|
-
let r =
|
|
1260
|
+
let r = un(e, t);
|
|
1261
1261
|
r && s.push(r);
|
|
1262
1262
|
}
|
|
1263
|
-
return JSON.stringify(
|
|
1263
|
+
return JSON.stringify(an(t.references)) !== JSON.stringify(an(n.references)) && (n.references && s.push(L({
|
|
1264
1264
|
kind: "drop-foreign-key",
|
|
1265
1265
|
table: e,
|
|
1266
1266
|
column: t.name
|
|
1267
|
-
}, "safe", `drop FK on ${e}.${t.name} (→ ${n.references.table})`)), s.push(...
|
|
1268
|
-
},
|
|
1267
|
+
}, "safe", `drop FK on ${e}.${t.name} (→ ${n.references.table})`)), s.push(...wn(e, t))), s;
|
|
1268
|
+
}, wn = (e, t) => {
|
|
1269
1269
|
let n = [];
|
|
1270
1270
|
if (!t.references) return n;
|
|
1271
1271
|
let r = t.references.table, i = t.references.orphanPolicy ?? "fail", a = {
|
|
@@ -1277,15 +1277,15 @@ BEGIN
|
|
|
1277
1277
|
...t.references.onDelete ? { onDelete: t.references.onDelete } : {},
|
|
1278
1278
|
...t.references.onUpdate ? { onUpdate: t.references.onUpdate } : {}
|
|
1279
1279
|
};
|
|
1280
|
-
return i === "null" && !t.nullable ? n.push(
|
|
1280
|
+
return i === "null" && !t.nullable ? n.push(L(a, "lossy", `add FK ${e}.${t.name} → ${r}: orphanPolicy 'null' needs a nullable column (the NULL-out would violate NOT NULL)`, { fix: `make ${t.name} \`.nullable()\`, OR use \`orphanPolicy: 'delete'\`, OR clean the orphans and drop the policy` })) : i === "null" || i === "delete" ? n.push(L({
|
|
1281
1281
|
...a,
|
|
1282
1282
|
orphanPolicy: i
|
|
1283
|
-
}, "lossy", i === "delete" ? `add FK ${e}.${t.name} → ${r}: orphanPolicy 'delete' first DELETES rows whose ${t.name} points at a missing ${r}` : `add FK ${e}.${t.name} → ${r}: orphanPolicy 'null' first NULLs ${t.name} where it points at a missing ${r}`)) : n.push(
|
|
1284
|
-
},
|
|
1283
|
+
}, "lossy", i === "delete" ? `add FK ${e}.${t.name} → ${r}: orphanPolicy 'delete' first DELETES rows whose ${t.name} points at a missing ${r}` : `add FK ${e}.${t.name} → ${r}: orphanPolicy 'null' first NULLs ${t.name} where it points at a missing ${r}`)) : n.push(L(a, "needs-backfill", `add FK ${e}.${t.name} → ${r} — existing rows must already reference a valid ${r} (else set orphanPolicy:'null'/'delete')`)), n;
|
|
1284
|
+
}, Tn = (e, t, n) => {
|
|
1285
1285
|
let r = [], i = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Set(), o = new Set(n.removed.map((e) => e.name)), s = new Set(n.added.map((e) => e.name));
|
|
1286
1286
|
for (let [n, c] of Object.entries(t)) {
|
|
1287
1287
|
let t = c.renamedFrom;
|
|
1288
|
-
t && o.has(t) && s.has(n) && (i.add(n), a.add(t), r.push(
|
|
1288
|
+
t && o.has(t) && s.has(n) && (i.add(n), a.add(t), r.push(L({
|
|
1289
1289
|
kind: "rename-column",
|
|
1290
1290
|
table: e.tableName,
|
|
1291
1291
|
from: t,
|
|
@@ -1297,26 +1297,26 @@ BEGIN
|
|
|
1297
1297
|
consumedAddedNames: i,
|
|
1298
1298
|
consumedRemovedNames: a
|
|
1299
1299
|
};
|
|
1300
|
-
},
|
|
1300
|
+
}, En = /* @__PURE__ */ new Set([
|
|
1301
1301
|
"postgres",
|
|
1302
1302
|
"mysql",
|
|
1303
1303
|
"mariadb",
|
|
1304
1304
|
"mssql"
|
|
1305
|
-
]),
|
|
1305
|
+
]), Dn = {
|
|
1306
1306
|
ops: [],
|
|
1307
1307
|
consumedAddedNames: /* @__PURE__ */ new Set(),
|
|
1308
1308
|
consumedRemovedNames: /* @__PURE__ */ new Set()
|
|
1309
|
-
},
|
|
1310
|
-
if (i === void 0 || !
|
|
1311
|
-
let a = t.added.filter((e) =>
|
|
1312
|
-
if (a.length === 0) return
|
|
1309
|
+
}, On = (e) => !e.unique && !e.expression, kn = (e, t, n, r, i) => {
|
|
1310
|
+
if (i === void 0 || !En.has(i)) return Dn;
|
|
1311
|
+
let a = t.added.filter((e) => On(e) && !r.has(e.name));
|
|
1312
|
+
if (a.length === 0) return Dn;
|
|
1313
1313
|
let o = (e) => e.columns.map((e) => n.get(e) ?? e).join("\0"), s = (e) => e.columns.join("\0"), c = [], l = /* @__PURE__ */ new Set(), u = /* @__PURE__ */ new Set();
|
|
1314
1314
|
for (let n of t.removed) {
|
|
1315
|
-
if (!
|
|
1315
|
+
if (!On(n)) continue;
|
|
1316
1316
|
let t = o(n), r = a.filter((e) => !l.has(e.name) && s(e) === t);
|
|
1317
1317
|
if (r.length !== 1) continue;
|
|
1318
1318
|
let i = r[0];
|
|
1319
|
-
i.name !== n.name && (l.add(i.name), u.add(n.name), c.push(
|
|
1319
|
+
i.name !== n.name && (l.add(i.name), u.add(n.name), c.push(L({
|
|
1320
1320
|
kind: "rename-index",
|
|
1321
1321
|
table: e,
|
|
1322
1322
|
from: n.name,
|
|
@@ -1328,7 +1328,7 @@ BEGIN
|
|
|
1328
1328
|
consumedAddedNames: l,
|
|
1329
1329
|
consumedRemovedNames: u
|
|
1330
1330
|
};
|
|
1331
|
-
},
|
|
1331
|
+
}, An = (e, t, n) => {
|
|
1332
1332
|
let r = [], i = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Set(), o = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Set();
|
|
1333
1333
|
for (let t of e.tables) t.renamedFrom !== void 0 && (s.set(t.renamedFrom, (s.get(t.renamedFrom) ?? 0) + 1), c.add(t.renamedFrom));
|
|
1334
1334
|
for (let c of e.tables) {
|
|
@@ -1339,7 +1339,7 @@ BEGIN
|
|
|
1339
1339
|
continue;
|
|
1340
1340
|
}
|
|
1341
1341
|
if (t.has(c.name)) {
|
|
1342
|
-
r.push(
|
|
1342
|
+
r.push(L({
|
|
1343
1343
|
kind: "rename-table",
|
|
1344
1344
|
from: e,
|
|
1345
1345
|
to: c.name
|
|
@@ -1347,14 +1347,14 @@ BEGIN
|
|
|
1347
1347
|
continue;
|
|
1348
1348
|
}
|
|
1349
1349
|
if ((s.get(e) ?? 0) !== 1) {
|
|
1350
|
-
r.push(
|
|
1350
|
+
r.push(L({
|
|
1351
1351
|
kind: "rename-table",
|
|
1352
1352
|
from: e,
|
|
1353
1353
|
to: c.name
|
|
1354
1354
|
}, "needs-rename-annotation", `.renamedFrom('${e}') is claimed by ${s.get(e)} tables — nothing says which receives its rows`, { fix: `remove the \`.renamedFrom('${e}')\` marker from all but one of them.` }));
|
|
1355
1355
|
continue;
|
|
1356
1356
|
}
|
|
1357
|
-
i.set(c.name, e), a.add(e), r.push(
|
|
1357
|
+
i.set(c.name, e), a.add(e), r.push(L({
|
|
1358
1358
|
kind: "rename-table",
|
|
1359
1359
|
from: e,
|
|
1360
1360
|
to: c.name
|
|
@@ -1368,19 +1368,19 @@ BEGIN
|
|
|
1368
1368
|
claimedOldNames: c,
|
|
1369
1369
|
refusals: o
|
|
1370
1370
|
};
|
|
1371
|
-
},
|
|
1371
|
+
}, jn = (e, t, n, r) => {
|
|
1372
1372
|
if (t === void 0) return {
|
|
1373
1373
|
live: e,
|
|
1374
1374
|
ops: []
|
|
1375
1375
|
};
|
|
1376
|
-
let i = r !== void 0 &&
|
|
1376
|
+
let i = r !== void 0 && En.has(r), a = [], o = e.indexes.map((e) => {
|
|
1377
1377
|
if (!e.name.startsWith(t)) return e;
|
|
1378
1378
|
let r = `${n}${e.name.slice(t.length)}`;
|
|
1379
1379
|
return r === e.name ? e : e.name === `${t}_pkey` ? {
|
|
1380
1380
|
...e,
|
|
1381
1381
|
name: r,
|
|
1382
1382
|
table: n
|
|
1383
|
-
} : i ? (a.push(
|
|
1383
|
+
} : i ? (a.push(L({
|
|
1384
1384
|
kind: "rename-index",
|
|
1385
1385
|
table: n,
|
|
1386
1386
|
from: e.name,
|
|
@@ -1399,7 +1399,7 @@ BEGIN
|
|
|
1399
1399
|
},
|
|
1400
1400
|
ops: a
|
|
1401
1401
|
};
|
|
1402
|
-
},
|
|
1402
|
+
}, Mn = (e) => {
|
|
1403
1403
|
let t = {
|
|
1404
1404
|
safe: 0,
|
|
1405
1405
|
needsDefault: 0,
|
|
@@ -1432,42 +1432,42 @@ BEGIN
|
|
|
1432
1432
|
case "multi-step": t.multiStep++;
|
|
1433
1433
|
}
|
|
1434
1434
|
return t;
|
|
1435
|
-
},
|
|
1436
|
-
let t =
|
|
1435
|
+
}, Nn = (e) => {
|
|
1436
|
+
let t = F(e.declared, e.dialect), n = tn(e.declared, t), r = new Map(e.live.tables.map((e) => [e.name, e])), i = e.onlineAfter ?? vn, a = [], o = An(t, r, n);
|
|
1437
1437
|
a.push(...o.ops);
|
|
1438
1438
|
for (let e of t.tables) if (!o.renamedInto.has(e.name) && !r.has(e.name)) {
|
|
1439
|
-
a.push(
|
|
1439
|
+
a.push(gn(e.name, e.columns, e.indexes, e.primaryKey, o.refusals.get(e.name)));
|
|
1440
1440
|
for (let t of e.columns) {
|
|
1441
|
-
let n =
|
|
1441
|
+
let n = un(e.name, t);
|
|
1442
1442
|
n && a.push(n);
|
|
1443
1443
|
}
|
|
1444
1444
|
}
|
|
1445
1445
|
let s = new Set(e.ignoreTables ?? []);
|
|
1446
|
-
for (let t of e.live.tables) n.has(t.name) || o.claimedOldNames.has(t.name) || m(t.name) || v(t.name) || s.has(t.name) || a.push(
|
|
1446
|
+
for (let t of e.live.tables) n.has(t.name) || o.claimedOldNames.has(t.name) || m(t.name) || v(t.name) || s.has(t.name) || a.push(_n(t.name));
|
|
1447
1447
|
for (let s of t.tables) {
|
|
1448
1448
|
let t = o.renamedInto.get(s.name), c = r.get(s.name) ?? (t === void 0 ? void 0 : r.get(t));
|
|
1449
1449
|
if (!c) continue;
|
|
1450
|
-
let l =
|
|
1450
|
+
let l = jn(c, t, s.name, e.dialect);
|
|
1451
1451
|
a.push(...l.ops);
|
|
1452
|
-
let u = l.live, d = n.get(s.name), f =
|
|
1452
|
+
let u = l.live, d = n.get(s.name), f = fn(s, u, e.dialect), p = pn(s, u), m = Tn(d.table, d.columnDefs, f);
|
|
1453
1453
|
a.push(...m.ops);
|
|
1454
1454
|
for (let e of f.removed) {
|
|
1455
1455
|
if (m.consumedRemovedNames.has(e.name) || v(e.name)) continue;
|
|
1456
1456
|
let t = d.columnDefs[e.name];
|
|
1457
|
-
a.push(
|
|
1457
|
+
a.push(hn(s.name, e, t));
|
|
1458
1458
|
}
|
|
1459
1459
|
for (let e of f.added) {
|
|
1460
1460
|
if (m.consumedAddedNames.has(e.name)) continue;
|
|
1461
1461
|
let t = d.columnDefs[e.name];
|
|
1462
|
-
a.push(
|
|
1463
|
-
let n =
|
|
1464
|
-
n && a.push(n), a.push(...
|
|
1462
|
+
a.push(mn(s.name, e, t));
|
|
1463
|
+
let n = un(s.name, e);
|
|
1464
|
+
n && a.push(n), a.push(...wn(s.name, e));
|
|
1465
1465
|
}
|
|
1466
|
-
let h = new Map(m.ops.flatMap((e) => e.op.kind === "rename-column" ? [[e.op.from, e.op.to]] : [])), g =
|
|
1466
|
+
let h = new Map(m.ops.flatMap((e) => e.op.kind === "rename-column" ? [[e.op.from, e.op.to]] : [])), g = kn(s.name, p, h, new Set(u.indexes.map((e) => e.name)), e.dialect);
|
|
1467
1467
|
a.push(...g.ops);
|
|
1468
|
-
for (let e of p.added) g.consumedAddedNames.has(e.name) || a.push(
|
|
1469
|
-
for (let e of p.removed) g.consumedRemovedNames.has(e.name) || a.push(
|
|
1470
|
-
for (let { declared: t, live: n } of f.changed) a.push(...
|
|
1468
|
+
for (let e of p.added) g.consumedAddedNames.has(e.name) || a.push(yn(s.name, e, u.rowCount, i));
|
|
1469
|
+
for (let e of p.removed) g.consumedRemovedNames.has(e.name) || a.push(bn(s.name, e));
|
|
1470
|
+
for (let { declared: t, live: n } of f.changed) a.push(...Cn(s.name, t, n, e.dialect, u.rowCount, i));
|
|
1471
1471
|
}
|
|
1472
1472
|
let c = new Set(a.flatMap((e) => e.op.kind === "create-table" ? [e.op.table] : [])), l = new Map(t.tables.map((e) => [e.name, e])), u = (e) => {
|
|
1473
1473
|
let t = l.get(e);
|
|
@@ -1476,7 +1476,7 @@ BEGIN
|
|
|
1476
1476
|
target: e.references.table
|
|
1477
1477
|
}] : []) : [];
|
|
1478
1478
|
}, d = fe([...c], u), f = [];
|
|
1479
|
-
for (let e of t.tables) if (c.has(e.name)) for (let t of e.columns) !t.references || !d.has(w(e.name, t.name)) || f.push(
|
|
1479
|
+
for (let e of t.tables) if (c.has(e.name)) for (let t of e.columns) !t.references || !d.has(w(e.name, t.name)) || f.push(L({
|
|
1480
1480
|
kind: "add-foreign-key",
|
|
1481
1481
|
table: e.name,
|
|
1482
1482
|
column: t.name,
|
|
@@ -1548,19 +1548,19 @@ BEGIN
|
|
|
1548
1548
|
});
|
|
1549
1549
|
return {
|
|
1550
1550
|
operations: S,
|
|
1551
|
-
fromFingerprint:
|
|
1552
|
-
toFingerprint:
|
|
1553
|
-
summary:
|
|
1551
|
+
fromFingerprint: P(e.live),
|
|
1552
|
+
toFingerprint: P(t),
|
|
1553
|
+
summary: Mn(S)
|
|
1554
1554
|
};
|
|
1555
|
-
},
|
|
1555
|
+
}, Pn = (e) => {
|
|
1556
1556
|
let t = /[`"[]?([A-Za-z_][A-Za-z0-9_]*)[`"\]]?\s*(?:in\b|=)/i.exec(e);
|
|
1557
1557
|
if (!t) return null;
|
|
1558
|
-
let n = [...e.replace(/\\'/g, "'
|
|
1558
|
+
let n = [...e.replace(/\\'/g, "'").matchAll(/'((?:[^']|'')*)'/g)].map((e) => e[1].replace(/''/g, "'")).filter((e) => e.length > 0);
|
|
1559
1559
|
return n.length === 0 ? null : {
|
|
1560
1560
|
column: t[1],
|
|
1561
1561
|
values: n
|
|
1562
1562
|
};
|
|
1563
|
-
},
|
|
1563
|
+
}, Fn = (e, t) => {
|
|
1564
1564
|
if (t === "vector") return "vector";
|
|
1565
1565
|
switch (e) {
|
|
1566
1566
|
case "text":
|
|
@@ -1587,10 +1587,10 @@ BEGIN
|
|
|
1587
1587
|
case "USER-DEFINED": return "text";
|
|
1588
1588
|
default: return "text";
|
|
1589
1589
|
}
|
|
1590
|
-
},
|
|
1590
|
+
}, In = (e, t) => e == null || e === "" ? void 0 : { generatedAs: {
|
|
1591
1591
|
expr: e,
|
|
1592
1592
|
stored: t
|
|
1593
|
-
} },
|
|
1593
|
+
} }, R = (e) => {
|
|
1594
1594
|
switch (e.toUpperCase()) {
|
|
1595
1595
|
case "CASCADE": return "cascade";
|
|
1596
1596
|
case "RESTRICT": return "restrict";
|
|
@@ -1598,25 +1598,25 @@ BEGIN
|
|
|
1598
1598
|
case "SET DEFAULT": return "noAction";
|
|
1599
1599
|
default: return "noAction";
|
|
1600
1600
|
}
|
|
1601
|
-
},
|
|
1601
|
+
}, Ln = (e, t) => {
|
|
1602
1602
|
let n = e !== void 0 && e !== "" ? Number(e) : NaN;
|
|
1603
1603
|
return Number.isInteger(n) && n > 0 ? n : t;
|
|
1604
|
-
},
|
|
1604
|
+
}, Rn = () => Ln(process.env.VOLTRO_INTROSPECT_BATCH, 20), zn = 300, Bn = () => {
|
|
1605
1605
|
let e = process.env.VOLTRO_INTROSPECT_TIMEOUT_MS;
|
|
1606
|
-
return e !== void 0 && e.trim() === "0" ? 0 :
|
|
1607
|
-
},
|
|
1606
|
+
return e !== void 0 && e.trim() === "0" ? 0 : Ln(e, 3e4);
|
|
1607
|
+
}, Vn = (e, t) => {
|
|
1608
1608
|
let n = Number.isFinite(t) && t >= 1 ? Math.floor(t) : 1, r = [];
|
|
1609
1609
|
for (let t = 0; t < e.length; t += n) r.push(e.slice(t, t + n));
|
|
1610
1610
|
return r;
|
|
1611
|
-
},
|
|
1612
|
-
let t =
|
|
1611
|
+
}, Hn = (e) => {
|
|
1612
|
+
let t = Bn(), n = x.gen(function* () {
|
|
1613
1613
|
t > 0 && (yield* e.unsafe(`SET LOCAL statement_timeout = ${t}`));
|
|
1614
|
-
let n = (t) => e.unsafe("(" + t.map((e) => `'${e.replace(/'/g, "''")}'`).join(", ") + ")"), r = (t) => e.unsafe(String(Math.max(0, Math.trunc(t)))), i =
|
|
1614
|
+
let n = (t) => e.unsafe("(" + t.map((e) => `'${e.replace(/'/g, "''")}'`).join(", ") + ")"), r = (t) => e.unsafe(String(Math.max(0, Math.trunc(t)))), i = Rn(), a = (e, t) => x.gen(function* () {
|
|
1615
1615
|
let r = [];
|
|
1616
|
-
for (let a of
|
|
1616
|
+
for (let a of Vn(e, i)) a.length !== 0 && r.push(...yield* t(n(a)));
|
|
1617
1617
|
return r;
|
|
1618
1618
|
}), o = [];
|
|
1619
|
-
for (let t = 0;; t +=
|
|
1619
|
+
for (let t = 0;; t += zn) {
|
|
1620
1620
|
let n = yield* e`
|
|
1621
1621
|
SELECT c.relname AS table_name,
|
|
1622
1622
|
COALESCE(c.reltuples::bigint, 0) AS row_count
|
|
@@ -1624,9 +1624,9 @@ BEGIN
|
|
|
1624
1624
|
JOIN pg_namespace n ON n.oid = c.relnamespace
|
|
1625
1625
|
WHERE n.nspname = current_schema() AND c.relkind = 'r'
|
|
1626
1626
|
ORDER BY c.relname
|
|
1627
|
-
LIMIT ${r(
|
|
1627
|
+
LIMIT ${r(zn)} OFFSET ${r(t)}
|
|
1628
1628
|
`;
|
|
1629
|
-
if (o.push(...n), n.length <
|
|
1629
|
+
if (o.push(...n), n.length < zn) break;
|
|
1630
1630
|
}
|
|
1631
1631
|
let s = /* @__PURE__ */ new Set(), c = [];
|
|
1632
1632
|
for (let e of o) s.has(e.table_name) || (s.add(e.table_name), c.push(e));
|
|
@@ -1760,23 +1760,23 @@ BEGIN
|
|
|
1760
1760
|
let te = [];
|
|
1761
1761
|
for (let e of c) {
|
|
1762
1762
|
let t = /* @__PURE__ */ new Set(), n = (_.get(e.table_name) ?? []).filter((e) => !t.has(e.column_name) && (t.add(e.column_name), !0)), r = v.get(e.table_name) ?? /* @__PURE__ */ new Set(), i = y.get(e.table_name) ?? /* @__PURE__ */ new Set(), a = S.get(e.table_name) ?? [], o = new Map(a.map((e) => [e.source_column, e])), s = new Set(n.filter((e) => e.udt_name === "tsvector").map((e) => e.column_name)), c = n.filter((e) => !s.has(e.column_name)).map((t) => {
|
|
1763
|
-
let n = r.has(t.column_name) && r.size === 1, a = o.get(t.column_name), s = a ? "reference" : n && t.column_name === "id" ? "id" :
|
|
1763
|
+
let n = r.has(t.column_name) && r.size === 1, a = o.get(t.column_name), s = a ? "reference" : n && t.column_name === "id" ? "id" : Fn(t.data_type, t.udt_name), c = a ? {
|
|
1764
1764
|
table: a.target_table,
|
|
1765
1765
|
column: a.target_column,
|
|
1766
|
-
onDelete:
|
|
1767
|
-
onUpdate:
|
|
1766
|
+
onDelete: R(a.delete_rule),
|
|
1767
|
+
onUpdate: R(a.update_rule)
|
|
1768
1768
|
} : void 0, l = m.get(`${e.table_name}.${t.column_name}`);
|
|
1769
1769
|
return {
|
|
1770
1770
|
name: t.column_name,
|
|
1771
1771
|
type: s,
|
|
1772
|
-
...
|
|
1772
|
+
...V(t.data_type, t.character_maximum_length) === void 0 ? {} : { maxLength: V(t.data_type, t.character_maximum_length) },
|
|
1773
1773
|
nullable: t.is_nullable === "YES",
|
|
1774
1774
|
unique: i.has(t.column_name) || n && t.column_name === "id",
|
|
1775
1775
|
hasDefault: t.column_default !== null,
|
|
1776
1776
|
...t.column_default === null ? {} : { defaultValue: t.column_default },
|
|
1777
1777
|
...c ? { references: c } : {},
|
|
1778
1778
|
...l ? { oneOf: l } : {},
|
|
1779
|
-
...
|
|
1779
|
+
...In(t.is_generated === "ALWAYS" ? t.generation_expression ?? "generated" : null, !0) ?? {}
|
|
1780
1780
|
};
|
|
1781
1781
|
}), l = [], u = ee.get(e.table_name);
|
|
1782
1782
|
if (u) for (let [t, n] of u) {
|
|
@@ -1815,7 +1815,7 @@ BEGIN
|
|
|
1815
1815
|
let n = `${String(e)} ${String(e.cause ?? "")}`.toLowerCase();
|
|
1816
1816
|
return n.includes("statement timeout") || n.includes("57014") ? x.die(/* @__PURE__ */ Error(`schema introspection exceeded VOLTRO_INTROSPECT_TIMEOUT_MS (${t}ms) — the schema is very large / FK-dense or the database is slow. Raise VOLTRO_INTROSPECT_TIMEOUT_MS, set it to 0 to disable the ceiling, or use DB_DIRECT_URL for a non-pooler connection.`)) : x.fail(e);
|
|
1817
1817
|
}));
|
|
1818
|
-
},
|
|
1818
|
+
}, Un = (e, t) => {
|
|
1819
1819
|
switch (e.toLowerCase()) {
|
|
1820
1820
|
case "varchar":
|
|
1821
1821
|
case "char":
|
|
@@ -1847,21 +1847,21 @@ BEGIN
|
|
|
1847
1847
|
case "json": return "json";
|
|
1848
1848
|
default: return "text";
|
|
1849
1849
|
}
|
|
1850
|
-
},
|
|
1850
|
+
}, z = (e) => e.map((e) => {
|
|
1851
1851
|
let t = e, n = {};
|
|
1852
1852
|
for (let e of Object.keys(t)) n[e.toLowerCase()] = t[e];
|
|
1853
1853
|
return n;
|
|
1854
|
-
}),
|
|
1855
|
-
let t =
|
|
1854
|
+
}), Wn = (e) => x.gen(function* () {
|
|
1855
|
+
let t = z(yield* e`
|
|
1856
1856
|
SELECT table_name, COALESCE(table_rows, 0) AS table_rows
|
|
1857
1857
|
FROM information_schema.tables
|
|
1858
1858
|
WHERE table_schema = DATABASE() AND table_type = 'BASE TABLE'
|
|
1859
|
-
ORDER BY table_name`), n =
|
|
1859
|
+
ORDER BY table_name`), n = z(yield* e`
|
|
1860
1860
|
SELECT table_name, column_name, data_type, column_type, is_nullable, column_default, column_key,
|
|
1861
1861
|
character_maximum_length, generation_expression, extra
|
|
1862
1862
|
FROM information_schema.columns
|
|
1863
1863
|
WHERE table_schema = DATABASE()
|
|
1864
|
-
ORDER BY table_name, ordinal_position`), r =
|
|
1864
|
+
ORDER BY table_name, ordinal_position`), r = z(yield* e`
|
|
1865
1865
|
SELECT k.table_name AS source_table,
|
|
1866
1866
|
k.column_name AS source_column,
|
|
1867
1867
|
k.referenced_table_name AS target_table,
|
|
@@ -1871,66 +1871,69 @@ BEGIN
|
|
|
1871
1871
|
JOIN information_schema.referential_constraints r
|
|
1872
1872
|
ON k.constraint_name = r.constraint_name
|
|
1873
1873
|
AND k.table_schema = r.constraint_schema
|
|
1874
|
-
WHERE k.table_schema = DATABASE() AND k.referenced_table_name IS NOT NULL`), i =
|
|
1874
|
+
WHERE k.table_schema = DATABASE() AND k.referenced_table_name IS NOT NULL`), i = z(yield* e`
|
|
1875
1875
|
SELECT table_name, index_name, non_unique, column_name, seq_in_index
|
|
1876
1876
|
FROM information_schema.statistics
|
|
1877
1877
|
WHERE table_schema = DATABASE() AND index_name <> 'PRIMARY'
|
|
1878
|
-
ORDER BY table_name, index_name, seq_in_index`), a =
|
|
1878
|
+
ORDER BY table_name, index_name, seq_in_index`), a = e`
|
|
1879
|
+
SELECT cc.table_name AS table_name, cc.check_clause AS check_clause
|
|
1880
|
+
FROM information_schema.check_constraints cc
|
|
1881
|
+
WHERE cc.constraint_schema = DATABASE()`.unprepared, o = e`
|
|
1879
1882
|
SELECT tc.table_name AS table_name, cc.check_clause AS check_clause
|
|
1880
1883
|
FROM information_schema.check_constraints cc
|
|
1881
1884
|
JOIN information_schema.table_constraints tc
|
|
1882
1885
|
ON tc.constraint_schema = cc.constraint_schema
|
|
1883
1886
|
AND tc.constraint_name = cc.constraint_name
|
|
1884
|
-
WHERE cc.constraint_schema = DATABASE()`.unprepared.pipe(x.orElseSucceed(() => []))),
|
|
1885
|
-
for (let e of
|
|
1887
|
+
WHERE cc.constraint_schema = DATABASE()`.unprepared, s = z(yield* a.pipe(x.orElse(() => o), x.orElseSucceed(() => []))), c = /* @__PURE__ */ new Set(), l = /* @__PURE__ */ new Map();
|
|
1888
|
+
for (let e of s) {
|
|
1886
1889
|
let t = /json_valid\(`?([^`)]+)`?\)/i.exec(e.check_clause);
|
|
1887
1890
|
if (t) {
|
|
1888
|
-
|
|
1891
|
+
c.add(`${e.table_name}.${t[1]}`);
|
|
1889
1892
|
continue;
|
|
1890
1893
|
}
|
|
1891
|
-
let n =
|
|
1892
|
-
n &&
|
|
1894
|
+
let n = Pn(e.check_clause);
|
|
1895
|
+
n && l.set(`${e.table_name}.${n.column}`, n.values);
|
|
1893
1896
|
}
|
|
1894
|
-
let
|
|
1897
|
+
let u = /* @__PURE__ */ new Map(), d = /* @__PURE__ */ new Map(), f = /* @__PURE__ */ new Map();
|
|
1895
1898
|
for (let e of n) {
|
|
1896
|
-
let t =
|
|
1897
|
-
t.push(e),
|
|
1899
|
+
let t = u.get(e.table_name) ?? [];
|
|
1900
|
+
t.push(e), u.set(e.table_name, t);
|
|
1898
1901
|
}
|
|
1899
1902
|
for (let e of r) {
|
|
1900
|
-
let t =
|
|
1901
|
-
t.push(e),
|
|
1903
|
+
let t = d.get(e.source_table) ?? [];
|
|
1904
|
+
t.push(e), d.set(e.source_table, t);
|
|
1902
1905
|
}
|
|
1903
1906
|
for (let e of i) {
|
|
1904
|
-
let t =
|
|
1905
|
-
t || (t = /* @__PURE__ */ new Map(),
|
|
1907
|
+
let t = f.get(e.table_name);
|
|
1908
|
+
t || (t = /* @__PURE__ */ new Map(), f.set(e.table_name, t));
|
|
1906
1909
|
let n = t.get(e.index_name) ?? [];
|
|
1907
1910
|
n.push(e), t.set(e.index_name, n);
|
|
1908
1911
|
}
|
|
1909
|
-
let
|
|
1912
|
+
let p = [];
|
|
1910
1913
|
for (let e of t) {
|
|
1911
|
-
let t =
|
|
1912
|
-
if (
|
|
1913
|
-
let
|
|
1914
|
-
let n = i.includes(t.column_name) && i.length === 1,
|
|
1915
|
-
table:
|
|
1916
|
-
column:
|
|
1917
|
-
onDelete:
|
|
1918
|
-
onUpdate:
|
|
1919
|
-
} : void 0, d = a.has(t.column_name) || n && t.column_name === "id", f = t.column_default === "NULL" ? null : t.column_default, p =
|
|
1914
|
+
let t = u.get(e.table_name) ?? [], n = d.get(e.table_name) ?? [], r = new Map(n.map((e) => [e.source_column, e])), i = t.filter((e) => e.column_key === "PRI").map((e) => e.column_name), a = /* @__PURE__ */ new Set(), o = f.get(e.table_name);
|
|
1915
|
+
if (o) for (let e of o.values()) e.length === 1 && e[0].non_unique === 0 && a.add(e[0].column_name);
|
|
1916
|
+
let s = t.map((t) => {
|
|
1917
|
+
let n = i.includes(t.column_name) && i.length === 1, o = r.get(t.column_name), s = o ? "reference" : n && t.column_name === "id" ? "id" : c.has(`${e.table_name}.${t.column_name}`) ? "json" : Un(t.data_type, t.column_type), u = o ? {
|
|
1918
|
+
table: o.target_table,
|
|
1919
|
+
column: o.target_column,
|
|
1920
|
+
onDelete: R(o.delete_rule),
|
|
1921
|
+
onUpdate: R(o.update_rule)
|
|
1922
|
+
} : void 0, d = a.has(t.column_name) || n && t.column_name === "id", f = t.column_default === "NULL" ? null : t.column_default, p = l.get(`${e.table_name}.${t.column_name}`);
|
|
1920
1923
|
return {
|
|
1921
1924
|
name: t.column_name,
|
|
1922
|
-
type:
|
|
1925
|
+
type: s,
|
|
1923
1926
|
nullable: t.is_nullable === "YES",
|
|
1924
|
-
...
|
|
1927
|
+
...V(t.data_type, t.character_maximum_length) === void 0 ? {} : { maxLength: V(t.data_type, t.character_maximum_length) },
|
|
1925
1928
|
unique: d,
|
|
1926
1929
|
hasDefault: f !== null,
|
|
1927
1930
|
...f === null ? {} : { defaultValue: f },
|
|
1928
1931
|
...u ? { references: u } : {},
|
|
1929
1932
|
...p ? { oneOf: p } : {},
|
|
1930
|
-
...
|
|
1933
|
+
...In(t.generation_expression, /STORED/i.test(t.extra ?? "")) ?? {}
|
|
1931
1934
|
};
|
|
1932
1935
|
}), m = new Set(n.map((e) => e.source_column)), h = [];
|
|
1933
|
-
if (
|
|
1936
|
+
if (o) for (let [t, n] of o) {
|
|
1934
1937
|
let r = [...n].sort((e, t) => e.seq_in_index - t.seq_in_index);
|
|
1935
1938
|
(r.length !== 1 || r[0].non_unique !== 0) && (r.length === 1 && r[0].non_unique !== 0 && m.has(r[0].column_name) && t !== `${e.table_name}_${r[0].column_name}_idx` || h.push({
|
|
1936
1939
|
name: t,
|
|
@@ -1946,18 +1949,18 @@ BEGIN
|
|
|
1946
1949
|
unique: !0
|
|
1947
1950
|
});
|
|
1948
1951
|
let g = Number(e.table_rows ?? 0);
|
|
1949
|
-
|
|
1952
|
+
p.push({
|
|
1950
1953
|
name: e.table_name,
|
|
1951
|
-
columns:
|
|
1954
|
+
columns: s,
|
|
1952
1955
|
indexes: h,
|
|
1953
1956
|
...g > 0 ? { rowCount: g } : {}
|
|
1954
1957
|
});
|
|
1955
1958
|
}
|
|
1956
|
-
return { tables:
|
|
1957
|
-
}),
|
|
1959
|
+
return { tables: p };
|
|
1960
|
+
}), Gn = (e) => {
|
|
1958
1961
|
let t = e.toUpperCase();
|
|
1959
1962
|
return t.includes("INT") ? "integer" : t.includes("REAL") || t.includes("FLOA") || t.includes("DOUB") ? "real" : t.includes("BLOB") ? "bytes" : "text";
|
|
1960
|
-
},
|
|
1963
|
+
}, Kn = (e) => x.gen(function* () {
|
|
1961
1964
|
let t = yield* e`
|
|
1962
1965
|
SELECT name, sql FROM sqlite_master
|
|
1963
1966
|
WHERE type = 'table' AND name NOT LIKE 'sqlite_%'
|
|
@@ -1974,11 +1977,11 @@ BEGIN
|
|
|
1974
1977
|
d.set(t.name, r), t.unique === 1 && r.length === 1 && f.add(r[0]);
|
|
1975
1978
|
}
|
|
1976
1979
|
let p = o.map((e) => {
|
|
1977
|
-
let n = u.length === 1 && u[0] === e.name, r = l.get(e.name), i = r ? "reference" : n && e.name === "id" ? "id" :
|
|
1980
|
+
let n = u.length === 1 && u[0] === e.name, r = l.get(e.name), i = r ? "reference" : n && e.name === "id" ? "id" : Gn(e.type), a = r ? {
|
|
1978
1981
|
table: r.table,
|
|
1979
1982
|
column: r.to,
|
|
1980
|
-
onDelete:
|
|
1981
|
-
onUpdate:
|
|
1983
|
+
onDelete: R(r.on_delete),
|
|
1984
|
+
onUpdate: R(r.on_update)
|
|
1982
1985
|
} : void 0, o = t.get(e.name);
|
|
1983
1986
|
return {
|
|
1984
1987
|
name: e.name,
|
|
@@ -1989,7 +1992,7 @@ BEGIN
|
|
|
1989
1992
|
...e.dflt_value === null ? {} : { defaultValue: e.dflt_value },
|
|
1990
1993
|
...a ? { references: a } : {},
|
|
1991
1994
|
...o ? { oneOf: o } : {},
|
|
1992
|
-
...
|
|
1995
|
+
...In(e.hidden === 2 || e.hidden === 3 ? "generated" : null, e.hidden === 3) ?? {}
|
|
1993
1996
|
};
|
|
1994
1997
|
}), m = new Set(s.map((e) => e.from)), h = [];
|
|
1995
1998
|
for (let e of c) {
|
|
@@ -2014,7 +2017,7 @@ BEGIN
|
|
|
2014
2017
|
});
|
|
2015
2018
|
}
|
|
2016
2019
|
return { tables: r };
|
|
2017
|
-
}),
|
|
2020
|
+
}), qn = (e) => {
|
|
2018
2021
|
switch (e.toLowerCase()) {
|
|
2019
2022
|
case "int":
|
|
2020
2023
|
case "smallint":
|
|
@@ -2036,7 +2039,7 @@ BEGIN
|
|
|
2036
2039
|
case "image": return "bytes";
|
|
2037
2040
|
default: return "text";
|
|
2038
2041
|
}
|
|
2039
|
-
},
|
|
2042
|
+
}, B = (e) => e === !0 || e === 1, Jn = (e) => x.gen(function* () {
|
|
2040
2043
|
let t = yield* e`
|
|
2041
2044
|
SELECT TABLE_NAME AS table_name FROM INFORMATION_SCHEMA.TABLES
|
|
2042
2045
|
WHERE TABLE_TYPE = 'BASE TABLE' ORDER BY TABLE_NAME`, n = yield* e`
|
|
@@ -2098,36 +2101,36 @@ BEGIN
|
|
|
2098
2101
|
let t = l.get(e) ?? [], n = u.get(e) ?? [], r = new Map(n.map((e) => [e.source_column, e])), a = new Set(n.map((e) => e.source_column)), o = d.get(e), s = [], p = /* @__PURE__ */ new Set();
|
|
2099
2102
|
if (o) for (let [, e] of o) {
|
|
2100
2103
|
let t = [...e].sort((e, t) => e.key_ordinal - t.key_ordinal);
|
|
2101
|
-
if (
|
|
2102
|
-
else
|
|
2104
|
+
if (B(t[0].is_primary)) for (let e of t) s.push(e.column_name);
|
|
2105
|
+
else B(t[0].is_unique) && t.length === 1 && p.add(t[0].column_name);
|
|
2103
2106
|
}
|
|
2104
2107
|
let m = t.map((t) => {
|
|
2105
|
-
let n = s.length === 1 && s[0] === t.column_name, a = r.get(t.column_name), o = a ? "reference" : n && t.column_name === "id" ? "id" :
|
|
2108
|
+
let n = s.length === 1 && s[0] === t.column_name, a = r.get(t.column_name), o = a ? "reference" : n && t.column_name === "id" ? "id" : qn(t.data_type), l = a ? {
|
|
2106
2109
|
table: a.target_table,
|
|
2107
2110
|
column: a.target_column,
|
|
2108
|
-
onDelete:
|
|
2109
|
-
onUpdate:
|
|
2110
|
-
} : void 0, u = t.column_default === null ? null :
|
|
2111
|
+
onDelete: Yn(a.delete_rule),
|
|
2112
|
+
onUpdate: Yn(a.update_rule)
|
|
2113
|
+
} : void 0, u = t.column_default === null ? null : Xn(t.column_default), d = c.get(`${e}.${t.column_name}`);
|
|
2111
2114
|
return {
|
|
2112
2115
|
name: t.column_name,
|
|
2113
2116
|
type: o,
|
|
2114
2117
|
nullable: t.is_nullable === "YES",
|
|
2115
|
-
...
|
|
2118
|
+
...V(t.data_type, t.character_maximum_length) === void 0 ? {} : { maxLength: V(t.data_type, t.character_maximum_length) },
|
|
2116
2119
|
unique: p.has(t.column_name) || n && t.column_name === "id",
|
|
2117
2120
|
hasDefault: u !== null,
|
|
2118
2121
|
...u === null ? {} : { defaultValue: u },
|
|
2119
2122
|
...l ? { references: l } : {},
|
|
2120
2123
|
...d ? { oneOf: d } : {},
|
|
2121
|
-
...
|
|
2124
|
+
...In(i.get(`${e}.${t.column_name}`)?.definition ?? null, B(i.get(`${e}.${t.column_name}`)?.is_persisted ?? !1)) ?? {}
|
|
2122
2125
|
};
|
|
2123
2126
|
}), h = [];
|
|
2124
2127
|
if (o) for (let [t, n] of o) {
|
|
2125
2128
|
let r = [...n].sort((e, t) => e.key_ordinal - t.key_ordinal);
|
|
2126
|
-
|
|
2129
|
+
B(r[0].is_primary) || r.length === 1 && B(r[0].is_unique) || r.length === 1 && !B(r[0].is_unique) && a.has(r[0].column_name) && t !== `${e}_${r[0].column_name}_idx` || h.push({
|
|
2127
2130
|
name: t,
|
|
2128
2131
|
table: e,
|
|
2129
2132
|
columns: r.map((e) => e.column_name),
|
|
2130
|
-
unique:
|
|
2133
|
+
unique: B(r[0].is_unique)
|
|
2131
2134
|
});
|
|
2132
2135
|
}
|
|
2133
2136
|
s.length > 0 && h.push({
|
|
@@ -2142,87 +2145,90 @@ BEGIN
|
|
|
2142
2145
|
});
|
|
2143
2146
|
}
|
|
2144
2147
|
return { tables: f };
|
|
2145
|
-
}),
|
|
2148
|
+
}), Yn = (e) => {
|
|
2146
2149
|
switch (e.toUpperCase().replace(/_/g, " ")) {
|
|
2147
2150
|
case "CASCADE": return "cascade";
|
|
2148
2151
|
case "SET NULL": return "setNull";
|
|
2149
2152
|
case "SET DEFAULT": return "noAction";
|
|
2150
2153
|
default: return "noAction";
|
|
2151
2154
|
}
|
|
2152
|
-
},
|
|
2155
|
+
}, Xn = (e) => {
|
|
2153
2156
|
let t = e.trim();
|
|
2154
2157
|
for (; t.startsWith("(") && t.endsWith(")");) t = t.slice(1, -1).trim();
|
|
2155
2158
|
return t.startsWith("N'") && t.endsWith("'") ? t = t.slice(2, -1) : t.startsWith("'") && t.endsWith("'") && (t = t.slice(1, -1)), t;
|
|
2156
|
-
},
|
|
2159
|
+
}, Zn = /* @__PURE__ */ new Set([
|
|
2157
2160
|
"character varying",
|
|
2158
2161
|
"varchar",
|
|
2159
2162
|
"nvarchar",
|
|
2160
2163
|
"char",
|
|
2161
2164
|
"character",
|
|
2162
2165
|
"nchar"
|
|
2163
|
-
]),
|
|
2164
|
-
if (!
|
|
2166
|
+
]), V = (e, t) => {
|
|
2167
|
+
if (!Zn.has(e.toLowerCase())) return;
|
|
2165
2168
|
let n = Number(t);
|
|
2166
2169
|
if (!(!Number.isFinite(n) || n <= 0)) return n;
|
|
2167
|
-
},
|
|
2168
|
-
mysql: () =>
|
|
2169
|
-
mssql: () =>
|
|
2170
|
-
sqlite: () =>
|
|
2171
|
-
orElse: () =>
|
|
2170
|
+
}, Qn = /* @__PURE__ */ new Set([D]), $n = (e) => e.onDialectOrElse({
|
|
2171
|
+
mysql: () => Wn(e),
|
|
2172
|
+
mssql: () => Jn(e),
|
|
2173
|
+
sqlite: () => Kn(e),
|
|
2174
|
+
orElse: () => Hn(e)
|
|
2172
2175
|
}).pipe(x.map((e) => ({
|
|
2173
2176
|
...e,
|
|
2174
|
-
tables: e.tables.filter((e) => !
|
|
2175
|
-
}))),
|
|
2176
|
-
let t =
|
|
2177
|
-
return t === void 0 ?
|
|
2178
|
-
}),
|
|
2177
|
+
tables: e.tables.filter((e) => !Qn.has(e.name))
|
|
2178
|
+
}))), er = (e) => /mariadb/i.test(e) ? "mariadb" : "mysql", tr = /* @__PURE__ */ new WeakMap(), H = (e) => x.suspend(() => {
|
|
2179
|
+
let t = tr.get(e);
|
|
2180
|
+
return t === void 0 ? nr(e).pipe(x.tap((t) => x.sync(() => tr.set(e, t)))) : x.succeed(t);
|
|
2181
|
+
}), nr = (e) => e.unsafe("SELECT VERSION() AS v").pipe(x.map((e) => {
|
|
2179
2182
|
let t = e[0]?.v;
|
|
2180
|
-
return typeof t == "string" ?
|
|
2181
|
-
}), x.catchAll(() => x.succeed("mysql"))),
|
|
2183
|
+
return typeof t == "string" ? er(t) : "mysql";
|
|
2184
|
+
}), x.catchAll(() => x.succeed("mysql"))), rr = (e) => {
|
|
2182
2185
|
let t = e;
|
|
2183
2186
|
for (let e = 0; e < 6 && typeof t == "object" && t; e++) {
|
|
2184
2187
|
let e = t;
|
|
2185
2188
|
if (typeof e.errno == "number") return e.errno;
|
|
2186
2189
|
t = e.cause;
|
|
2187
2190
|
}
|
|
2188
|
-
},
|
|
2191
|
+
}, ir = (e) => {
|
|
2189
2192
|
let t = [], n = e;
|
|
2190
2193
|
for (let e = 0; e < 6 && typeof n == "object" && n; e++) {
|
|
2191
2194
|
let e = n;
|
|
2192
2195
|
typeof e.message == "string" && t.push(e.message), n = e.cause;
|
|
2193
2196
|
}
|
|
2194
2197
|
return t.join(" | ");
|
|
2195
|
-
},
|
|
2198
|
+
}, ar = (e, t) => {
|
|
2196
2199
|
if (t.length === 0) return !1;
|
|
2197
|
-
let n =
|
|
2200
|
+
let n = rr(e), r = ir(e);
|
|
2198
2201
|
return t.some((e) => e.errno !== void 0 && n !== void 0 && e.errno.includes(n) || e.messageIncludes !== void 0 && e.messageIncludes.some((e) => r.includes(e)));
|
|
2199
|
-
},
|
|
2202
|
+
}, or = {
|
|
2200
2203
|
why: "mysql has no CREATE INDEX IF NOT EXISTS; 1061 is exactly that condition",
|
|
2201
2204
|
errno: [1061]
|
|
2202
|
-
},
|
|
2205
|
+
}, sr = {
|
|
2203
2206
|
why: "mysql has no DROP COLUMN IF EXISTS; 1091 is exactly that condition",
|
|
2204
2207
|
errno: [1091]
|
|
2205
|
-
},
|
|
2208
|
+
}, cr = {
|
|
2206
2209
|
why: "sqlite has no DROP COLUMN IF EXISTS, and reports the absent column only in the message",
|
|
2207
2210
|
messageIncludes: ["no such column"]
|
|
2208
|
-
},
|
|
2211
|
+
}, lr = {
|
|
2212
|
+
why: "mysql/mariadb DROP CONSTRAINT has no portable IF EXISTS; 1091 / 3940 are exactly \"already gone\"",
|
|
2213
|
+
errno: [1091, 3940]
|
|
2214
|
+
}, U = (e, t) => e.onDialectOrElse({
|
|
2209
2215
|
mysql: () => x.succeed(t.replace("T", " ").replace("Z", "")),
|
|
2210
2216
|
orElse: () => x.succeed(t)
|
|
2211
|
-
}),
|
|
2217
|
+
}), ur = (e, t) => `${t}(${e.precision ?? 38}, ${e.scale ?? 0})`, dr = (e, t) => {
|
|
2212
2218
|
if ((e.type !== "text" || e.maxLength === void 0) && !e.spatial && e.type !== "vector" && e.type !== "array" && e.type !== "enum") return;
|
|
2213
2219
|
let n = e.type === "vector" && e.vectorDim === void 0 ? "vector dimension" : e.type === "array" && e.arrayElement === void 0 ? "array element type" : e.type === "enum" && e.enumName === void 0 && e.enumValues === void 0 ? "enum name/values" : void 0;
|
|
2214
2220
|
if (n !== void 0) throw Error(`migration applier: cannot render '${e.name}' (${e.type}) — the schema snapshot carries no ${n}. Rendering it as 'text' would emit DDL that applies successfully and changes nothing, so this fails instead. This is a framework bug: declaredSchema.ts must carry the parameter into the ColumnSnapshot.`);
|
|
2215
|
-
return
|
|
2216
|
-
},
|
|
2217
|
-
let t =
|
|
2218
|
-
return t === void 0 ?
|
|
2219
|
-
},
|
|
2221
|
+
return A(e, t);
|
|
2222
|
+
}, fr = (e) => {
|
|
2223
|
+
let t = dr(e, "postgres");
|
|
2224
|
+
return t === void 0 ? pr(e) : t;
|
|
2225
|
+
}, pr = (e) => {
|
|
2220
2226
|
switch (e.type) {
|
|
2221
2227
|
case "id": return "text";
|
|
2222
2228
|
case "text": return "text";
|
|
2223
2229
|
case "integer": return "integer";
|
|
2224
2230
|
case "real": return "double precision";
|
|
2225
|
-
case "decimal": return
|
|
2231
|
+
case "decimal": return ur(e, "NUMERIC");
|
|
2226
2232
|
case "bigint": return "bigint";
|
|
2227
2233
|
case "boolean": return "boolean";
|
|
2228
2234
|
case "timestamp": return "timestamptz";
|
|
@@ -2236,15 +2242,15 @@ BEGIN
|
|
|
2236
2242
|
case "interval": return "interval";
|
|
2237
2243
|
case "raw": return e.rawDdl ?? "text";
|
|
2238
2244
|
}
|
|
2239
|
-
},
|
|
2240
|
-
let t =
|
|
2245
|
+
}, mr = (e) => {
|
|
2246
|
+
let t = dr(e, "mariadb");
|
|
2241
2247
|
if (t !== void 0) return t;
|
|
2242
2248
|
switch (e.type) {
|
|
2243
2249
|
case "id": return "VARCHAR(64)";
|
|
2244
2250
|
case "text": return e.hasDefault && e.defaultValue !== void 0 || e.oneOf && e.oneOf.length > 0 ? "VARCHAR(255)" : "LONGTEXT";
|
|
2245
2251
|
case "integer": return "INT";
|
|
2246
2252
|
case "real": return "DOUBLE";
|
|
2247
|
-
case "decimal": return
|
|
2253
|
+
case "decimal": return ur(e, "DECIMAL");
|
|
2248
2254
|
case "bigint": return "BIGINT";
|
|
2249
2255
|
case "boolean": return "TINYINT(1)";
|
|
2250
2256
|
case "timestamp": return "DATETIME(6)";
|
|
@@ -2258,58 +2264,58 @@ BEGIN
|
|
|
2258
2264
|
case "interval": return "BIGINT";
|
|
2259
2265
|
case "raw": return e.rawDdl ?? "LONGTEXT";
|
|
2260
2266
|
}
|
|
2261
|
-
},
|
|
2267
|
+
}, W = (e) => `"${e}"`, G = (e) => `\`${e.replace(/`/g, "``")}\``, hr = (e) => e === "mariadb" ? "IF NOT EXISTS " : "", gr = (e, t, n = !0) => `ALTER TABLE ${t(e.table)} DROP COLUMN ${n ? "IF EXISTS " : ""}${t(e.column)};`, _r = (e, t = "mariadb") => `ALTER TABLE ${G(e.table)} DROP COLUMN ${t === "mariadb" ? "IF EXISTS " : ""}${G(e.column)}, ALGORITHM=COPY;`, vr = (e, t) => `ALTER TABLE ${t(e.table)} RENAME COLUMN ${t(e.from)} TO ${t(e.to)};`, yr = (e, t, n) => `ALTER TABLE ${n(e.table)} RENAME COLUMN ${n(e.column)} TO ${n(`${e.column}${Kr(t)}`)};`, br = (e, t, n) => e.hasDefault && e.defaultValue !== void 0 ? `ALTER TABLE ${t(e.table)} ALTER COLUMN ${t(e.column)} SET ${xr(e, n)};` : `ALTER TABLE ${t(e.table)} ALTER COLUMN ${t(e.column)} DROP DEFAULT;`, xr = (e, t) => {
|
|
2262
2268
|
let n = t(e.defaultValue);
|
|
2263
2269
|
if (n === null) throw Error(`migration applier: cannot render the declared default for '${e.table}.${e.column}' (${JSON.stringify(e.defaultValue)}). Emitting 'DEFAULT NULL' would apply cleanly and drop the default silently, so this fails instead. This is a framework bug — report the column type + default.`);
|
|
2264
2270
|
return n;
|
|
2265
|
-
},
|
|
2266
|
-
let r =
|
|
2267
|
-
return r ?
|
|
2268
|
-
},
|
|
2269
|
-
let r = n ?? e.nullable, i =
|
|
2271
|
+
}, K = (e, t, n) => e.find((e) => e.tableName === t)?.fields[n], Sr = (e, t, n) => {
|
|
2272
|
+
let r = K(e, t, n);
|
|
2273
|
+
return r ? Kt(n, r) : void 0;
|
|
2274
|
+
}, Cr = (e, t, n) => {
|
|
2275
|
+
let r = n ?? e.nullable, i = $e(e, "mariadb");
|
|
2270
2276
|
return [
|
|
2271
|
-
|
|
2272
|
-
|
|
2277
|
+
G(t),
|
|
2278
|
+
A(e, "mariadb"),
|
|
2273
2279
|
r ? null : "NOT NULL",
|
|
2274
2280
|
i
|
|
2275
2281
|
].filter(Boolean).join(" ");
|
|
2276
|
-
},
|
|
2282
|
+
}, wr = (e, t) => e == null ? null : Array.isArray(e) ? Tr(e, t, "mariadb") : e === "now" ? "DEFAULT CURRENT_TIMESTAMP(6)" : typeof e == "boolean" ? `DEFAULT ${+!!e}` : typeof e == "number" ? `DEFAULT ${e}` : typeof e == "string" ? /[()]|^'/.test(e) ? `DEFAULT ${e}` : `DEFAULT '${e.replace(/'/g, "''")}'` : typeof e == "object" ? j(e, "mariadb") : null, Tr = (e, t, n) => et(e, t ?? { type: "json" }, n), Er = (e, t) => e == null ? null : Array.isArray(e) ? Tr(e, t, "postgres") : e === "now" ? "DEFAULT now()" : typeof e == "boolean" || typeof e == "number" ? `DEFAULT ${e}` : typeof e == "string" ? /[()]|::|^'/.test(e) ? `DEFAULT ${e}` : `DEFAULT '${e.replace(/'/g, "''")}'` : typeof e == "object" ? j(e, "postgres") : null, q = (e, t) => {
|
|
2277
2283
|
if (!e.generatedAs) return null;
|
|
2278
2284
|
let { expr: n, stored: r } = e.generatedAs;
|
|
2279
2285
|
return t === "postgres" ? `GENERATED ALWAYS AS (${n}) STORED` : t === "mssql" ? `AS (${n})${r ? " PERSISTED" : ""}` : `GENERATED ALWAYS AS (${n}) ${r ? "STORED" : "VIRTUAL"}`;
|
|
2280
|
-
},
|
|
2281
|
-
if (e.type === "id" && e.idScheme?.kind === "numeric") return
|
|
2282
|
-
let t =
|
|
2283
|
-
if (t) return `${
|
|
2284
|
-
let n = [
|
|
2286
|
+
}, Dr = (e) => {
|
|
2287
|
+
if (e.type === "id" && e.idScheme?.kind === "numeric") return M(e.name, "postgres");
|
|
2288
|
+
let t = q(e, "postgres");
|
|
2289
|
+
if (t) return `${W(e.name)} ${fr(e)} ${t}`;
|
|
2290
|
+
let n = [W(e.name), fr(e)];
|
|
2285
2291
|
if (e.type === "id" && n.push("PRIMARY KEY"), e.nullable || n.push("NOT NULL"), e.unique && e.type !== "id" && n.push("UNIQUE"), e.hasDefault) {
|
|
2286
|
-
let t =
|
|
2292
|
+
let t = Er(e.defaultValue, e);
|
|
2287
2293
|
t && n.push(t);
|
|
2288
2294
|
}
|
|
2289
|
-
return e.references && (n.push(`REFERENCES ${
|
|
2295
|
+
return e.references && (n.push(`REFERENCES ${W(e.references.table)} (${W(e.references.column)})`), e.references.onDelete && n.push(`ON DELETE ${{
|
|
2290
2296
|
cascade: "CASCADE",
|
|
2291
2297
|
restrict: "RESTRICT",
|
|
2292
2298
|
setNull: "SET NULL",
|
|
2293
2299
|
noAction: "NO ACTION"
|
|
2294
2300
|
}[e.references.onDelete]}`)), n.join(" ");
|
|
2295
|
-
},
|
|
2296
|
-
let t = e.columns.map((e) => ` ${
|
|
2297
|
-
for (let t of e.indexes) t.name !== `${e.table}_pkey` && n.push(`CREATE ${t.unique ? "UNIQUE " : ""}INDEX IF NOT EXISTS ${
|
|
2301
|
+
}, Or = (e, t) => e.primaryKey && e.primaryKey.length > 0 ? `,\n PRIMARY KEY (${e.primaryKey.map(t).join(", ")})` : "", kr = (e) => {
|
|
2302
|
+
let t = e.columns.map((e) => ` ${Dr(e)}`).join(",\n"), n = [`CREATE TABLE IF NOT EXISTS ${W(e.table)} (\n${t}${Or(e, W)}\n)`];
|
|
2303
|
+
for (let t of e.indexes) t.name !== `${e.table}_pkey` && n.push(`CREATE ${t.unique ? "UNIQUE " : ""}INDEX IF NOT EXISTS ${W(t.name)} ON ${W(e.table)} (${t.columns.map(Zr).join(", ")})`);
|
|
2298
2304
|
return n;
|
|
2299
|
-
},
|
|
2300
|
-
let t =
|
|
2305
|
+
}, Ar = 191, jr = (e) => {
|
|
2306
|
+
let t = mr(e).toUpperCase();
|
|
2301
2307
|
return t.endsWith("TEXT") || t.endsWith("BLOB");
|
|
2302
|
-
},
|
|
2303
|
-
if (e.type === "id" && e.idScheme?.kind === "numeric") return
|
|
2304
|
-
let t =
|
|
2305
|
-
if (t) return `${
|
|
2306
|
-
let n = [
|
|
2307
|
-
if (e.type === "id" && n.push("PRIMARY KEY"), e.nullable || n.push("NOT NULL"), e.unique && e.type !== "id" && !
|
|
2308
|
-
let t =
|
|
2308
|
+
}, Mr = (e) => {
|
|
2309
|
+
if (e.type === "id" && e.idScheme?.kind === "numeric") return M(e.name, "mariadb");
|
|
2310
|
+
let t = q(e, "mariadb");
|
|
2311
|
+
if (t) return `${G(e.name)} ${mr(e)} ${t}`;
|
|
2312
|
+
let n = [G(e.name), mr(e)];
|
|
2313
|
+
if (e.type === "id" && n.push("PRIMARY KEY"), e.nullable || n.push("NOT NULL"), e.unique && e.type !== "id" && !jr(e) && n.push("UNIQUE"), e.hasDefault) {
|
|
2314
|
+
let t = wr(e.defaultValue, e);
|
|
2309
2315
|
t && n.push(t);
|
|
2310
2316
|
}
|
|
2311
2317
|
return n.join(" ");
|
|
2312
|
-
},
|
|
2318
|
+
}, Nr = (e) => e.columns.flatMap((t) => {
|
|
2313
2319
|
if (!t.references) return [];
|
|
2314
2320
|
let n = t.references.onDelete ? ` ON DELETE ${{
|
|
2315
2321
|
cascade: "CASCADE",
|
|
@@ -2317,27 +2323,27 @@ BEGIN
|
|
|
2317
2323
|
setNull: "SET NULL",
|
|
2318
2324
|
noAction: "NO ACTION"
|
|
2319
2325
|
}[t.references.onDelete]}` : "";
|
|
2320
|
-
return [` CONSTRAINT ${
|
|
2321
|
-
}),
|
|
2326
|
+
return [` CONSTRAINT ${G(`${e.table}_${t.name}_fkey`)} FOREIGN KEY (${G(t.name)}) REFERENCES ${G(t.references.table)} (${G(t.references.column)})${n}`];
|
|
2327
|
+
}), Pr = (e, t = "mariadb") => {
|
|
2322
2328
|
let n = new Map(e.columns.map((e) => [e.name, e])), r = (e) => {
|
|
2323
|
-
let t =
|
|
2324
|
-
return t === void 0 ?
|
|
2325
|
-
}, i = e.columns.map((e) => ` ${
|
|
2326
|
-
for (let n of e.columns) n.unique && n.type !== "id" &&
|
|
2327
|
-
for (let n of e.indexes) n.name !== `${e.table}_pkey` && s.push(`CREATE ${n.unique ? "UNIQUE " : ""}INDEX ${
|
|
2329
|
+
let t = Yr(n.get(e));
|
|
2330
|
+
return t === void 0 ? G(e) : `${G(e)}(${t})`;
|
|
2331
|
+
}, i = e.columns.map((e) => ` ${Mr(e)}`).join(",\n"), a = Nr(e), o = a.length > 0 ? `${i},\n${a.join(",\n")}` : i, s = [`CREATE TABLE IF NOT EXISTS ${G(e.table)} (\n${o}${Or(e, r)}\n)`];
|
|
2332
|
+
for (let n of e.columns) n.unique && n.type !== "id" && jr(n) && s.push(`CREATE UNIQUE INDEX ${hr(t)}${G(`${e.table}_${n.name}_key`)} ON ${G(e.table)} (${r(n.name)})`);
|
|
2333
|
+
for (let n of e.indexes) n.name !== `${e.table}_pkey` && s.push(`CREATE ${n.unique ? "UNIQUE " : ""}INDEX ${hr(t)}${G(n.name)} ON ${G(e.table)} (${n.columns.map(r).join(", ")})`);
|
|
2328
2334
|
return s;
|
|
2329
|
-
},
|
|
2335
|
+
}, Fr = {
|
|
2330
2336
|
cascade: "CASCADE",
|
|
2331
2337
|
restrict: "RESTRICT",
|
|
2332
2338
|
setNull: "SET NULL",
|
|
2333
2339
|
noAction: "NO ACTION"
|
|
2334
|
-
},
|
|
2340
|
+
}, Ir = {
|
|
2335
2341
|
cascade: "CASCADE",
|
|
2336
2342
|
restrict: "NO ACTION",
|
|
2337
2343
|
setNull: "SET NULL",
|
|
2338
2344
|
noAction: "NO ACTION"
|
|
2339
|
-
},
|
|
2340
|
-
let t =
|
|
2345
|
+
}, Lr = (e) => {
|
|
2346
|
+
let t = dr(e, "sqlite");
|
|
2341
2347
|
if (t !== void 0) return t;
|
|
2342
2348
|
switch (e.type) {
|
|
2343
2349
|
case "integer":
|
|
@@ -2348,60 +2354,60 @@ BEGIN
|
|
|
2348
2354
|
case "bytes": return "BLOB";
|
|
2349
2355
|
default: return "TEXT";
|
|
2350
2356
|
}
|
|
2351
|
-
},
|
|
2352
|
-
if (e.type === "id" && e.idScheme?.kind === "numeric") return
|
|
2353
|
-
let t =
|
|
2354
|
-
if (t) return `${
|
|
2355
|
-
let n = [
|
|
2357
|
+
}, Rr = (e, t) => e == null ? null : e === "now" ? `DEFAULT ${t}` : typeof e == "boolean" ? `DEFAULT ${+!!e}` : typeof e == "number" ? `DEFAULT ${e}` : typeof e == "string" ? /[()]|^'/.test(e) ? `DEFAULT ${e}` : `DEFAULT '${e.replace(/'/g, "''")}'` : typeof e == "object" ? j(e, "sqlite") : null, zr = (e) => {
|
|
2358
|
+
if (e.type === "id" && e.idScheme?.kind === "numeric") return M(e.name, "sqlite");
|
|
2359
|
+
let t = q(e, "sqlite");
|
|
2360
|
+
if (t) return `${W(e.name)} ${Lr(e)} ${t}`;
|
|
2361
|
+
let n = [W(e.name), Lr(e)];
|
|
2356
2362
|
if (e.type === "id" && n.push("PRIMARY KEY"), e.nullable || n.push("NOT NULL"), e.unique && e.type !== "id" && n.push("UNIQUE"), e.hasDefault) {
|
|
2357
|
-
let t =
|
|
2363
|
+
let t = Rr(e.defaultValue, "CURRENT_TIMESTAMP");
|
|
2358
2364
|
t && n.push(t);
|
|
2359
2365
|
}
|
|
2360
|
-
if (e.references && (n.push(`REFERENCES ${
|
|
2366
|
+
if (e.references && (n.push(`REFERENCES ${W(e.references.table)} (${W(e.references.column)})`), e.references.onDelete && n.push(`ON DELETE ${Fr[e.references.onDelete]}`)), e.oneOf && e.oneOf.length > 0) {
|
|
2361
2367
|
let t = e.oneOf.map((e) => `'${e.replace(/'/g, "''")}'`).join(", ");
|
|
2362
|
-
n.push(`CHECK (${
|
|
2368
|
+
n.push(`CHECK (${W(e.name)} IN (${t}))`);
|
|
2363
2369
|
}
|
|
2364
2370
|
return n.join(" ");
|
|
2365
|
-
},
|
|
2366
|
-
let t = e.columns.map((e) => ` ${
|
|
2367
|
-
for (let t of e.indexes) t.name !== `${e.table}_pkey` && n.push(`CREATE ${t.unique ? "UNIQUE " : ""}INDEX IF NOT EXISTS ${
|
|
2371
|
+
}, Br = (e) => {
|
|
2372
|
+
let t = e.columns.map((e) => ` ${zr(e)}`).join(",\n"), n = [`CREATE TABLE IF NOT EXISTS ${W(e.table)} (\n${t}${Or(e, W)}\n)`];
|
|
2373
|
+
for (let t of e.indexes) t.name !== `${e.table}_pkey` && n.push(`CREATE ${t.unique ? "UNIQUE " : ""}INDEX IF NOT EXISTS ${W(t.name)} ON ${W(e.table)} (${t.columns.map(W).join(", ")})`);
|
|
2368
2374
|
return n;
|
|
2369
2375
|
}, J = (e, t) => {
|
|
2370
2376
|
let n = t.find((t) => t.tableName === e);
|
|
2371
2377
|
if (!n) return [];
|
|
2372
|
-
let r =
|
|
2373
|
-
...
|
|
2378
|
+
let r = F([n]).tables[0], i = `${e}__voltro_rebuild`, a = r.columns.map((e) => W(e.name)).join(", "), o = [
|
|
2379
|
+
...Br({
|
|
2374
2380
|
kind: "create-table",
|
|
2375
2381
|
table: i,
|
|
2376
2382
|
columns: r.columns,
|
|
2377
2383
|
indexes: [],
|
|
2378
2384
|
...r.primaryKey ? { primaryKey: r.primaryKey } : {}
|
|
2379
2385
|
}),
|
|
2380
|
-
`INSERT INTO ${
|
|
2381
|
-
`DROP TABLE ${
|
|
2382
|
-
`ALTER TABLE ${
|
|
2386
|
+
`INSERT INTO ${W(i)} (${a}) SELECT ${a} FROM ${W(e)}`,
|
|
2387
|
+
`DROP TABLE ${W(e)}`,
|
|
2388
|
+
`ALTER TABLE ${W(i)} RENAME TO ${W(e)}`
|
|
2383
2389
|
];
|
|
2384
|
-
for (let t of r.indexes) t.name !== `${e}_pkey` && o.push(`CREATE ${t.unique ? "UNIQUE " : ""}INDEX IF NOT EXISTS ${
|
|
2390
|
+
for (let t of r.indexes) t.name !== `${e}_pkey` && o.push(`CREATE ${t.unique ? "UNIQUE " : ""}INDEX IF NOT EXISTS ${W(t.name)} ON ${W(e)} (${t.columns.map(W).join(", ")})`);
|
|
2385
2391
|
return o;
|
|
2386
|
-
},
|
|
2392
|
+
}, Vr = (e, t, n, r) => {
|
|
2387
2393
|
let i = r ?? e.nullable;
|
|
2388
|
-
return `ALTER TABLE ${Y(n)} ALTER COLUMN ${Y(t)} ${
|
|
2389
|
-
},
|
|
2394
|
+
return `ALTER TABLE ${Y(n)} ALTER COLUMN ${Y(t)} ${A(e, "mssql")} ${i ? "NULL" : "NOT NULL"};`;
|
|
2395
|
+
}, Hr = (e) => {
|
|
2390
2396
|
let t = `DECLARE @dc sysname; SELECT @dc = dc.name FROM sys.default_constraints dc JOIN sys.columns col ON col.object_id = dc.parent_object_id AND col.column_id = dc.parent_column_id WHERE dc.parent_object_id = OBJECT_ID(N'${e.table.replace(/'/g, "''")}') AND col.name = N'${e.column.replace(/'/g, "''")}'; IF @dc IS NOT NULL EXEC(N'ALTER TABLE ${Y(e.table)} DROP CONSTRAINT [' + @dc + ']');`;
|
|
2391
2397
|
if (!e.hasDefault) return t;
|
|
2392
|
-
let n =
|
|
2398
|
+
let n = Rr(e.defaultValue, "SYSUTCDATETIME()");
|
|
2393
2399
|
if (!n) return t;
|
|
2394
2400
|
let r = n.replace(/^DEFAULT\s+/i, "");
|
|
2395
2401
|
return `${t} ALTER TABLE ${Y(e.table)} ADD DEFAULT ${r} FOR ${Y(e.column)};`;
|
|
2396
|
-
}, Y = (e) => `[${e.replace(/]/g, "]]")}]`,
|
|
2397
|
-
let t =
|
|
2402
|
+
}, Y = (e) => `[${e.replace(/]/g, "]]")}]`, Ur = (e) => {
|
|
2403
|
+
let t = dr(e, "mssql");
|
|
2398
2404
|
if (t !== void 0) return t;
|
|
2399
2405
|
switch (e.type) {
|
|
2400
2406
|
case "id":
|
|
2401
2407
|
case "reference": return "NVARCHAR(64)";
|
|
2402
2408
|
case "integer": return "INT";
|
|
2403
2409
|
case "real": return "FLOAT";
|
|
2404
|
-
case "decimal": return
|
|
2410
|
+
case "decimal": return ur(e, "DECIMAL");
|
|
2405
2411
|
case "bigint": return "BIGINT";
|
|
2406
2412
|
case "boolean": return "BIT";
|
|
2407
2413
|
case "timestamp": return "DATETIME2(6)";
|
|
@@ -2409,44 +2415,44 @@ BEGIN
|
|
|
2409
2415
|
case "bytes": return "VARBINARY(MAX)";
|
|
2410
2416
|
default: return "NVARCHAR(MAX)";
|
|
2411
2417
|
}
|
|
2412
|
-
},
|
|
2413
|
-
if (e.type === "id" && e.idScheme?.kind === "numeric") return
|
|
2414
|
-
let n = e.type === "text" && t?.has(e.name) ? "NVARCHAR(450)" :
|
|
2418
|
+
}, Wr = (e, t) => {
|
|
2419
|
+
if (e.type === "id" && e.idScheme?.kind === "numeric") return M(e.name, "mssql");
|
|
2420
|
+
let n = e.type === "text" && t?.has(e.name) ? "NVARCHAR(450)" : Ur(e), r = q(e, "mssql");
|
|
2415
2421
|
if (r) return `${Y(e.name)} ${r}`;
|
|
2416
2422
|
let i = [Y(e.name), n];
|
|
2417
2423
|
if (e.type === "id" && i.push("PRIMARY KEY"), e.nullable || i.push("NOT NULL"), e.unique && e.type !== "id" && i.push("UNIQUE"), e.hasDefault) {
|
|
2418
|
-
let t =
|
|
2424
|
+
let t = Rr(e.defaultValue, "SYSUTCDATETIME()");
|
|
2419
2425
|
t && i.push(t);
|
|
2420
2426
|
}
|
|
2421
|
-
return e.references && (i.push(`REFERENCES ${Y(e.references.table)} (${Y(e.references.column)})`), e.references.onDelete && i.push(`ON DELETE ${
|
|
2422
|
-
},
|
|
2423
|
-
let t = (e) => e.replace(/'/g, "''"), n = new Set(e.indexes.flatMap((e) => e.columns)), r = e.columns.map((e) => ` ${
|
|
2427
|
+
return e.references && (i.push(`REFERENCES ${Y(e.references.table)} (${Y(e.references.column)})`), e.references.onDelete && i.push(`ON DELETE ${Ir[e.references.onDelete]}`)), i.join(" ");
|
|
2428
|
+
}, Gr = (e) => {
|
|
2429
|
+
let t = (e) => e.replace(/'/g, "''"), n = new Set(e.indexes.flatMap((e) => e.columns)), r = e.columns.map((e) => ` ${Wr(e, n)}`).join(",\n"), i = `CREATE TABLE ${Y(e.table)} (\n${r}${Or(e, Y)}\n)`, a = [`IF OBJECT_ID(N'${t(e.table)}', N'U') IS NULL EXEC(N'${t(i)}')`];
|
|
2424
2430
|
for (let n of e.indexes) {
|
|
2425
2431
|
if (n.name === `${e.table}_pkey`) continue;
|
|
2426
2432
|
let r = `CREATE ${n.unique ? "UNIQUE " : ""}INDEX ${Y(n.name)} ON ${Y(e.table)} (${n.columns.map(Y).join(", ")})`;
|
|
2427
2433
|
a.push(`IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = N'${t(n.name)}' AND object_id = OBJECT_ID(N'${t(e.table)}')) EXEC(N'${t(r)}')`);
|
|
2428
2434
|
}
|
|
2429
2435
|
return a;
|
|
2430
|
-
},
|
|
2431
|
-
let r = `${e.table}${
|
|
2436
|
+
}, Kr = (e) => `__dropped_${e.replace(/[-:T.Z]/g, "").slice(0, 14)}`, qr = (e, t) => `DROP TABLE IF EXISTS ${t(e.table)};`, Jr = (e, t, n) => {
|
|
2437
|
+
let r = `${e.table}${Kr(t)}`;
|
|
2432
2438
|
return `ALTER TABLE ${n(e.table)} RENAME TO ${n(r)};`;
|
|
2433
|
-
},
|
|
2434
|
-
if (e === void 0 || !
|
|
2439
|
+
}, Yr = (e) => {
|
|
2440
|
+
if (e === void 0 || !jr(e)) return;
|
|
2435
2441
|
let t = typeof e.maxLength == "number" && e.maxLength > 0 ? e.maxLength : void 0;
|
|
2436
|
-
return t === void 0 ?
|
|
2437
|
-
},
|
|
2438
|
-
let r =
|
|
2439
|
-
return r === void 0 ?
|
|
2440
|
-
},
|
|
2442
|
+
return t === void 0 ? Ar : Math.min(Ar, t);
|
|
2443
|
+
}, Xr = (e, t, n) => {
|
|
2444
|
+
let r = Yr(Sr(e, t, n));
|
|
2445
|
+
return r === void 0 ? G(n) : `${G(n)}(${r})`;
|
|
2446
|
+
}, Zr = (e) => e.startsWith("(") ? e : W(e), Qr = (e, t) => `CREATE ${e.index.unique ? "UNIQUE " : ""}INDEX ${t ? "CONCURRENTLY " : ""}IF NOT EXISTS ${W(e.index.name)} ON ${W(e.table)} (${e.index.columns.map(Zr).join(", ")});`, $r = (e, t, n = "mariadb") => `CREATE ${e.index.unique ? "UNIQUE " : ""}INDEX ${hr(n)}${G(e.index.name)} ON ${G(e.table)} (${e.index.columns.map((n) => Xr(t, e.table, n)).join(", ")});`, ei = (e) => `DROP INDEX IF EXISTS ${W(e.index)};`, ti = (e) => `DROP INDEX ${G(e.index)} ON ${G(e.table)};`, ni = (e) => `DROP INDEX IF EXISTS ${Y(e.index)} ON ${Y(e.table)};`, ri = (e, t) => `ALTER TABLE ${t(e.from)} RENAME TO ${t(e.to)};`, ii = (e) => {
|
|
2441
2447
|
let t = (e) => e.replace(/'/g, "''");
|
|
2442
2448
|
return `EXEC sp_rename N'${t(e.from)}', N'${t(e.to)}';`;
|
|
2443
|
-
},
|
|
2449
|
+
}, ai = (e) => `ALTER INDEX ${W(e.from)} RENAME TO ${W(e.to)};`, oi = (e) => `ALTER TABLE ${G(e.table)} RENAME INDEX ${G(e.from)} TO ${G(e.to)};`, si = (e) => {
|
|
2444
2450
|
let t = (e) => e.replace(/'/g, "''");
|
|
2445
2451
|
return `EXEC sp_rename N'${t(e.table)}.${t(e.from)}', N'${t(e.to)}', N'INDEX';`;
|
|
2446
|
-
},
|
|
2452
|
+
}, ci = (e) => {
|
|
2447
2453
|
let t = (e) => e.replace(/'/g, "''"), n = `CREATE ${e.index.unique ? "UNIQUE " : ""}INDEX ${Y(e.index.name)} ON ${Y(e.table)} (${e.index.columns.map(Y).join(", ")})`;
|
|
2448
2454
|
return `IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = N'${t(e.index.name)}' AND object_id = OBJECT_ID(N'${t(e.table)}')) EXEC(N'${t(n)}');`;
|
|
2449
|
-
},
|
|
2455
|
+
}, li = (e, t, n) => {
|
|
2450
2456
|
let r = n.find((t) => t.tableName === e);
|
|
2451
2457
|
if (!r) return [];
|
|
2452
2458
|
let i = [];
|
|
@@ -2455,13 +2461,13 @@ BEGIN
|
|
|
2455
2461
|
t && t.type === "text" && !t.generatedAs && i.push(`ALTER TABLE ${Y(e)} ALTER COLUMN ${Y(n)} NVARCHAR(450) ${t.nullable ? "NULL" : "NOT NULL"};`);
|
|
2456
2462
|
}
|
|
2457
2463
|
return i;
|
|
2458
|
-
},
|
|
2459
|
-
let t = e.fields.map((e) =>
|
|
2460
|
-
return `ALTER TABLE ${
|
|
2461
|
-
},
|
|
2462
|
-
let n = e.fields.map((n) =>
|
|
2463
|
-
return `ALTER TABLE ${
|
|
2464
|
-
},
|
|
2464
|
+
}, ui = (e) => `ALTER TABLE ${W(e.table)} ADD CONSTRAINT ${W(`${e.table}_${e.column}_key`)} UNIQUE (${W(e.column)});`, di = (e, t) => `ALTER TABLE ${G(e.table)} ADD CONSTRAINT ${G(`${e.table}_${e.column}_key`)} UNIQUE (${Xr(t, e.table, e.column)});`, fi = (e) => {
|
|
2465
|
+
let t = e.fields.map((e) => W(e)).join(", ");
|
|
2466
|
+
return `ALTER TABLE ${W(e.table)} ADD CONSTRAINT ${W(e.name)} UNIQUE (${t});`;
|
|
2467
|
+
}, pi = (e, t) => {
|
|
2468
|
+
let n = e.fields.map((n) => Xr(t, e.table, n)).join(", ");
|
|
2469
|
+
return `ALTER TABLE ${G(e.table)} ADD CONSTRAINT ${G(e.name)} UNIQUE (${n});`;
|
|
2470
|
+
}, mi = (e) => `ALTER TABLE ${W(e.table)} DROP CONSTRAINT IF EXISTS ${W(e.name)};`, hi = (e) => `ALTER TABLE ${G(e.table)} DROP INDEX ${G(e.name)};`, gi = (e) => `ALTER TABLE ${W(e.table)} DROP CONSTRAINT IF EXISTS ${W(`${e.table}_${e.column}_key`)};`, _i = (e) => `ALTER TABLE ${G(e.table)} DROP INDEX ${G(`${e.table}_${e.column}_key`)};`, vi = (e, t) => {
|
|
2465
2471
|
let n = [], r = t(e.table), i = t(e.column), a = t(e.targetTable), o = t(e.targetColumn);
|
|
2466
2472
|
if (e.orphanPolicy) {
|
|
2467
2473
|
let t = `${i} IS NOT NULL AND ${i} NOT IN (SELECT ${o} FROM ${a})`;
|
|
@@ -2479,11 +2485,34 @@ BEGIN
|
|
|
2479
2485
|
setNull: "SET NULL",
|
|
2480
2486
|
noAction: "NO ACTION"
|
|
2481
2487
|
}[e.onDelete]}`), n.push(s.join(" ") + ";"), n;
|
|
2482
|
-
},
|
|
2488
|
+
}, yi = (e) => `ALTER TABLE ${W(e.table)} DROP CONSTRAINT IF EXISTS ${W(`${e.table}_${e.column}_fkey`)};`, bi = (e) => `ALTER TABLE ${G(e.table)} DROP FOREIGN KEY ${G(`${e.table}_${e.column}_fkey`)};`, xi = (e, t) => {
|
|
2483
2489
|
let n = e.values.map((e) => `'${e.replace(/'/g, "''")}'`).join(", ");
|
|
2484
2490
|
return `ALTER TABLE ${t(e.table)} ADD CONSTRAINT ${t(`${e.table}_${e.column}_check`)} CHECK (${t(e.column)} IN (${n}));`;
|
|
2485
|
-
},
|
|
2486
|
-
let
|
|
2491
|
+
}, Si = (e) => `ALTER TABLE ${W(e.table)} DROP CONSTRAINT IF EXISTS ${W(`${e.table}_${e.column}_check`)};`, Ci = (e, t) => x.gen(function* () {
|
|
2492
|
+
let n = yield* e`
|
|
2493
|
+
SELECT cc.constraint_name AS n, cc.check_clause AS c
|
|
2494
|
+
FROM information_schema.check_constraints cc
|
|
2495
|
+
WHERE cc.constraint_schema = DATABASE() AND cc.table_name = ${t.table}`.pipe(x.orElse(() => e`
|
|
2496
|
+
SELECT cc.constraint_name AS n, cc.check_clause AS c
|
|
2497
|
+
FROM information_schema.check_constraints cc
|
|
2498
|
+
JOIN information_schema.table_constraints tc
|
|
2499
|
+
ON tc.constraint_schema = cc.constraint_schema
|
|
2500
|
+
AND tc.constraint_name = cc.constraint_name
|
|
2501
|
+
WHERE tc.table_schema = DATABASE() AND tc.table_name = ${t.table}`), x.orElseSucceed(() => []));
|
|
2502
|
+
for (let e of n) {
|
|
2503
|
+
let n = String(e.n ?? "");
|
|
2504
|
+
if (n !== "" && Pn(String(e.c ?? ""))?.column === t.column) return n;
|
|
2505
|
+
}
|
|
2506
|
+
}), wi = (e, t, n) => x.gen(function* () {
|
|
2507
|
+
let r = yield* Ci(e, t);
|
|
2508
|
+
r !== void 0 && (yield* X(e, `ALTER TABLE ${G(t.table)} DROP CONSTRAINT ${G(r)};`, t.kind, [lr]));
|
|
2509
|
+
let i = yield* Ci(e, t);
|
|
2510
|
+
if (i === void 0) return;
|
|
2511
|
+
let a = K(n, t.table, t.column);
|
|
2512
|
+
if (!a) return yield* x.die(/* @__PURE__ */ Error(`applier: cannot drop the CHECK on '${t.table}.${t.column}' — it is column-level (catalog name '${i}'), which this family removes only by redefining the column, and the declared column is not available to redefine it from.`));
|
|
2513
|
+
yield* X(e, `ALTER TABLE ${G(t.table)} MODIFY COLUMN ${Cr(a, t.column)};`, t.kind);
|
|
2514
|
+
}), Ti = (e, t, n, r) => {
|
|
2515
|
+
let i = e.column, a = r === "mariadb", o = a ? G : r === "mssql" ? Y : W, s = a ? mr(i) : r === "mssql" ? Ur(i) : r === "sqlite" ? Lr(i) : fr(i), c = r === "mssql" ? "ADD" : "ADD COLUMN", l = (e) => a ? wr(e, i) : r === "mssql" ? Rr(e, "SYSUTCDATETIME()") : r === "sqlite" ? Rr(e, "CURRENT_TIMESTAMP") : Er(e, i), u = q(i, r);
|
|
2487
2516
|
if (u) {
|
|
2488
2517
|
let t = r === "mssql" ? `${o(i.name)} ${u}` : `${o(i.name)} ${s} ${u}`;
|
|
2489
2518
|
return {
|
|
@@ -2511,7 +2540,7 @@ BEGIN
|
|
|
2511
2540
|
post: f ? [f] : []
|
|
2512
2541
|
};
|
|
2513
2542
|
return d?.sql && (p.backfillKind = "sql", p.backfillSql = d.sql), d?.js && (p.backfillKind = "js", p.backfillJs = d.js), d?.batchSize !== void 0 && (p.batchSize = d.batchSize), d?.sleepMs !== void 0 && (p.sleepMs = d.sleepMs), p;
|
|
2514
|
-
},
|
|
2543
|
+
}, Ei = (e) => {
|
|
2515
2544
|
let t = new Map(e.map((e) => [e.tableName, e]));
|
|
2516
2545
|
return (e, n) => {
|
|
2517
2546
|
let r = t.get(e);
|
|
@@ -2531,47 +2560,47 @@ BEGIN
|
|
|
2531
2560
|
...o
|
|
2532
2561
|
};
|
|
2533
2562
|
};
|
|
2534
|
-
}, X = (e, t, n, r = []) => e.unsafe(t).pipe(x.catchIf((e) =>
|
|
2563
|
+
}, X = (e, t, n, r = []) => e.unsafe(t).pipe(x.catchIf((e) => ar(e, r), () => x.void), x.tapError((e) => x.sync(() => {
|
|
2535
2564
|
process.stderr.write(ae(`applier: statement failed (op=${n})`, t, e, 400));
|
|
2536
2565
|
})), x.mapError((e) => {
|
|
2537
2566
|
let r = ae(`applier: statement failed (op=${n})`, t, e, 400).trim();
|
|
2538
2567
|
return Object.assign(e, { message: r });
|
|
2539
|
-
}), x.map(() => void 0)), Z = (e, t, n) => x.forEach(t, (t) => X(e, t, n), { discard: !0 }), Q = (e, t) => e.literal(`LIMIT ${Math.max(1, Math.floor(Number.isFinite(t) ? t : 1))}`), $ = (e, t, r, i) => e.unsafe(`SELECT ${i === void 0 ? "*" : n(i, t)} FROM ${n(r, t)} WHERE 1=0`).pipe(x.as(!0), x.catchAll(() => x.succeed(!1))),
|
|
2540
|
-
let n =
|
|
2568
|
+
}), x.map(() => void 0)), Z = (e, t, n) => x.forEach(t, (t) => X(e, t, n), { discard: !0 }), Q = (e, t) => e.literal(`LIMIT ${Math.max(1, Math.floor(Number.isFinite(t) ? t : 1))}`), $ = (e, t, r, i) => e.unsafe(`SELECT ${i === void 0 ? "*" : n(i, t)} FROM ${n(r, t)} WHERE 1=0`).pipe(x.as(!0), x.catchAll(() => x.succeed(!1))), Di = (e, t) => x.gen(function* () {
|
|
2569
|
+
let n = F([Le], t).tables[0];
|
|
2541
2570
|
if (!n) return yield* x.die(/* @__PURE__ */ Error("migration applier: the resume-ledger table descriptor produced no snapshot. This is a framework bug."));
|
|
2542
2571
|
let r = {
|
|
2543
2572
|
kind: "create-table",
|
|
2544
|
-
table:
|
|
2573
|
+
table: D,
|
|
2545
2574
|
columns: n.columns,
|
|
2546
2575
|
indexes: []
|
|
2547
2576
|
}, i = yield* e.onDialectOrElse({
|
|
2548
|
-
mysql: () =>
|
|
2549
|
-
mssql: () => x.succeed(
|
|
2550
|
-
sqlite: () => x.succeed(
|
|
2551
|
-
orElse: () => x.succeed(
|
|
2577
|
+
mysql: () => H(e).pipe(x.map((e) => Pr(r, e))),
|
|
2578
|
+
mssql: () => x.succeed(Gr(r)),
|
|
2579
|
+
sqlite: () => x.succeed(Br(r)),
|
|
2580
|
+
orElse: () => x.succeed(kr(r))
|
|
2552
2581
|
});
|
|
2553
2582
|
yield* x.forEach(i, (t) => X(e, t, "resume-ledger-bootstrap"), { discard: !0 });
|
|
2554
|
-
}),
|
|
2583
|
+
}), Oi = (e) => e`
|
|
2555
2584
|
SELECT ${e("runId")}, ${e("planFingerprint")}, ${e("opIndex")},
|
|
2556
2585
|
${e("status")}, ${e("payload")}
|
|
2557
|
-
FROM ${e(
|
|
2558
|
-
`,
|
|
2559
|
-
let i = yield*
|
|
2586
|
+
FROM ${e(D)}
|
|
2587
|
+
`, ki = (e, t, n, r) => x.gen(function* () {
|
|
2588
|
+
let i = yield* U(e, (/* @__PURE__ */ new Date()).toISOString());
|
|
2560
2589
|
yield* x.forEach(r, ({ index: r, planned: a }) => e`
|
|
2561
|
-
INSERT INTO ${e(
|
|
2590
|
+
INSERT INTO ${e(D)}
|
|
2562
2591
|
(${e("id")}, ${e("runId")}, ${e("planFingerprint")}, ${e("opIndex")},
|
|
2563
2592
|
${e("opKind")}, ${e("opTarget")}, ${e("status")}, ${e("payload")},
|
|
2564
2593
|
${e("createdAt")})
|
|
2565
2594
|
VALUES
|
|
2566
2595
|
(${`mop_${t}_${r}`}, ${t}, ${n}, ${r},
|
|
2567
|
-
${a.op.kind}, ${
|
|
2596
|
+
${a.op.kind}, ${ze(a.op)}, ${"pending"},
|
|
2568
2597
|
${JSON.stringify(a)}, ${i})
|
|
2569
2598
|
`, { discard: !0 });
|
|
2570
|
-
}),
|
|
2571
|
-
let a = yield*
|
|
2599
|
+
}), Ai = (e, t, n, r, i) => x.gen(function* () {
|
|
2600
|
+
let a = yield* U(e, (/* @__PURE__ */ new Date()).toISOString());
|
|
2572
2601
|
if (r === "applied") {
|
|
2573
2602
|
yield* e`
|
|
2574
|
-
UPDATE ${e(
|
|
2603
|
+
UPDATE ${e(D)}
|
|
2575
2604
|
SET ${e("status")} = ${r}, ${e("appliedAt")} = ${a},
|
|
2576
2605
|
${e("durationMs")} = ${i ?? null}
|
|
2577
2606
|
WHERE ${e("runId")} = ${t} AND ${e("opIndex")} = ${n}
|
|
@@ -2579,145 +2608,145 @@ BEGIN
|
|
|
2579
2608
|
return;
|
|
2580
2609
|
}
|
|
2581
2610
|
yield* e`
|
|
2582
|
-
UPDATE ${e(
|
|
2611
|
+
UPDATE ${e(D)}
|
|
2583
2612
|
SET ${e("status")} = ${r}, ${e("startedAt")} = ${a}
|
|
2584
2613
|
WHERE ${e("runId")} = ${t} AND ${e("opIndex")} = ${n}
|
|
2585
2614
|
`;
|
|
2586
|
-
}),
|
|
2587
|
-
let i = yield*
|
|
2615
|
+
}), ji = (e, t, n, r) => x.gen(function* () {
|
|
2616
|
+
let i = yield* U(e, (/* @__PURE__ */ new Date()).toISOString());
|
|
2588
2617
|
r.length > 0 && (yield* e`
|
|
2589
|
-
UPDATE ${e(
|
|
2618
|
+
UPDATE ${e(D)}
|
|
2590
2619
|
SET ${e("status")} = ${"applied"}, ${e("appliedAt")} = ${i}
|
|
2591
2620
|
WHERE ${e("runId")} = ${t} AND ${e("opIndex")} IN ${e.in(r)}
|
|
2592
2621
|
`), n.length > 0 && (yield* e`
|
|
2593
|
-
UPDATE ${e(
|
|
2622
|
+
UPDATE ${e(D)}
|
|
2594
2623
|
SET ${e("status")} = ${"pending"}
|
|
2595
2624
|
WHERE ${e("runId")} = ${t} AND ${e("opIndex")} IN ${e.in(n)}
|
|
2596
2625
|
`);
|
|
2597
|
-
}),
|
|
2598
|
-
if (
|
|
2626
|
+
}), Mi = (e, t) => t === void 0 ? e`DELETE FROM ${e(D)}`.pipe(x.asVoid) : e`DELETE FROM ${e(D)} WHERE ${e("runId")} = ${t}`.pipe(x.asVoid), Ni = (e, t, r) => x.gen(function* () {
|
|
2627
|
+
if (qe(r.op, r.classification, t) !== "artefact-repair") return "clean";
|
|
2599
2628
|
let i = r.op, a = (e) => n(e, t);
|
|
2600
2629
|
if (t === "sqlite" || t === "turso") {
|
|
2601
2630
|
if (!("table" in i)) return "clean";
|
|
2602
|
-
let n = `${i.table}${
|
|
2631
|
+
let n = `${i.table}${He}`;
|
|
2603
2632
|
return (yield* $(e, t, n)) ? ((yield* $(e, t, i.table)) ? yield* X(e, `DROP TABLE ${a(n)}`, "resume-repair") : yield* X(e, `ALTER TABLE ${a(n)} RENAME TO ${a(i.table)}`, "resume-repair"), yield* x.logWarning(`migration resume: reconciled an interrupted sqlite table rebuild on '${i.table}' — replaying the operation`).pipe(x.annotateLogs({ scope: "voltro:migrate" })), "outstanding") : "clean";
|
|
2604
2633
|
}
|
|
2605
2634
|
if (i.kind !== "alter-column-type") return "clean";
|
|
2606
|
-
let o = `${i.column}${
|
|
2635
|
+
let o = `${i.column}${Ue}`, s = `${i.column}${We}`, c = yield* $(e, t, i.table, i.column), l = yield* $(e, t, i.table, o), u = yield* $(e, t, i.table, s), d = (e) => x.logWarning(`migration resume: ${e}`).pipe(x.annotateLogs({ scope: "voltro:migrate" }));
|
|
2607
2636
|
return !l && !u ? "clean" : c && l && !u ? (yield* X(e, `ALTER TABLE ${a(i.table)} DROP COLUMN ${a(o)}`, "resume-repair"), yield* d(`dropped a half-populated shadow column '${i.table}.${o}' — replaying the type change`), "outstanding") : !c && l && u ? (yield* X(e, `ALTER TABLE ${a(i.table)} RENAME COLUMN ${a(o)} TO ${a(i.column)}`, "resume-repair"), yield* X(e, `ALTER TABLE ${a(i.table)} DROP COLUMN ${a(s)}`, "resume-repair"), yield* d(`completed an interrupted shadow swap on '${i.table}.${i.column}'`), "applied") : c && !l && u ? (yield* X(e, `ALTER TABLE ${a(i.table)} DROP COLUMN ${a(s)}`, "resume-repair"), yield* d(`dropped the leftover pre-swap column '${i.table}.${s}'`), "applied") : yield* x.die(/* @__PURE__ */ Error(`applyPlan: an interrupted online type change on '${i.table}.${i.column}' left a shadow-swap state this resume cannot classify (column=${c}, ${o}=${l}, ${s}=${u}).\nNothing was changed. Inspect those three columns and reconcile them by hand — the data is in whichever of them is populated — then re-run the migration.`));
|
|
2608
|
-
}),
|
|
2609
|
-
let i = process.hrtime.bigint(), a =
|
|
2637
|
+
}), Pi = (e, t, n, r = "fresh") => x.gen(function* () {
|
|
2638
|
+
let i = process.hrtime.bigint(), a = Ei(n.declared), o = t.op;
|
|
2610
2639
|
switch (o.kind) {
|
|
2611
2640
|
case "create-table": {
|
|
2612
2641
|
let t = yield* e.onDialectOrElse({
|
|
2613
|
-
mysql: () =>
|
|
2614
|
-
mssql: () => x.succeed(
|
|
2615
|
-
sqlite: () => x.succeed(
|
|
2616
|
-
orElse: () => x.succeed(
|
|
2642
|
+
mysql: () => H(e).pipe(x.map((e) => Pr(o, e))),
|
|
2643
|
+
mssql: () => x.succeed(Gr(o)),
|
|
2644
|
+
sqlite: () => x.succeed(Br(o)),
|
|
2645
|
+
orElse: () => x.succeed(kr(o))
|
|
2617
2646
|
}), n = yield* e.onDialectOrElse({
|
|
2618
|
-
mysql: () => x.succeed([
|
|
2647
|
+
mysql: () => x.succeed([or]),
|
|
2619
2648
|
orElse: () => x.succeed([])
|
|
2620
2649
|
});
|
|
2621
2650
|
for (let r of t) yield* X(e, r, o.kind, n);
|
|
2622
2651
|
break;
|
|
2623
2652
|
}
|
|
2624
2653
|
case "drop-table": {
|
|
2625
|
-
let t = process.env.VOLTRO_SOFT_DROP === "1", n = (/* @__PURE__ */ new Date()).toISOString(), r = (e) => t ?
|
|
2654
|
+
let t = process.env.VOLTRO_SOFT_DROP === "1", n = (/* @__PURE__ */ new Date()).toISOString(), r = (e) => t ? Jr(o, n, e) : qr(o, e);
|
|
2626
2655
|
yield* e.onDialectOrElse({
|
|
2627
|
-
mysql: () => X(e, r(
|
|
2628
|
-
orElse: () => X(e, r(
|
|
2656
|
+
mysql: () => X(e, r(G), o.kind),
|
|
2657
|
+
orElse: () => X(e, r(W), o.kind)
|
|
2629
2658
|
});
|
|
2630
2659
|
break;
|
|
2631
2660
|
}
|
|
2632
2661
|
case "drop-column": {
|
|
2633
2662
|
let t = process.env.VOLTRO_SOFT_DROP === "1", n = (/* @__PURE__ */ new Date()).toISOString();
|
|
2634
2663
|
yield* e.onDialectOrElse({
|
|
2635
|
-
mysql: () =>
|
|
2636
|
-
sqlite: () => X(e, t ?
|
|
2637
|
-
orElse: () => X(e, t ?
|
|
2664
|
+
mysql: () => H(e).pipe(x.flatMap((r) => X(e, t ? yr(o, n, G) : _r(o, r), o.kind, t ? [] : [sr]))),
|
|
2665
|
+
sqlite: () => X(e, t ? yr(o, n, W) : gr(o, W, !1), o.kind, t ? [] : [cr]),
|
|
2666
|
+
orElse: () => X(e, t ? yr(o, n, W) : gr(o, W), o.kind)
|
|
2638
2667
|
});
|
|
2639
2668
|
break;
|
|
2640
2669
|
}
|
|
2641
2670
|
case "rename-column":
|
|
2642
2671
|
yield* e.onDialectOrElse({
|
|
2643
|
-
mysql: () => X(e,
|
|
2672
|
+
mysql: () => X(e, vr(o, G), o.kind),
|
|
2644
2673
|
mssql: () => X(e, `EXEC sp_rename N'${o.table.replace(/'/g, "''")}.${o.from.replace(/'/g, "''")}', N'${o.to.replace(/'/g, "''")}', 'COLUMN';`, o.kind),
|
|
2645
|
-
orElse: () => X(e,
|
|
2674
|
+
orElse: () => X(e, vr(o, W), o.kind)
|
|
2646
2675
|
});
|
|
2647
2676
|
break;
|
|
2648
2677
|
case "add-index":
|
|
2649
2678
|
yield* e.onDialectOrElse({
|
|
2650
|
-
mysql: () =>
|
|
2651
|
-
mssql: () => Z(e, [...
|
|
2652
|
-
orElse: () => X(e,
|
|
2679
|
+
mysql: () => H(e).pipe(x.flatMap((t) => X(e, $r(o, n.declared, t), o.kind, [or]))),
|
|
2680
|
+
mssql: () => Z(e, [...li(o.table, o.index.columns, n.declared), ci(o)], o.kind),
|
|
2681
|
+
orElse: () => X(e, Qr(o, t.classification === "online-required"), o.kind)
|
|
2653
2682
|
});
|
|
2654
2683
|
break;
|
|
2655
2684
|
case "drop-index":
|
|
2656
2685
|
yield* e.onDialectOrElse({
|
|
2657
|
-
mysql: () => X(e,
|
|
2658
|
-
mssql: () => X(e,
|
|
2659
|
-
orElse: () => X(e,
|
|
2686
|
+
mysql: () => X(e, ti(o), o.kind),
|
|
2687
|
+
mssql: () => X(e, ni(o), o.kind),
|
|
2688
|
+
orElse: () => X(e, ei(o), o.kind)
|
|
2660
2689
|
});
|
|
2661
2690
|
break;
|
|
2662
2691
|
case "rename-table":
|
|
2663
2692
|
yield* e.onDialectOrElse({
|
|
2664
|
-
mysql: () => X(e,
|
|
2665
|
-
mssql: () => X(e,
|
|
2666
|
-
orElse: () => X(e,
|
|
2693
|
+
mysql: () => X(e, ri(o, G), o.kind),
|
|
2694
|
+
mssql: () => X(e, ii(o), o.kind),
|
|
2695
|
+
orElse: () => X(e, ri(o, W), o.kind)
|
|
2667
2696
|
});
|
|
2668
2697
|
break;
|
|
2669
2698
|
case "rename-index":
|
|
2670
2699
|
yield* e.onDialectOrElse({
|
|
2671
|
-
mysql: () => X(e,
|
|
2672
|
-
mssql: () => X(e,
|
|
2673
|
-
orElse: () => X(e,
|
|
2700
|
+
mysql: () => X(e, oi(o), o.kind),
|
|
2701
|
+
mssql: () => X(e, si(o), o.kind),
|
|
2702
|
+
orElse: () => X(e, ai(o), o.kind)
|
|
2674
2703
|
});
|
|
2675
2704
|
break;
|
|
2676
2705
|
case "add-unique":
|
|
2677
2706
|
yield* e.onDialectOrElse({
|
|
2678
|
-
mysql: () => X(e,
|
|
2707
|
+
mysql: () => X(e, di(o, n.declared), o.kind),
|
|
2679
2708
|
sqlite: () => Z(e, J(o.table, n.declared), o.kind),
|
|
2680
|
-
mssql: () => Z(e, [...
|
|
2681
|
-
orElse: () => X(e,
|
|
2709
|
+
mssql: () => Z(e, [...li(o.table, [o.column], n.declared), ui(o)], o.kind),
|
|
2710
|
+
orElse: () => X(e, ui(o), o.kind)
|
|
2682
2711
|
});
|
|
2683
2712
|
break;
|
|
2684
2713
|
case "drop-unique":
|
|
2685
2714
|
yield* e.onDialectOrElse({
|
|
2686
|
-
mysql: () => X(e,
|
|
2715
|
+
mysql: () => X(e, _i(o), o.kind),
|
|
2687
2716
|
sqlite: () => Z(e, J(o.table, n.declared), o.kind),
|
|
2688
|
-
orElse: () => X(e,
|
|
2717
|
+
orElse: () => X(e, gi(o), o.kind)
|
|
2689
2718
|
});
|
|
2690
2719
|
break;
|
|
2691
2720
|
case "add-unique-composite":
|
|
2692
2721
|
yield* e.onDialectOrElse({
|
|
2693
|
-
mysql: () => X(e,
|
|
2722
|
+
mysql: () => X(e, pi(o, n.declared), o.kind),
|
|
2694
2723
|
sqlite: () => Z(e, J(o.table, n.declared), o.kind),
|
|
2695
|
-
mssql: () => Z(e, [...
|
|
2696
|
-
orElse: () => X(e,
|
|
2724
|
+
mssql: () => Z(e, [...li(o.table, o.fields, n.declared), fi(o)], o.kind),
|
|
2725
|
+
orElse: () => X(e, fi(o), o.kind)
|
|
2697
2726
|
});
|
|
2698
2727
|
break;
|
|
2699
2728
|
case "drop-unique-composite":
|
|
2700
2729
|
yield* e.onDialectOrElse({
|
|
2701
|
-
mysql: () => X(e,
|
|
2730
|
+
mysql: () => X(e, hi(o), o.kind),
|
|
2702
2731
|
sqlite: () => Z(e, J(o.table, n.declared), o.kind),
|
|
2703
|
-
orElse: () => X(e,
|
|
2732
|
+
orElse: () => X(e, mi(o), o.kind)
|
|
2704
2733
|
});
|
|
2705
2734
|
break;
|
|
2706
2735
|
case "add-foreign-key":
|
|
2707
2736
|
yield* e.onDialectOrElse({
|
|
2708
|
-
mysql: () => Z(e,
|
|
2737
|
+
mysql: () => Z(e, vi(o, G), o.kind),
|
|
2709
2738
|
sqlite: () => Z(e, J(o.table, n.declared), o.kind),
|
|
2710
|
-
orElse: () => Z(e,
|
|
2739
|
+
orElse: () => Z(e, vi(o, W), o.kind)
|
|
2711
2740
|
});
|
|
2712
2741
|
break;
|
|
2713
2742
|
case "add-column": {
|
|
2714
|
-
let n =
|
|
2743
|
+
let n = Ti(o, t, a, yield* e.onDialectOrElse({
|
|
2715
2744
|
mysql: () => x.succeed("mariadb"),
|
|
2716
2745
|
mssql: () => x.succeed("mssql"),
|
|
2717
2746
|
sqlite: () => x.succeed("sqlite"),
|
|
2718
2747
|
orElse: () => x.succeed("postgres")
|
|
2719
2748
|
}));
|
|
2720
|
-
if (!(r === "resume" && (yield* $(e,
|
|
2749
|
+
if (!(r === "resume" && (yield* $(e, Pe(e), o.table, o.column.name)))) for (let t of n.pre) yield* X(e, t, o.kind);
|
|
2721
2750
|
if (n.backfillKind === "sql" && n.backfillSql) {
|
|
2722
2751
|
if (t.classification !== "online-required" && n.batchSize === void 0) yield* e`UPDATE ${e(o.table)} SET ${e(o.column.name)} = ${n.backfillSql}`;
|
|
2723
2752
|
else {
|
|
@@ -2757,41 +2786,41 @@ BEGIN
|
|
|
2757
2786
|
case "alter-column-nullability":
|
|
2758
2787
|
yield* e.onDialectOrElse({
|
|
2759
2788
|
mysql: () => {
|
|
2760
|
-
let t =
|
|
2761
|
-
return t ? X(e, `ALTER TABLE ${
|
|
2789
|
+
let t = K(n.declared, o.table, o.column);
|
|
2790
|
+
return t ? X(e, `ALTER TABLE ${G(o.table)} MODIFY COLUMN ${Cr(t, o.column, o.toNullable)};`, o.kind) : x.die(/* @__PURE__ */ Error(`alter-column-nullability on mariadb needs the declared column '${o.table}.${o.column}' (to render MODIFY COLUMN); it was not in ctx.declared.`));
|
|
2762
2791
|
},
|
|
2763
2792
|
mssql: () => {
|
|
2764
|
-
let t =
|
|
2765
|
-
return t ? X(e,
|
|
2793
|
+
let t = K(n.declared, o.table, o.column);
|
|
2794
|
+
return t ? X(e, Vr(t, o.column, o.table, o.toNullable), o.kind) : x.die(/* @__PURE__ */ Error(`alter-column-nullability on mssql needs the declared column '${o.table}.${o.column}'.`));
|
|
2766
2795
|
},
|
|
2767
2796
|
sqlite: () => Z(e, J(o.table, n.declared), o.kind),
|
|
2768
|
-
orElse: () => X(e, `ALTER TABLE ${
|
|
2797
|
+
orElse: () => X(e, `ALTER TABLE ${W(o.table)} ALTER COLUMN ${W(o.column)} ${o.toNullable ? "DROP NOT NULL" : "SET NOT NULL"};`, o.kind)
|
|
2769
2798
|
});
|
|
2770
2799
|
break;
|
|
2771
2800
|
case "alter-column-default": {
|
|
2772
|
-
let t =
|
|
2801
|
+
let t = Sr(n.declared, o.table, o.column);
|
|
2773
2802
|
yield* e.onDialectOrElse({
|
|
2774
|
-
mysql: () => X(e,
|
|
2775
|
-
mssql: () => X(e,
|
|
2803
|
+
mysql: () => X(e, br(o, G, (e) => wr(e, t)), o.kind),
|
|
2804
|
+
mssql: () => X(e, Hr(o), o.kind),
|
|
2776
2805
|
sqlite: () => Z(e, J(o.table, n.declared), o.kind),
|
|
2777
|
-
orElse: () => X(e,
|
|
2806
|
+
orElse: () => X(e, br(o, W, (e) => Er(e, t)), o.kind)
|
|
2778
2807
|
});
|
|
2779
2808
|
break;
|
|
2780
2809
|
}
|
|
2781
2810
|
case "alter-column-type": {
|
|
2782
|
-
let r =
|
|
2811
|
+
let r = fr(Sr(n.declared, o.table, o.column) ?? { type: o.to }), i = o.using ? ` USING ${o.using}` : "";
|
|
2783
2812
|
if (t.classification !== "online-required") {
|
|
2784
2813
|
yield* e.onDialectOrElse({
|
|
2785
2814
|
mysql: () => {
|
|
2786
|
-
let t =
|
|
2787
|
-
return t ? X(e, `ALTER TABLE ${
|
|
2815
|
+
let t = K(n.declared, o.table, o.column);
|
|
2816
|
+
return t ? X(e, `ALTER TABLE ${G(o.table)} MODIFY COLUMN ${Cr(t, o.column)};`, o.kind) : x.die(/* @__PURE__ */ Error(`alter-column-type on mariadb needs the declared column '${o.table}.${o.column}' (to render MODIFY COLUMN); it was not in ctx.declared.`));
|
|
2788
2817
|
},
|
|
2789
2818
|
mssql: () => {
|
|
2790
|
-
let t =
|
|
2791
|
-
return t ? X(e,
|
|
2819
|
+
let t = K(n.declared, o.table, o.column);
|
|
2820
|
+
return t ? X(e, Vr(t, o.column, o.table), o.kind) : x.die(/* @__PURE__ */ Error(`alter-column-type on mssql needs the declared column '${o.table}.${o.column}'.`));
|
|
2792
2821
|
},
|
|
2793
2822
|
sqlite: () => Z(e, J(o.table, n.declared), o.kind),
|
|
2794
|
-
orElse: () => X(e, `ALTER TABLE ${
|
|
2823
|
+
orElse: () => X(e, `ALTER TABLE ${W(o.table)} ALTER COLUMN ${W(o.column)} TYPE ${r}${i};`, o.kind)
|
|
2795
2824
|
});
|
|
2796
2825
|
break;
|
|
2797
2826
|
}
|
|
@@ -2800,34 +2829,34 @@ BEGIN
|
|
|
2800
2829
|
orElse: () => x.void
|
|
2801
2830
|
});
|
|
2802
2831
|
let a = `${o.column}__shadow`, s = `${o.column}__old`;
|
|
2803
|
-
yield* e.unsafe(`ALTER TABLE ${
|
|
2804
|
-
let c = o.using ??
|
|
2832
|
+
yield* e.unsafe(`ALTER TABLE ${W(o.table)} ADD COLUMN ${W(a)} ${r}`);
|
|
2833
|
+
let c = o.using ?? W(o.column), l;
|
|
2805
2834
|
for (;;) {
|
|
2806
2835
|
let t = l === void 0 ? yield* e`SELECT ${e("id")} FROM ${e(o.table)} WHERE ${e(a)} IS NULL ORDER BY ${e("id")} ${Q(e, 5e3)}` : yield* e`SELECT ${e("id")} FROM ${e(o.table)} WHERE ${e(a)} IS NULL AND ${e("id")} > ${l} ORDER BY ${e("id")} ${Q(e, 5e3)}`;
|
|
2807
2836
|
if (t.length === 0) break;
|
|
2808
|
-
yield* e.unsafe(`UPDATE ${
|
|
2837
|
+
yield* e.unsafe(`UPDATE ${W(o.table)} SET ${W(a)} = ${c} WHERE ${W(o.column)} IS NOT NULL AND ${W(a)} IS NULL AND ${W("id")} IN (${t.map((e) => `'${e.id.replace(/'/g, "''")}'`).join(",")})`), l = t[t.length - 1].id;
|
|
2809
2838
|
}
|
|
2810
|
-
yield* x.logInfo(`alter-column-type shadow ${o.table}.${o.column}: shadow populated`).pipe(x.annotateLogs({ scope: "voltro:migrate" })), yield* e.unsafe(`ALTER TABLE ${
|
|
2839
|
+
yield* x.logInfo(`alter-column-type shadow ${o.table}.${o.column}: shadow populated`).pipe(x.annotateLogs({ scope: "voltro:migrate" })), yield* e.unsafe(`ALTER TABLE ${W(o.table)} RENAME COLUMN ${W(o.column)} TO ${W(s)}`), yield* e.unsafe(`ALTER TABLE ${W(o.table)} RENAME COLUMN ${W(a)} TO ${W(o.column)}`), yield* e.unsafe(`ALTER TABLE ${W(o.table)} DROP COLUMN ${W(s)}`);
|
|
2811
2840
|
break;
|
|
2812
2841
|
}
|
|
2813
2842
|
case "drop-foreign-key":
|
|
2814
2843
|
yield* e.onDialectOrElse({
|
|
2815
|
-
mysql: () => X(e,
|
|
2844
|
+
mysql: () => X(e, bi(o), o.kind),
|
|
2816
2845
|
sqlite: () => Z(e, J(o.table, n.declared), o.kind),
|
|
2817
|
-
orElse: () => X(e,
|
|
2846
|
+
orElse: () => X(e, yi(o), o.kind)
|
|
2818
2847
|
});
|
|
2819
2848
|
break;
|
|
2820
2849
|
case "add-check":
|
|
2821
2850
|
yield* e.onDialectOrElse({
|
|
2822
|
-
mysql: () => X(e,
|
|
2851
|
+
mysql: () => X(e, xi(o, G), o.kind),
|
|
2823
2852
|
sqlite: () => Z(e, J(o.table, n.declared), o.kind),
|
|
2824
|
-
orElse: () => X(e,
|
|
2853
|
+
orElse: () => X(e, xi(o, W), o.kind)
|
|
2825
2854
|
});
|
|
2826
2855
|
break;
|
|
2827
2856
|
case "drop-check": yield* e.onDialectOrElse({
|
|
2828
|
-
mysql: () =>
|
|
2857
|
+
mysql: () => wi(e, o, n.declared),
|
|
2829
2858
|
sqlite: () => Z(e, J(o.table, n.declared), o.kind),
|
|
2830
|
-
orElse: () => X(e,
|
|
2859
|
+
orElse: () => X(e, Si(o), o.kind)
|
|
2831
2860
|
});
|
|
2832
2861
|
}
|
|
2833
2862
|
return {
|
|
@@ -2835,32 +2864,32 @@ BEGIN
|
|
|
2835
2864
|
status: "applied",
|
|
2836
2865
|
durationMs: Number((process.hrtime.bigint() - i) / 1000000n)
|
|
2837
2866
|
};
|
|
2838
|
-
}),
|
|
2867
|
+
}), Fi = (e, t, n, r) => x.gen(function* () {
|
|
2839
2868
|
let i = [...new Set(r.map((e) => e.runId))];
|
|
2840
|
-
if (i.length > 1) return yield* x.die(/* @__PURE__ */ Error(`applyPlan: the resume ledger holds ${i.length} unfinished runs (${i.join(", ")}). Only one migration may be in flight at a time — the advisory lock enforces it — so this means a run was interrupted and a LATER one wrote over it without clearing.\nNothing was changed. Inspect \`${
|
|
2869
|
+
if (i.length > 1) return yield* x.die(/* @__PURE__ */ Error(`applyPlan: the resume ledger holds ${i.length} unfinished runs (${i.join(", ")}). Only one migration may be in flight at a time — the advisory lock enforces it — so this means a run was interrupted and a LATER one wrote over it without clearing.\nNothing was changed. Inspect \`${D}\`, reconcile the schema by hand, and delete the rows of the run you have finished.`));
|
|
2841
2870
|
let a = i[0], o = [...r].map((e) => ({
|
|
2842
2871
|
index: Number(e.opIndex),
|
|
2843
2872
|
status: e.status,
|
|
2844
2873
|
planned: JSON.parse(e.payload)
|
|
2845
2874
|
})).sort((e, t) => e.index - t.index), s = o.find((e) => e.status === "started"), c = o.filter((e) => e.status === "started").length;
|
|
2846
|
-
if (c > 1) return yield* x.die(/* @__PURE__ */ Error(`applyPlan: the resume ledger records ${c} operations as in-flight for run ${a}. It is written strictly sequentially, so at most one can be — this ledger is corrupt and the schema state it describes cannot be trusted.\nNothing was changed. Reconcile \`${
|
|
2847
|
-
if (yield* x.logWarning(`migration resume: found an interrupted run (${a}) — ${o.filter((e) => e.status === "applied").length} of ${o.length} operation(s) completed${s ? `, in flight: ${s.planned.op.kind} ${
|
|
2875
|
+
if (c > 1) return yield* x.die(/* @__PURE__ */ Error(`applyPlan: the resume ledger records ${c} operations as in-flight for run ${a}. It is written strictly sequentially, so at most one can be — this ledger is corrupt and the schema state it describes cannot be trusted.\nNothing was changed. Reconcile \`${D}\` by hand before re-running.`));
|
|
2876
|
+
if (yield* x.logWarning(`migration resume: found an interrupted run (${a}) — ${o.filter((e) => e.status === "applied").length} of ${o.length} operation(s) completed${s ? `, in flight: ${s.planned.op.kind} ${ze(s.planned.op)}` : ""}`).pipe(x.annotateLogs({ scope: "voltro:migrate" })), o.every((e) => e.status === "pending")) return {
|
|
2848
2877
|
kind: "discard",
|
|
2849
2878
|
runId: a,
|
|
2850
2879
|
why: "no operation had started — no DDL ran"
|
|
2851
2880
|
};
|
|
2852
|
-
let l = s ? yield*
|
|
2881
|
+
let l = s ? yield* Ni(e, t, s.planned) : "clean", u = r[0].planFingerprint;
|
|
2853
2882
|
if (u !== n.toFingerprint) return {
|
|
2854
2883
|
kind: "discard",
|
|
2855
2884
|
runId: a,
|
|
2856
2885
|
why: `the declared schema changed since the interruption (recorded target ${u.slice(0, 12)}…, current ${n.toFingerprint.slice(0, 12)}…) — applying the freshly-diffed plan instead`
|
|
2857
2886
|
};
|
|
2858
|
-
let d = (e) => e.status === "applied" ? !1 : s && e.index === s.index && l !== "clean" ? l === "outstanding" :
|
|
2887
|
+
let d = (e) => e.status === "applied" ? !1 : s && e.index === s.index && l !== "clean" ? l === "outstanding" : Ve(n, e.planned.op), f = o.filter(d), p = o.filter((e) => e.status !== "applied" && !d(e));
|
|
2859
2888
|
return f.length === 0 ? {
|
|
2860
2889
|
kind: "discard",
|
|
2861
2890
|
runId: a,
|
|
2862
2891
|
why: "every recorded operation had already taken effect"
|
|
2863
|
-
} : (yield*
|
|
2892
|
+
} : (yield* ji(e, a, f.map((e) => e.index), p.map((e) => e.index)), yield* x.logWarning(`migration resume: continuing run ${a} — replaying ${f.length} operation(s), ${o.length - f.length} already applied`).pipe(x.annotateLogs({ scope: "voltro:migrate" })), {
|
|
2864
2893
|
kind: "resume",
|
|
2865
2894
|
runId: a,
|
|
2866
2895
|
ops: f.map((e) => ({
|
|
@@ -2868,39 +2897,39 @@ BEGIN
|
|
|
2868
2897
|
planned: e.planned
|
|
2869
2898
|
}))
|
|
2870
2899
|
});
|
|
2871
|
-
}),
|
|
2900
|
+
}), Ii = (e, t, n) => x.gen(function* () {
|
|
2872
2901
|
let r = t.operations.filter((e) => e.blocked);
|
|
2873
2902
|
if (r.length > 0) return yield* x.die(/* @__PURE__ */ Error(`applyPlan: refusing to execute — ${r.length} blocked operations. Run \`voltro db plan\` to see the fixes.`));
|
|
2874
|
-
yield*
|
|
2875
|
-
let i = Date.now(), a = [], o =
|
|
2903
|
+
yield* T(e, { schema: n.lockSchema });
|
|
2904
|
+
let i = Date.now(), a = [], o = Pe(e), s = Ie(o) === "plan-transactional", c = s ? t.operations.filter((e) => e.classification !== "online-required") : [], u = s ? t.operations.filter((e) => e.classification === "online-required") : t.operations, d = `plan_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 8)}`, f = u.map((e, t) => ({
|
|
2876
2905
|
index: t,
|
|
2877
2906
|
planned: e
|
|
2878
2907
|
})), p = "fresh";
|
|
2879
2908
|
try {
|
|
2880
|
-
yield*
|
|
2881
|
-
let r = yield*
|
|
2909
|
+
yield* Di(e, o);
|
|
2910
|
+
let r = yield* Oi(e);
|
|
2882
2911
|
if (r.length > 0) {
|
|
2883
|
-
let n = yield*
|
|
2884
|
-
n.kind === "resume" ? (d = n.runId, f = n.ops, p = "resume") : (yield* x.logWarning(`migration resume: discarding the ledger of run ${n.runId} — ${n.why}`).pipe(x.annotateLogs({ scope: "voltro:migrate" })), yield*
|
|
2912
|
+
let n = yield* Fi(e, o, t, r);
|
|
2913
|
+
n.kind === "resume" ? (d = n.runId, f = n.ops, p = "resume") : (yield* x.logWarning(`migration resume: discarding the ledger of run ${n.runId} — ${n.why}`).pipe(x.annotateLogs({ scope: "voltro:migrate" })), yield* Mi(e, n.runId));
|
|
2885
2914
|
}
|
|
2886
|
-
p === "fresh" && f.length > 0 && (yield*
|
|
2915
|
+
p === "fresh" && f.length > 0 && (yield* ki(e, d, t.toFingerprint, f)), c.length > 0 && (yield* e.withTransaction(x.gen(function* () {
|
|
2887
2916
|
let e = yield* C.SqlClient;
|
|
2888
|
-
for (let t of c) a.push(yield*
|
|
2917
|
+
for (let t of c) a.push(yield* Pi(e, t, n));
|
|
2889
2918
|
})));
|
|
2890
2919
|
for (let { index: t, planned: r } of f) {
|
|
2891
|
-
yield*
|
|
2892
|
-
let i = yield*
|
|
2893
|
-
a.push(
|
|
2920
|
+
yield* Ai(e, d, t, "started");
|
|
2921
|
+
let i = a.length, o = yield* Pi(e, r, n, p).pipe(x.mapError((e) => Object.assign(e, { message: `${String(e?.message ?? e)}\n\n progress: ${i} of ${f.length + c.length} operation(s) applied before this one${c.length > 0 ? ` (${c.length} of them in a transaction)` : ""}.\n` + (s ? " This dialect applies a plan atomically, so the run is rolled back.\n" : ` This dialect does NOT apply a plan atomically: those ${i} are COMMITTED and there is no rollback.\n The next \`voltro db apply\` resumes from operation ${t} — the ledger records the sequence.\n`) })));
|
|
2922
|
+
a.push(o), yield* Ai(e, d, t, "applied", o.durationMs);
|
|
2894
2923
|
}
|
|
2895
2924
|
} finally {
|
|
2896
|
-
yield*
|
|
2925
|
+
yield* E(e, { schema: n.lockSchema }).pipe(x.orDie);
|
|
2897
2926
|
}
|
|
2898
2927
|
let m = yield* n.replan(e);
|
|
2899
2928
|
if (m.operations.length > 0) {
|
|
2900
2929
|
let e = m.operations.slice(0, 10).map((e) => ` - ${e.op.kind} ${"table" in e.op ? e.op.table : ""}${"column" in e.op ? `.${String(e.op.column)}` : ""}`).join("\n");
|
|
2901
2930
|
return yield* x.die(/* @__PURE__ */ Error(`applyPlan: the migration did not converge. ${t.operations.length} operation(s) were executed without error, but re-planning against the live schema still finds ${m.operations.length}:\n${e}${m.operations.length > 10 ? `\n … and ${m.operations.length - 10} more` : ""}\nNo fingerprint was recorded — recording one would make the next boot report "schema up to date" for a schema that was never applied. This is a framework bug; the schema is unchanged and safe.\nTwo causes look identical from here, so read the list before assuming either:\n - the DDL for those operations is a no-op (it succeeded and changed nothing), or\n - the planner cannot see what the DDL did, so it proposes the same work again — which is what an\n operation naming an object a PREVIOUS operation created or renamed usually means.\nReport the operation kinds above with the column types involved.`));
|
|
2902
2931
|
}
|
|
2903
|
-
let h = a.filter((e) => e.status === "applied").length, g = Date.now() - i, _ = d, v = (/* @__PURE__ */ new Date()).toISOString(), y = yield*
|
|
2932
|
+
let h = a.filter((e) => e.status === "applied").length, g = Date.now() - i, _ = d, v = (/* @__PURE__ */ new Date()).toISOString(), y = yield* U(e, v), b = [...c, ...f.map((e) => e.planned)];
|
|
2904
2933
|
yield* e`
|
|
2905
2934
|
INSERT INTO ${e("_voltro_migration_plans")}
|
|
2906
2935
|
(${e("id")}, ${e("fingerprint")}, ${e("liveFingerprint")}, ${e("operations")},
|
|
@@ -2910,7 +2939,7 @@ BEGIN
|
|
|
2910
2939
|
(${_}, ${t.toFingerprint}, ${m.fromFingerprint}, ${JSON.stringify(b)},
|
|
2911
2940
|
${n.appliedBy}, ${n.environment}, ${n.source},
|
|
2912
2941
|
${g}, ${y}, ${n.notes ?? null})
|
|
2913
|
-
`, yield*
|
|
2942
|
+
`, yield* Mi(e, d);
|
|
2914
2943
|
let S = [...new Set(b.flatMap((e) => e.op.kind === "rename-table" ? [e.op.to] : [e.op.table]))];
|
|
2915
2944
|
return yield* x.promise(() => l({ changedTables: S }).catch(() => {})), {
|
|
2916
2945
|
id: _,
|
|
@@ -2924,14 +2953,14 @@ BEGIN
|
|
|
2924
2953
|
source: n.source,
|
|
2925
2954
|
...n.notes ? { notes: n.notes } : {}
|
|
2926
2955
|
};
|
|
2927
|
-
}),
|
|
2956
|
+
}), Li = (e) => e.operations.filter((e) => e.blocked).map((e) => ` - ${e.op.kind} ${"table" in e.op ? `[${e.op.table}]` : ""}: ${e.reason ?? "<no reason>"}\n fix: ${e.blocked?.fix ?? "<no fix>"}`).join("\n"), Ri = (e) => e`
|
|
2928
2957
|
SELECT fingerprint
|
|
2929
2958
|
FROM _voltro_migration_plans
|
|
2930
2959
|
ORDER BY ${e("appliedAt")} DESC
|
|
2931
2960
|
LIMIT 1
|
|
2932
|
-
`.pipe(x.map((e) => e.length > 0 ? e[0].fingerprint : void 0), x.catchAll(() => x.succeed(void 0))),
|
|
2933
|
-
if ((yield*
|
|
2934
|
-
let r = `plan_${Date.now().toString(36)}`, i = yield*
|
|
2961
|
+
`.pipe(x.map((e) => e.length > 0 ? e[0].fingerprint : void 0), x.catchAll(() => x.succeed(void 0))), zi = (e, t, n) => x.gen(function* () {
|
|
2962
|
+
if ((yield* Ri(e)) === t.toFingerprint) return "already-current";
|
|
2963
|
+
let r = `plan_${Date.now().toString(36)}`, i = yield* U(e, (/* @__PURE__ */ new Date()).toISOString());
|
|
2935
2964
|
return yield* e`
|
|
2936
2965
|
INSERT INTO ${e("_voltro_migration_plans")}
|
|
2937
2966
|
(${e("id")}, ${e("fingerprint")}, ${e("liveFingerprint")}, ${e("operations")},
|
|
@@ -2942,8 +2971,8 @@ BEGIN
|
|
|
2942
2971
|
${n.appliedBy}, ${n.environment}, ${n.source},
|
|
2943
2972
|
${0}, ${i}, ${"no DDL — the declared schema already matched the database"})
|
|
2944
2973
|
`, "recorded";
|
|
2945
|
-
}).pipe(x.catchAll(() => x.succeed("already-current"))),
|
|
2946
|
-
let n =
|
|
2974
|
+
}).pipe(x.catchAll(() => x.succeed("already-current"))), Bi = (e, t) => x.gen(function* () {
|
|
2975
|
+
let n = P(F(t, Pe(e))), r = yield* Ri(e);
|
|
2947
2976
|
return r === n ? {
|
|
2948
2977
|
kind: "up-to-date",
|
|
2949
2978
|
fingerprint: n
|
|
@@ -2952,23 +2981,23 @@ BEGIN
|
|
|
2952
2981
|
expected: n,
|
|
2953
2982
|
...r === void 0 ? {} : { actual: r }
|
|
2954
2983
|
};
|
|
2955
|
-
}),
|
|
2984
|
+
}), Vi = [
|
|
2956
2985
|
"pgeagertest_",
|
|
2957
2986
|
"mig_e2e_",
|
|
2958
2987
|
"mig_test_",
|
|
2959
2988
|
"mysqleagertest_",
|
|
2960
2989
|
"mssqleagertest_",
|
|
2961
2990
|
"sqliteeagertest_"
|
|
2962
|
-
],
|
|
2991
|
+
], Hi = (e) => Vi.some((t) => e.startsWith(t)), Ui = (e, t) => x.gen(function* () {
|
|
2963
2992
|
if (process.env.VOLTRO_TEST_FIXTURE_GC === "off") return [];
|
|
2964
|
-
let n = t.filter((e) =>
|
|
2993
|
+
let n = t.filter((e) => Hi(e.name)).map((e) => e.name);
|
|
2965
2994
|
if (n.length === 0) return [];
|
|
2966
2995
|
for (let t of n) yield* e.unsafe(`DROP TABLE IF EXISTS "${t}" CASCADE`).pipe(x.catchAll(() => x.void));
|
|
2967
2996
|
return n;
|
|
2968
|
-
}),
|
|
2997
|
+
}), Wi = () => {
|
|
2969
2998
|
let e = (process.env.VOLTRO_DB_IGNORE_TABLES ?? "").split(",").map((e) => e.trim()).filter((e) => e.length > 0);
|
|
2970
2999
|
return e.length > 0 ? { ignoreTables: e } : {};
|
|
2971
|
-
},
|
|
3000
|
+
}, Gi = (e) => {
|
|
2972
3001
|
if (e === void 0) return;
|
|
2973
3002
|
let t = e.trim();
|
|
2974
3003
|
if (t === "") return;
|
|
@@ -2978,48 +3007,48 @@ BEGIN
|
|
|
2978
3007
|
kind: "tables",
|
|
2979
3008
|
tables: new Set(n)
|
|
2980
3009
|
} : void 0;
|
|
2981
|
-
},
|
|
3010
|
+
}, Ki = (e) => typeof e.table == "string" ? e.table : void 0, qi = (e, t = { kind: "all" }) => ({
|
|
2982
3011
|
...e,
|
|
2983
3012
|
operations: e.operations.map((e) => {
|
|
2984
3013
|
if (!e.blocked || e.classification !== "lossy") return e;
|
|
2985
3014
|
if (t?.kind === "tables") {
|
|
2986
|
-
let n =
|
|
3015
|
+
let n = Ki(e.op);
|
|
2987
3016
|
if (n === void 0 || !t.tables.has(n)) return e;
|
|
2988
3017
|
}
|
|
2989
3018
|
let { blocked: n, ...r } = e;
|
|
2990
3019
|
return r;
|
|
2991
3020
|
})
|
|
2992
|
-
}),
|
|
2993
|
-
let t =
|
|
3021
|
+
}), Ji = (e, t, n) => t === "postgres" ? Xt(e, n).pipe(x.flatMap((e) => {
|
|
3022
|
+
let t = Zt(e);
|
|
2994
3023
|
return t === void 0 ? x.void : x.logWarning(`auto-migrate: ${t}`).pipe(x.annotateLogs({ scope: "voltro:migrate" }));
|
|
2995
|
-
}), x.catchAll(() => x.void)) : x.void,
|
|
2996
|
-
let r =
|
|
3024
|
+
}), x.catchAll(() => x.void)) : x.void, Yi = (e, t, n) => x.gen(function* () {
|
|
3025
|
+
let r = Pe(e), i = t;
|
|
2997
3026
|
if (process.env.VOLTRO_MIGRATE_FORCE !== "1") {
|
|
2998
|
-
let t =
|
|
2999
|
-
if ((yield*
|
|
3027
|
+
let t = P(F(i, r));
|
|
3028
|
+
if ((yield* Ri(e)) === t) return yield* Ji(e, r, i), {
|
|
3000
3029
|
kind: "up-to-date",
|
|
3001
3030
|
fingerprint: t
|
|
3002
3031
|
};
|
|
3003
3032
|
}
|
|
3004
|
-
let a = yield*
|
|
3033
|
+
let a = yield* $n(e), o = yield* Ui(e, a.tables);
|
|
3005
3034
|
o.length > 0 && (yield* x.logInfo(`auto-migrate: reaped ${o.length} test-fixture leftover(s)`).pipe(x.annotateLogs({
|
|
3006
3035
|
scope: "voltro:migrate",
|
|
3007
3036
|
count: o.length
|
|
3008
|
-
})), a = yield*
|
|
3009
|
-
let s = new Set(t.map((e) => e.tableName)), c = (e) => e.filter((e) => !m(e.name) || s.has(e.name)), l =
|
|
3037
|
+
})), a = yield* $n(e));
|
|
3038
|
+
let s = new Set(t.map((e) => e.tableName)), c = (e) => e.filter((e) => !m(e.name) || s.has(e.name)), l = Nn({
|
|
3010
3039
|
declared: i,
|
|
3011
3040
|
live: { tables: c(a.tables) },
|
|
3012
3041
|
dialect: r,
|
|
3013
|
-
...
|
|
3042
|
+
...Wi()
|
|
3014
3043
|
});
|
|
3015
3044
|
if (l.summary.blocked > 0) {
|
|
3016
|
-
let e = l.operations.filter((e) => e.blocked).every((e) => e.classification === "lossy"), t =
|
|
3017
|
-
if (t === void 0 || !e || (l =
|
|
3045
|
+
let e = l.operations.filter((e) => e.blocked).every((e) => e.classification === "lossy"), t = Gi(process.env.VOLTRO_DESTRUCTIVE_OK);
|
|
3046
|
+
if (t === void 0 || !e || (l = qi(l, t), l.operations.some((e) => e.blocked))) return {
|
|
3018
3047
|
kind: "refused-blocked",
|
|
3019
3048
|
plan: l
|
|
3020
3049
|
};
|
|
3021
3050
|
}
|
|
3022
|
-
return l.operations.length === 0 ? (yield*
|
|
3051
|
+
return l.operations.length === 0 ? (yield* zi(e, l, {
|
|
3023
3052
|
appliedBy: n.appliedBy,
|
|
3024
3053
|
environment: n.environment === "prod" ? "dev" : n.environment,
|
|
3025
3054
|
source: "auto-diff"
|
|
@@ -3028,37 +3057,37 @@ BEGIN
|
|
|
3028
3057
|
fingerprint: l.toFingerprint
|
|
3029
3058
|
}) : {
|
|
3030
3059
|
kind: "applied",
|
|
3031
|
-
applied: yield*
|
|
3060
|
+
applied: yield* Ii(e, l, {
|
|
3032
3061
|
declared: t,
|
|
3033
3062
|
appliedBy: n.appliedBy,
|
|
3034
3063
|
environment: n.environment === "prod" ? "dev" : n.environment,
|
|
3035
3064
|
source: "auto-diff",
|
|
3036
3065
|
replan: (e) => x.gen(function* () {
|
|
3037
|
-
let t = yield*
|
|
3038
|
-
return
|
|
3066
|
+
let t = yield* $n(e);
|
|
3067
|
+
return Nn({
|
|
3039
3068
|
declared: i,
|
|
3040
3069
|
live: { tables: c(t.tables) },
|
|
3041
3070
|
dialect: r,
|
|
3042
|
-
...
|
|
3071
|
+
...Wi()
|
|
3043
3072
|
});
|
|
3044
3073
|
})
|
|
3045
3074
|
}),
|
|
3046
3075
|
plan: l
|
|
3047
3076
|
};
|
|
3048
|
-
}),
|
|
3077
|
+
}), Xi = (e, t, n) => process.env.VOLTRO_AUTO_MIGRATE === "0" ? x.succeed({
|
|
3049
3078
|
kind: "skipped",
|
|
3050
3079
|
reason: "VOLTRO_AUTO_MIGRATE=0"
|
|
3051
|
-
}) : n.environment === "prod" ?
|
|
3080
|
+
}) : n.environment === "prod" ? Bi(e, t) : Yi(e, t, n), Zi = (e, t) => {
|
|
3052
3081
|
switch (e.kind) {
|
|
3053
3082
|
case "skipped": return `auto-migrate: skipped (${e.reason})`;
|
|
3054
|
-
case "up-to-date": return `auto-migrate: schema up to date (${t}, fingerprint=${
|
|
3083
|
+
case "up-to-date": return `auto-migrate: schema up to date (${t}, fingerprint=${Gt(e.fingerprint)})`;
|
|
3055
3084
|
case "applied": {
|
|
3056
3085
|
let t = e.plan.summary;
|
|
3057
|
-
return `auto-migrate: applied ${e.applied.appliedOps} op(s) in ${e.applied.durationMs}ms [safe=${t.safe} needs-default=${t.needsDefault} needs-backfill=${t.needsBackfill} rename=${t.needsRenameAnnotation} lossy=${t.lossy}] fingerprint=${
|
|
3086
|
+
return `auto-migrate: applied ${e.applied.appliedOps} op(s) in ${e.applied.durationMs}ms [safe=${t.safe} needs-default=${t.needsDefault} needs-backfill=${t.needsBackfill} rename=${t.needsRenameAnnotation} lossy=${t.lossy}] fingerprint=${Gt(e.applied.fingerprint)}`;
|
|
3058
3087
|
}
|
|
3059
|
-
case "prod-mismatch": return `auto-migrate: SCHEMA FINGERPRINT MISMATCH — declared=${
|
|
3088
|
+
case "prod-mismatch": return `auto-migrate: SCHEMA FINGERPRINT MISMATCH — declared=${Gt(e.expected)}` + (e.actual ? ` live=${Gt(e.actual)}` : " live=<no _voltro_migration_plans row>") + ". Run `voltro db apply --plan plan.json` from the deploy pipeline before serving.";
|
|
3060
3089
|
case "refused-blocked": {
|
|
3061
|
-
let t = e.plan.operations.filter((e) => e.blocked), n = t.filter((e) => e.op.kind === "drop-table").length, r = t.filter((e) => e.op.kind === "drop-table").map((e) => "table" in e.op ? e.op.table : "").filter(Boolean), i = t.filter((e) => e.op.kind === "add-column").length, a = t.filter((e) => e.op.kind === "drop-column").length, o = t.filter((e) => e.classification === "needs-rename-annotation").length, s = `auto-migrate: REFUSED — ${e.plan.summary.blocked} blocked operation(s):\n` +
|
|
3090
|
+
let t = e.plan.operations.filter((e) => e.blocked), n = t.filter((e) => e.op.kind === "drop-table").length, r = t.filter((e) => e.op.kind === "drop-table").map((e) => "table" in e.op ? e.op.table : "").filter(Boolean), i = t.filter((e) => e.op.kind === "add-column").length, a = t.filter((e) => e.op.kind === "drop-column").length, o = t.filter((e) => e.classification === "needs-rename-annotation").length, s = `auto-migrate: REFUSED — ${e.plan.summary.blocked} blocked operation(s):\n` + Li(e.plan), c = [""];
|
|
3062
3091
|
if (n > 0 && c.push(`${n} table(s) exist in the live DB but aren't in your declared schema.`, "This is usually one of three things:", " (a) You're iterating on the schema — the table file got renamed, moved, or temporarily commented out.", " → Restore the declaration. Your data stays intact.", " (b) You want to KEEP the table but NOT manage it with Voltro (a leftover from another tool —", " a Strapi/Rails/legacy migration artifact, or an externally-owned table).", ` → Set \`VOLTRO_DB_IGNORE_TABLES=${r.join(",")}\` (comma-separated).`, " The planner excludes those tables from the diff entirely — it never drops them, and they", " stop blocking your OTHER (additive) changes. This is the fix when a leftover freezes your schema.", " (c) You actually want to drop the table.", ` → Set \`VOLTRO_DESTRUCTIVE_OK=${r.join(",")}\` for ONE run — it acknowledges`, " the data loss for THOSE tables only; every other lossy op in this plan stays blocked.", " (`VOLTRO_DESTRUCTIVE_OK=1` acknowledges all of them, which is rarely what you mean.)", " There is deliberately no `dropped()` marker for a TABLE, unlike for a column: a", " dropped column leaves a slot worth documenting in the declaration, a dropped table", " leaves nothing — the marker would be a dead entry you must remember to delete.", " Soft-drop: set `VOLTRO_SOFT_DROP=1` alongside DESTRUCTIVE_OK to RENAME instead of DROP", " (data survives as `<name>__dropped_<ts>` for ~7d; restorable via `voltro db restore-snapshot`)."), i > 0 && c.push(`${i} required column(s) need a backfill strategy before adding to a populated table.`, " → Annotate the column: `.backfill(sql`<expr>`)` or `.backfill(row => <fn>)` or `.default(<value>)`.", " Existing rows get the backfill value; the column then lands as NOT NULL."), a > 0) {
|
|
3063
3092
|
let t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map();
|
|
3064
3093
|
for (let r of e.plan.operations) {
|
|
@@ -3075,7 +3104,7 @@ BEGIN
|
|
|
3075
3104
|
return o > 0 && c.push(`${o} column(s) look like renames (one column gone + a new one of same shape appeared).`, " → On the NEW column add `.renamedFrom('<oldName>')` so the planner emits RENAME instead of DROP+ADD."), c.push("", "See `voltro db plan` for the full machine-readable diff."), s + "\n" + c.join("\n");
|
|
3076
3105
|
}
|
|
3077
3106
|
}
|
|
3078
|
-
},
|
|
3107
|
+
}, Qi = /* @__PURE__ */ new Set([
|
|
3079
3108
|
"node_modules",
|
|
3080
3109
|
"dist",
|
|
3081
3110
|
"build",
|
|
@@ -3084,11 +3113,11 @@ BEGIN
|
|
|
3084
3113
|
".next",
|
|
3085
3114
|
".git",
|
|
3086
3115
|
".framework"
|
|
3087
|
-
]),
|
|
3116
|
+
]), $i = async (e) => {
|
|
3088
3117
|
let t = [], n = async (e) => {
|
|
3089
3118
|
let r = await ne.readdir(e, { withFileTypes: !0 }).catch(() => []);
|
|
3090
3119
|
for (let i of r) {
|
|
3091
|
-
if (
|
|
3120
|
+
if (Qi.has(i.name)) continue;
|
|
3092
3121
|
let r = re(e, i.name);
|
|
3093
3122
|
i.isDirectory() ? await n(r) : i.isFile() && d.test(i.name) && t.push(r);
|
|
3094
3123
|
}
|
|
@@ -3097,7 +3126,7 @@ BEGIN
|
|
|
3097
3126
|
let n = e.split("/").pop() ?? e, r = t.split("/").pop() ?? t;
|
|
3098
3127
|
return n.localeCompare(r);
|
|
3099
3128
|
});
|
|
3100
|
-
},
|
|
3129
|
+
}, ea = async (e) => {
|
|
3101
3130
|
let t = [];
|
|
3102
3131
|
for (let n of e) {
|
|
3103
3132
|
let e = (await import(ie(n).href)).default;
|
|
@@ -3111,11 +3140,11 @@ BEGIN
|
|
|
3111
3140
|
});
|
|
3112
3141
|
}
|
|
3113
3142
|
return t;
|
|
3114
|
-
},
|
|
3143
|
+
}, ta = (e) => e`
|
|
3115
3144
|
SELECT ${e("id")}
|
|
3116
3145
|
FROM ${e("_voltro_migration_plans")}
|
|
3117
3146
|
WHERE ${e("source")} = 'file'
|
|
3118
|
-
`.pipe(x.map((e) => e.map((e) => e.id)), x.catchAll(() => x.succeed([]))),
|
|
3147
|
+
`.pipe(x.map((e) => e.map((e) => e.id)), x.catchAll(() => x.succeed([]))), na = class extends Error {
|
|
3119
3148
|
migrationId;
|
|
3120
3149
|
file;
|
|
3121
3150
|
cause;
|
|
@@ -3123,7 +3152,7 @@ BEGIN
|
|
|
3123
3152
|
constructor(e, t, n) {
|
|
3124
3153
|
super(`migration ${e}: up() SUCCEEDED but the ledger row could not be written.\n The change IS in the database. It is NOT recorded, so the next run would apply it AGAIN.\n Do not re-run ${t} until this is resolved.\n Cause: ${n instanceof Error ? n.message : String(n)}`), this.migrationId = e, this.file = t, this.cause = n, this.name = "FileMigrationLedgerError";
|
|
3125
3154
|
}
|
|
3126
|
-
},
|
|
3155
|
+
}, ra = (e, t, n, r) => x.gen(function* () {
|
|
3127
3156
|
let i = Date.now(), a = (/* @__PURE__ */ new Date()).toISOString(), o = {
|
|
3128
3157
|
sql: e,
|
|
3129
3158
|
log: {
|
|
@@ -3144,7 +3173,7 @@ BEGIN
|
|
|
3144
3173
|
});
|
|
3145
3174
|
let c = Date.now() - i;
|
|
3146
3175
|
!x.isEffect(s) && c < 2 && (yield* x.logWarning(`migration ${t.migration.id}: up() resolved in ${c}ms — did the body \`await\` an \`@effect/sql\` Effect by accident? \`sql.unsafe(...)\` returns an Effect, not a Promise; \`await\` on it is a silent no-op. Switch the body to \`Effect.gen(function* () { yield* sql.unsafe(...) })\` form.`).pipe(x.annotateLogs({ scope: `migrations:file:${t.migration.id}` })));
|
|
3147
|
-
let l = yield*
|
|
3176
|
+
let l = yield* U(e, a);
|
|
3148
3177
|
return yield* e`
|
|
3149
3178
|
INSERT INTO ${e("_voltro_migration_plans")}
|
|
3150
3179
|
(${e("id")}, ${e("fingerprint")}, ${e("operations")},
|
|
@@ -3157,10 +3186,10 @@ BEGIN
|
|
|
3157
3186
|
}])},
|
|
3158
3187
|
${r}, ${n}, ${"file"},
|
|
3159
3188
|
${c}, ${l}, ${t.migration.description})
|
|
3160
|
-
`.pipe(x.mapError((e) => new
|
|
3161
|
-
}),
|
|
3189
|
+
`.pipe(x.mapError((e) => new na(t.migration.id, t.file, e))), { durationMs: c };
|
|
3190
|
+
}), ia = (e, t) => x.gen(function* () {
|
|
3162
3191
|
let n = yield* x.tryPromise({
|
|
3163
|
-
try: () =>
|
|
3192
|
+
try: () => $i(re(t, "migrations")),
|
|
3164
3193
|
catch: (e) => e
|
|
3165
3194
|
});
|
|
3166
3195
|
if (n.length === 0) return {
|
|
@@ -3168,25 +3197,25 @@ BEGIN
|
|
|
3168
3197
|
skipped: []
|
|
3169
3198
|
};
|
|
3170
3199
|
let r = yield* x.tryPromise({
|
|
3171
|
-
try: () =>
|
|
3200
|
+
try: () => ea(n),
|
|
3172
3201
|
catch: (e) => e
|
|
3173
3202
|
});
|
|
3174
3203
|
if (r.length === 0) return {
|
|
3175
3204
|
pending: [],
|
|
3176
3205
|
skipped: []
|
|
3177
3206
|
};
|
|
3178
|
-
let i = new Set(yield*
|
|
3207
|
+
let i = new Set(yield* ta(e));
|
|
3179
3208
|
return {
|
|
3180
3209
|
pending: r.filter((e) => !i.has(e.migration.id)),
|
|
3181
3210
|
skipped: r.filter((e) => i.has(e.migration.id)).map((e) => e.migration.id)
|
|
3182
3211
|
};
|
|
3183
|
-
}),
|
|
3184
|
-
let { pending: n, skipped: r } = yield*
|
|
3212
|
+
}), aa = (e, t) => ia(e, t).pipe(x.map((e) => e.pending.map((e) => e.migration.id))), oa = (e, t) => x.gen(function* () {
|
|
3213
|
+
let { pending: n, skipped: r } = yield* ia(e, t.projectRoot);
|
|
3185
3214
|
if (n.length === 0) return {
|
|
3186
3215
|
applied: [],
|
|
3187
3216
|
skipped: r
|
|
3188
3217
|
};
|
|
3189
|
-
yield*
|
|
3218
|
+
yield* T(e, { schema: t.lockSchema });
|
|
3190
3219
|
let i = [];
|
|
3191
3220
|
try {
|
|
3192
3221
|
for (let r of n) {
|
|
@@ -3195,7 +3224,7 @@ BEGIN
|
|
|
3195
3224
|
id: r.migration.id,
|
|
3196
3225
|
file: r.file
|
|
3197
3226
|
}));
|
|
3198
|
-
let { durationMs: n } = yield*
|
|
3227
|
+
let { durationMs: n } = yield* ra(e, r, t.env, t.appliedBy);
|
|
3199
3228
|
i.push({
|
|
3200
3229
|
id: r.migration.id,
|
|
3201
3230
|
durationMs: n
|
|
@@ -3206,28 +3235,28 @@ BEGIN
|
|
|
3206
3235
|
}));
|
|
3207
3236
|
}
|
|
3208
3237
|
} finally {
|
|
3209
|
-
yield*
|
|
3238
|
+
yield* E(e, { schema: t.lockSchema }).pipe(x.orDie);
|
|
3210
3239
|
}
|
|
3211
3240
|
return {
|
|
3212
3241
|
applied: i,
|
|
3213
3242
|
skipped: r
|
|
3214
3243
|
};
|
|
3215
|
-
}),
|
|
3244
|
+
}), sa = (e, t) => e`
|
|
3216
3245
|
SELECT ${e("id")}
|
|
3217
3246
|
FROM ${e("_voltro_migration_plans")}
|
|
3218
3247
|
WHERE ${e("id")} = ${t} AND ${e("source")} = 'file'
|
|
3219
3248
|
LIMIT 1
|
|
3220
|
-
`,
|
|
3221
|
-
if (!(yield*
|
|
3249
|
+
`, ca = (e, t) => x.gen(function* () {
|
|
3250
|
+
if (!(yield* sa(e, t.id))[0]) return yield* x.fail(/* @__PURE__ */ Error(`rollback: ${t.id} not found in _voltro_migration_plans (file source)`));
|
|
3222
3251
|
let n = yield* x.tryPromise({
|
|
3223
|
-
try: () =>
|
|
3252
|
+
try: () => $i(re(t.projectRoot, "migrations")),
|
|
3224
3253
|
catch: (e) => e
|
|
3225
3254
|
}), r = (yield* x.tryPromise({
|
|
3226
|
-
try: () =>
|
|
3255
|
+
try: () => ea(n),
|
|
3227
3256
|
catch: (e) => e
|
|
3228
3257
|
})).find((e) => e.migration.id === t.id);
|
|
3229
3258
|
if (!r) return yield* x.fail(/* @__PURE__ */ Error(`rollback: file for migration ${t.id} not found on disk under ${t.projectRoot}/migrations/`));
|
|
3230
|
-
yield*
|
|
3259
|
+
yield* T(e, { schema: t.lockSchema });
|
|
3231
3260
|
let i = Date.now();
|
|
3232
3261
|
try {
|
|
3233
3262
|
let n = {
|
|
@@ -3254,9 +3283,9 @@ BEGIN
|
|
|
3254
3283
|
durationMs: o
|
|
3255
3284
|
};
|
|
3256
3285
|
} finally {
|
|
3257
|
-
yield*
|
|
3286
|
+
yield* E(e, { schema: t.lockSchema }).pipe(x.orDie);
|
|
3258
3287
|
}
|
|
3259
|
-
}),
|
|
3288
|
+
}), la = (e) => x.gen(function* () {
|
|
3260
3289
|
let t = yield* C.SqlClient, n = yield* t`
|
|
3261
3290
|
SELECT id, fingerprint, appliedAt FROM _voltro_migration_plans
|
|
3262
3291
|
WHERE source = 'auto-diff'
|
|
@@ -3301,7 +3330,7 @@ BEGIN
|
|
|
3301
3330
|
snapshotFingerprint: e.fingerprint,
|
|
3302
3331
|
snapshotId: i
|
|
3303
3332
|
};
|
|
3304
|
-
}),
|
|
3333
|
+
}), ua = { safe: !0 }, da = (e) => {
|
|
3305
3334
|
switch (e.kind) {
|
|
3306
3335
|
case "drop-column": return {
|
|
3307
3336
|
safe: !1,
|
|
@@ -3328,7 +3357,7 @@ BEGIN
|
|
|
3328
3357
|
reason: `old instances read/write "${e.table}"."${e.column}" as ${e.from}; the new ${e.to} type can reject their writes or fail to decode their reads`,
|
|
3329
3358
|
remedy: "add a new column of the target type + backfill + dual-write, cut code over, then drop the old column in a LATER deploy"
|
|
3330
3359
|
};
|
|
3331
|
-
case "alter-column-nullability": return e.toNullable ?
|
|
3360
|
+
case "alter-column-nullability": return e.toNullable ? ua : {
|
|
3332
3361
|
safe: !1,
|
|
3333
3362
|
reason: `old instances may INSERT "${e.table}" without (or with NULL in) "${e.column}", which the new NOT NULL rejects`,
|
|
3334
3363
|
remedy: `make code always write "${e.column}" and deploy that first; add NOT NULL in a LATER deploy (with a default to cover the gap)`
|
|
@@ -3358,12 +3387,12 @@ BEGIN
|
|
|
3358
3387
|
case "drop-unique":
|
|
3359
3388
|
case "drop-unique-composite":
|
|
3360
3389
|
case "drop-foreign-key":
|
|
3361
|
-
case "drop-check": return
|
|
3390
|
+
case "drop-check": return ua;
|
|
3362
3391
|
}
|
|
3363
|
-
},
|
|
3392
|
+
}, fa = (e) => {
|
|
3364
3393
|
let t = [];
|
|
3365
3394
|
for (let n of e) {
|
|
3366
|
-
let e =
|
|
3395
|
+
let e = da(n.op);
|
|
3367
3396
|
e.safe || t.push({
|
|
3368
3397
|
op: n,
|
|
3369
3398
|
reason: e.reason,
|
|
@@ -3371,7 +3400,7 @@ BEGIN
|
|
|
3371
3400
|
});
|
|
3372
3401
|
}
|
|
3373
3402
|
return t;
|
|
3374
|
-
},
|
|
3403
|
+
}, pa = (e) => {
|
|
3375
3404
|
if (!e.enabled || e.unsafeCount === 0) return {
|
|
3376
3405
|
refuse: !1,
|
|
3377
3406
|
warnForced: !1,
|
|
@@ -3387,18 +3416,18 @@ BEGIN
|
|
|
3387
3416
|
warnForced: !1,
|
|
3388
3417
|
message: `${t}. Old instances would break against the new schema mid-rollout. Split into expand → deploy → contract (see the ⚠ list above), deploy with no overlap (maintenance window / scale-to-zero), or pass --force to override.`
|
|
3389
3418
|
};
|
|
3390
|
-
},
|
|
3419
|
+
}, ma = (e) => {
|
|
3391
3420
|
let t = e.table;
|
|
3392
3421
|
if (typeof t == "string") return t;
|
|
3393
3422
|
let n = e.from;
|
|
3394
3423
|
return typeof n == "string" ? n : void 0;
|
|
3395
|
-
},
|
|
3424
|
+
}, ha = (e) => ({
|
|
3396
3425
|
kind: e.op.kind,
|
|
3397
|
-
table:
|
|
3426
|
+
table: ma(e.op),
|
|
3398
3427
|
classification: e.classification,
|
|
3399
3428
|
reason: e.reason,
|
|
3400
3429
|
blockedFix: e.blocked?.fix
|
|
3401
|
-
}),
|
|
3430
|
+
}), ga = (e) => e.operations.map(ha), _a = async (e) => {
|
|
3402
3431
|
let t = e.log ?? (() => {}), n = {
|
|
3403
3432
|
branchId: e.branchId,
|
|
3404
3433
|
mechanism: e.mechanism,
|
|
@@ -3417,10 +3446,10 @@ BEGIN
|
|
|
3417
3446
|
applied: !1,
|
|
3418
3447
|
converged: !1,
|
|
3419
3448
|
residual: r,
|
|
3420
|
-
infidelity:
|
|
3449
|
+
infidelity: ga(o)
|
|
3421
3450
|
};
|
|
3422
3451
|
else {
|
|
3423
|
-
let i = await e.plan(), o =
|
|
3452
|
+
let i = await e.plan(), o = ga(i), s = o.filter((e) => e.classification === "lossy"), c = qi(i), l = c.operations.filter((e) => e.blocked !== void 0).map(ha);
|
|
3424
3453
|
if (l.length > 0) a = {
|
|
3425
3454
|
...n,
|
|
3426
3455
|
outcome: "blocked",
|
|
@@ -3445,7 +3474,7 @@ BEGIN
|
|
|
3445
3474
|
};
|
|
3446
3475
|
else {
|
|
3447
3476
|
await e.apply(c), t(`branch ${e.branchId}: applied ${o.length} operation(s)`);
|
|
3448
|
-
let i =
|
|
3477
|
+
let i = ga(await e.replan());
|
|
3449
3478
|
a = {
|
|
3450
3479
|
...n,
|
|
3451
3480
|
outcome: i.length > 0 ? "diverged" : s.length > 0 ? "lossy" : "clean",
|
|
@@ -3483,7 +3512,7 @@ BEGIN
|
|
|
3483
3512
|
...a,
|
|
3484
3513
|
tornDown: o
|
|
3485
3514
|
};
|
|
3486
|
-
},
|
|
3515
|
+
}, va = (e) => {
|
|
3487
3516
|
switch (e.outcome) {
|
|
3488
3517
|
case "clean": return 0;
|
|
3489
3518
|
case "lossy": return 2;
|
|
@@ -3492,22 +3521,22 @@ BEGIN
|
|
|
3492
3521
|
case "infidelity": return 1;
|
|
3493
3522
|
case "failed": return 1;
|
|
3494
3523
|
}
|
|
3495
|
-
},
|
|
3524
|
+
}, ya = (e) => ` ${e.classification === "lossy" ? "✗" : "•"} ${e.kind}${e.table ? ` ${e.table}` : ""} [${e.classification}]${e.reason ? ` — ${e.reason}` : ""}${e.blockedFix ? `\n ! ${e.blockedFix}` : ""}`, ba = (e) => {
|
|
3496
3525
|
let t = [];
|
|
3497
3526
|
if (t.push(`branch rehearsal · ${e.branchId} · mechanism ${e.mechanism}`), t.push(` branched ${e.branchedTables} table(s), replayed ${e.replayedForeignKeys} foreign key(s)`), e.outcome === "failed") t.push(` FAILED: ${e.error ?? "unknown error"}`);
|
|
3498
3527
|
else if (e.outcome === "infidelity") {
|
|
3499
3528
|
t.push(" BRANCH IS NOT A FAITHFUL COPY of the parent — the rehearsal proves nothing about your migration."), t.push(" The parent's own schema still differs from the branch by:");
|
|
3500
|
-
for (let n of e.infidelity) t.push(
|
|
3529
|
+
for (let n of e.infidelity) t.push(ya(n));
|
|
3501
3530
|
} else {
|
|
3502
3531
|
t.push(` plan: ${e.operations.length} operation(s), ${e.lossy.length} lossy, ${e.blocked.length} refused`);
|
|
3503
|
-
for (let n of e.operations) t.push(
|
|
3504
|
-
if (e.lossy.length > 0 && (t.push(""), t.push(` ⚠ ${e.lossy.length} operation(s) DESTROY DATA. They were executed on the branch (it is`), t.push(" disposable) so they are rehearsed, but production refuses them until you set"), t.push(" VOLTRO_DESTRUCTIVE_OK — naming the tables, not `1`.")), e.blocked.length > 0 && (t.push(""), t.push(` ${e.blocked.length} operation(s) the planner will not auto-apply anywhere — the plan was NOT executed.`)), e.applied && (t.push(""), t.push(e.converged ? " ✓ applied on the branch, and the re-plan is EMPTY (the migration converges)." : ` ✗ applied, but the re-plan STILL proposes ${e.residual.length} operation(s) — this migration does not converge:`), !e.converged)) for (let n of e.residual) t.push(
|
|
3532
|
+
for (let n of e.operations) t.push(ya(n));
|
|
3533
|
+
if (e.lossy.length > 0 && (t.push(""), t.push(` ⚠ ${e.lossy.length} operation(s) DESTROY DATA. They were executed on the branch (it is`), t.push(" disposable) so they are rehearsed, but production refuses them until you set"), t.push(" VOLTRO_DESTRUCTIVE_OK — naming the tables, not `1`.")), e.blocked.length > 0 && (t.push(""), t.push(` ${e.blocked.length} operation(s) the planner will not auto-apply anywhere — the plan was NOT executed.`)), e.applied && (t.push(""), t.push(e.converged ? " ✓ applied on the branch, and the re-plan is EMPTY (the migration converges)." : ` ✗ applied, but the re-plan STILL proposes ${e.residual.length} operation(s) — this migration does not converge:`), !e.converged)) for (let n of e.residual) t.push(ya(n));
|
|
3505
3534
|
}
|
|
3506
3535
|
return t.push(e.tornDown ? ` branch ${e.branchId} torn down.` : ` branch ${e.branchId} KEPT — drop it when you are done.`), t.join("\n");
|
|
3507
|
-
},
|
|
3536
|
+
}, xa = (e, ...t) => ({
|
|
3508
3537
|
_tag: "RawSqlFragment",
|
|
3509
3538
|
strings: [...e],
|
|
3510
3539
|
values: [...t]
|
|
3511
|
-
}),
|
|
3540
|
+
}), Sa = (e) => typeof e == "object" && !!e && e._tag === "RawSqlFragment";
|
|
3512
3541
|
//#endregion
|
|
3513
|
-
export {
|
|
3542
|
+
export { O as DEFAULT_CDC_CHANNEL, d as FILE_MIGRATION_PATTERN, na as FileMigrationLedgerError, Je as REACTIVE_TRIGGER_PREFIX, pe as VOLTRO_MIGRATION_LOCK_KEY, T as acquireMigrationLock, U as appliedAtValue, Lt as applyNamespacedSchema, Ii as applyPlan, Dt as applySchema, pa as assessRollingDeployGate, va as branchRehearsalExitCode, Vn as chunkTables, da as classifyRollingDeploySafety, F as declaredSnapshot, et as defaultArrayClause, $e as defaultClause, j as defaultJsonClause, Zi as describeOutcome, Gi as destructiveScope, Xt as detectReactiveTriggerDrift, $r as emitAddIndexMysql, Pr as emitCreateTableMysql, gr as emitDropColumnDdl, _r as emitDropColumnDdlMysql, Et as emitFrameworkBootstrapSql, wt as emitNamespaceProvisionDdl, Tt as emitNamespacedSchemaSql, Ct as emitSchemaSql, er as engineFromVersion, P as fingerprintSchema, ye as fnv1a64, ba as formatBranchRehearsal, Zt as formatReactiveTriggerDrift, Wi as ignoreTablesFromEnv, $n as introspectSchema, ar as isAlreadySatisfied, c as isFileMigration, Sa as isRawSqlFragment, kt as isReRunSafeDdl, Fn as mapPgType, g as migration, be as migrationLockKeyForSchema, xe as migrationLockNameForSchema, Yr as mysqlIndexPrefixFor, Xe as notifyFunctionName, M as numericIdSql, Pn as parseEnumCheck, aa as pendingFileMigrationIds, Nn as planMigrations, Rt as provisionTenantNamespace, Ye as reactiveTriggerName, mt as reactiveTriggerRepairSql, zi as recordUpToDate, _a as rehearseMigrationOnBranch, ha as rehearsedOperation, E as releaseMigrationLock, Mr as renderColumnMysql, Dr as renderColumnPg, he as resolveMigrationLockSchema, H as resolveMysqlEngine, ca as rollbackFileBasedMigration, fa as rollingDeployUnsafeOps, oa as runFileBasedMigrations, zt as runFrameworkBootstrap, It as runMigrate, Xi as runPlannedMigrations, Gt as shortFingerprint, Kt as snapshotColumn, xa as sql, A as sqlType, la as squashMigrationPlans, qi as unblockLossy, Ne as withMigrationLock };
|