@voltro/database 0.21.0 → 0.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/sql.js CHANGED
@@ -1,4 +1,4 @@
1
- import { B as e, W as t, a as n, c as r, i, lt as a, n as o, r as s, rt as c, t as l, z as u } from "./fileBased-Dfuv6JWP.js";
1
+ import { B as e, W as t, a as n, c as r, i, lt as a, n as o, r as s, rt as c, t as l, z as u } from "./fileBased-CDnutVVk.js";
2
2
  import { Effect as d } from "effect";
3
3
  import { createLogger as f } from "@voltro/logger";
4
4
  import { SqlClient as p } from "@effect/sql";
@@ -39,7 +39,7 @@ var _ = (e, t, n, r = 400) => {
39
39
  t !== void 0 && s.push(`db.${e}: ${t}`);
40
40
  }
41
41
  return s.push(""), s.join("\n");
42
- }, v = (e) => e.unique === !0 && typeof e.where == "string" && e.where.length > 0, te = (e) => e.replace(/"/g, "`"), y = (e) => typeof e == "string" ? e : e.name ?? String(e), ne = (e, t) => `_ua_${t}_${e}`.slice(0, 64), b = (e, t) => {
42
+ }, v = (e) => e.unique === !0 && typeof e.where == "string" && e.where.length > 0, y = (e) => e.replace(/"/g, "`"), b = (e) => typeof e == "string" ? e : e.name ?? String(e), te = (e, t) => `_ua_${t}_${e}`.slice(0, 64), x = (e, t) => {
43
43
  if (t !== "mysql" && t !== "mariadb" || !e.appliedIndexes.some(v)) return e;
44
44
  let n = { ...e.fields }, r = [], i = [];
45
45
  for (let t of e.appliedIndexes) {
@@ -47,11 +47,11 @@ var _ = (e, t, n, r = 400) => {
47
47
  r.push(t);
48
48
  continue;
49
49
  }
50
- let a = te(t.where), o = [];
50
+ let a = y(t.where), o = [];
51
51
  for (let r of t.fields) {
52
- let i = y(r);
52
+ let i = b(r);
53
53
  if (!(i in e.fields)) throw Error(`@voltro/migrate: uniqueActive '${t.name}' on '${e.tableName}' references unknown column '${i}'.`);
54
- let s = ne(t.name, i);
54
+ let s = te(t.name, i);
55
55
  o.push(s), n[s] = {
56
56
  type: "text",
57
57
  nullable: !0,
@@ -74,16 +74,16 @@ var _ = (e, t, n, r = 400) => {
74
74
  appliedIndexes: r,
75
75
  appliedUniques: [...e.appliedUniques ?? [], ...i]
76
76
  };
77
- }, x = (e, t) => `${e}::${t}`, re = (e, t) => {
77
+ }, S = (e, t) => `${e}::${t}`, ne = (e, t) => {
78
78
  let n = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Set(), a = (e) => {
79
79
  n.add(e);
80
80
  let o = [...t(e)].filter((t) => t.target !== e).sort((e, t) => e.column.localeCompare(t.column));
81
- for (let t of o) n.has(t.target) ? i.add(x(e, t.column)) : r.has(t.target) || a(t.target);
81
+ for (let t of o) n.has(t.target) ? i.add(S(e, t.column)) : r.has(t.target) || a(t.target);
82
82
  n.delete(e), r.add(e);
83
83
  };
84
84
  for (let t of [...e].sort()) r.has(t) || a(t);
85
85
  return i;
86
- }, S = 6322741009312437n, ie = 250, ae = () => {
86
+ }, re = 6322741009312437n, ie = 250, ae = () => {
87
87
  let e = Number(process.env.VOLTRO_MIGRATION_LOCK_TIMEOUT_MS);
88
88
  return Number.isFinite(e) && e > 0 ? e : 3e4;
89
89
  }, oe = (e) => d.gen(function* () {
@@ -94,13 +94,13 @@ var _ = (e, t, n, r = 400) => {
94
94
  Date.now() - n >= t && (yield* d.die(/* @__PURE__ */ Error(`could not acquire the postgres migration advisory lock within ${Math.round(t / 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* d.sleep(`${ie} millis`);
95
95
  }
96
96
  }), se = (e) => d.gen(function* () {
97
- yield* e`SELECT pg_advisory_unlock(${S.toString()}::bigint)`;
98
- }), ce = `voltro_migration_${S.toString(36)}`, le = 30, ue = (e) => d.gen(function* () {
97
+ yield* e`SELECT pg_advisory_unlock(${re.toString()}::bigint)`;
98
+ }), ce = `voltro_migration_${re.toString(36)}`, le = 30, ue = (e) => d.gen(function* () {
99
99
  (yield* e`
100
100
  SELECT GET_LOCK(${ce}, ${le}) AS got`)[0]?.got !== 1 && (yield* d.die(/* @__PURE__ */ Error(`could not acquire the migration lock '${ce}' within ${le}s (another migration is in progress, or a prior one left it held).`)));
101
101
  }), de = (e) => d.gen(function* () {
102
102
  yield* e`SELECT RELEASE_LOCK(${ce})`;
103
- }), fe = `voltro_migration_${S.toString(36)}`, pe = 3e4, me = (e) => d.gen(function* () {
103
+ }), fe = `voltro_migration_${re.toString(36)}`, pe = 3e4, me = (e) => d.gen(function* () {
104
104
  let t = yield* e`
105
105
  DECLARE @res int;
106
106
  EXEC @res = sp_getapplock @Resource = ${fe}, @LockMode = 'Exclusive',
@@ -119,9 +119,9 @@ var _ = (e, t, n, r = 400) => {
119
119
  mssql: () => he(e),
120
120
  sqlite: () => ge,
121
121
  orElse: () => se(e)
122
- }), T = (e, t) => d.acquireUseRelease(C(e), () => t, () => w(e).pipe(d.orDie)), _e = f({ scope: "voltro:migrate" }), E = (e) => {
123
- _e.warn(e.replace(/^\[voltro:migrate\]\s*/, ""));
124
- }, D = (e, t) => {
122
+ }), _e = (e, t) => d.acquireUseRelease(C(e), () => t, () => w(e).pipe(d.orDie)), ve = f({ scope: "voltro:migrate" }), T = (e) => {
123
+ ve.warn(e.replace(/^\[voltro:migrate\]\s*/, ""));
124
+ }, E = (e, t) => {
125
125
  let n = e.type;
126
126
  if (e.spatial) {
127
127
  if (t === "postgres") return `${e.spatial.kind}(${e.spatial.geomKind},${e.spatial.srid})`;
@@ -132,7 +132,7 @@ var _ = (e, t, n, r = 400) => {
132
132
  return e.rawDdl;
133
133
  }
134
134
  if (n === "array" && e.arrayElement) {
135
- if (t === "postgres") return `${D({
135
+ if (t === "postgres") return `${E({
136
136
  ...e,
137
137
  type: e.arrayElement,
138
138
  arrayElement: void 0
@@ -232,22 +232,22 @@ var _ = (e, t, n, r = 400) => {
232
232
  case "array": return "TEXT[]";
233
233
  case "interval": return "INTERVAL";
234
234
  }
235
- }, ve = (e, t) => {
235
+ }, ye = (e, t) => {
236
236
  if (!e.hasDefault || e.defaultFactory !== void 0) return null;
237
237
  let n = e.defaultValue;
238
- return n === "now" ? u(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) ? ye(n, e, t) : typeof n == "object" && n ? O(n, t) : null;
239
- }, ye = (e, t, n) => {
240
- if (n !== "postgres" || t.type !== "array" || t.arrayElement === void 0) return O(e, n);
241
- let r = D({
238
+ return n === "now" ? u(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) ? be(n, e, t) : typeof n == "object" && n ? D(n, t) : null;
239
+ }, be = (e, t, n) => {
240
+ if (n !== "postgres" || t.type !== "array" || t.arrayElement === void 0) return D(e, n);
241
+ let r = E({
242
242
  ...t,
243
243
  type: t.arrayElement,
244
244
  arrayElement: void 0
245
245
  }, n);
246
246
  return `DEFAULT '{${e.map((e) => typeof e == "number" || typeof e == "boolean" ? String(e) : `"${String(e).replace(/\\/g, "\\\\").replace(/"/g, "\\\"")}"`).join(",").replace(/'/g, "''")}}'::${r}[]`;
247
- }, O = (e, t) => {
247
+ }, D = (e, t) => {
248
248
  let n = JSON.stringify(e).replace(/'/g, "''");
249
249
  return t === "postgres" ? `DEFAULT '${n}'::jsonb` : t === "mysql" || t === "mariadb" ? `DEFAULT (CAST('${n}' AS JSON))` : `DEFAULT '${n}'`;
250
- }, k = (e, t) => {
250
+ }, O = (e, t) => {
251
251
  switch (t) {
252
252
  case "postgres": return `"${e}" BIGSERIAL PRIMARY KEY`;
253
253
  case "mysql":
@@ -256,7 +256,7 @@ var _ = (e, t, n, r = 400) => {
256
256
  case "sqlite": return `"${e}" INTEGER PRIMARY KEY AUTOINCREMENT`;
257
257
  case "turso": return `"${e}" INTEGER PRIMARY KEY`;
258
258
  }
259
- }, be = (e, t) => {
259
+ }, k = (e, t) => {
260
260
  if (e === "restrict" && t === "mssql") return "NO ACTION";
261
261
  switch (e) {
262
262
  case "cascade": return "CASCADE";
@@ -269,33 +269,33 @@ var _ = (e, t, n, r = 400) => {
269
269
  if (r !== "mysql" && r !== "mariadb") return i;
270
270
  let a = n[t];
271
271
  if (!a) return i;
272
- let o = D(a, r).toUpperCase();
272
+ let o = E(a, r).toUpperCase();
273
273
  return o.endsWith("TEXT") || o.endsWith("BLOB") ? `${i}(${Se})` : i;
274
274
  }, we = (e, t) => {
275
275
  if (!e.generatedAs) return null;
276
276
  let { expr: n, stored: r } = e.generatedAs;
277
- if (t === "postgres") return r || E("[voltro:migrate] generated column requested as VIRTUAL but postgres only supports STORED — promoting"), `GENERATED ALWAYS AS (${n}) STORED`;
277
+ if (t === "postgres") return r || T("[voltro:migrate] generated column requested as VIRTUAL but postgres only supports STORED — promoting"), `GENERATED ALWAYS AS (${n}) STORED`;
278
278
  if (t === "mysql" || t === "mariadb") return `GENERATED ALWAYS AS (${n}) ${r ? "STORED" : "VIRTUAL"}`;
279
279
  if (t === "mssql") return `AS (${n})${r ? " PERSISTED" : ""}`;
280
280
  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.");
281
281
  return `GENERATED ALWAYS AS (${n}) ${r ? "STORED" : "VIRTUAL"}`;
282
282
  }, Te = (t, n, r, i, a = !1, o = !1) => {
283
- if (n.type === "id" && n.idScheme?.kind === "numeric") return k(t, r);
284
- let s = r === "mssql" && n.type === "text" && !n.generatedAs && n.maxLength === void 0 && i?.has(t) ? "NVARCHAR(450)" : D(n, r), c = [e(t, r), s];
283
+ if (n.type === "id" && n.idScheme?.kind === "numeric") return O(t, r);
284
+ let s = r === "mssql" && n.type === "text" && !n.generatedAs && n.maxLength === void 0 && i?.has(t) ? "NVARCHAR(450)" : E(n, r), c = [e(t, r), s];
285
285
  n.type === "id" && !o && c.push("PRIMARY KEY");
286
286
  let l = we(n, r);
287
287
  if (l) c.push(l);
288
288
  else {
289
289
  n.nullable || c.push("NOT NULL"), n.unique && n.type !== "id" && c.push("UNIQUE");
290
- let e = ve(n, r);
290
+ let e = ye(n, r);
291
291
  e && c.push(e);
292
292
  }
293
293
  if (n.type === "reference" && n.references && !a) {
294
294
  let t = n.references();
295
295
  c.push(`REFERENCES ${e(t.tableName, r)} (${e("id", r)})`);
296
- let i = be(n.onDelete ?? "restrict", r);
296
+ let i = k(n.onDelete ?? "restrict", r);
297
297
  c.push(`ON DELETE ${i}`);
298
- let a = be(n.refOnUpdate ?? "noAction", r);
298
+ let a = k(n.refOnUpdate ?? "noAction", r);
299
299
  a !== "NO ACTION" && c.push(`ON UPDATE ${a}`);
300
300
  }
301
301
  if (n.oneOf && n.oneOf.length > 0) {
@@ -348,21 +348,21 @@ var _ = (e, t, n, r = 400) => {
348
348
  using: " USING GIST",
349
349
  withSuffix: "",
350
350
  skip: !1
351
- } : (E(`[voltro:migrate] index '${e}' on '${n}': ${r} doesn't support GiST — falling back to btree. Spatial queries on this column will fall back to sequential scan.`), o);
351
+ } : (T(`[voltro:migrate] index '${e}' on '${n}': ${r} doesn't support GiST — falling back to btree. Spatial queries on this column will fall back to sequential scan.`), o);
352
352
  if (i === "gin") return r === "postgres" ? {
353
353
  using: " USING GIN",
354
354
  withSuffix: "",
355
355
  skip: !1
356
- } : r === "mysql" || r === "mariadb" ? (E(`[voltro:migrate] gin index '${e}' on '${n}': ${r} 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(...).`), {
356
+ } : r === "mysql" || r === "mariadb" ? (T(`[voltro:migrate] gin index '${e}' on '${n}': ${r} 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(...).`), {
357
357
  using: "",
358
358
  withSuffix: "",
359
359
  skip: !0
360
- }) : (E(`[voltro:migrate] gin index '${e}' on '${n}': ${r} has no GIN access method — falling back to btree. Containment/membership queries won't use this index efficiently.`), o);
360
+ }) : (T(`[voltro:migrate] gin index '${e}' on '${n}': ${r} has no GIN access method — falling back to btree. Containment/membership queries won't use this index efficiently.`), o);
361
361
  if (i === "brin") return r === "postgres" ? {
362
362
  using: " USING BRIN",
363
363
  withSuffix: "",
364
364
  skip: !1
365
- } : (E(`[voltro:migrate] brin index '${e}' on '${n}': ${r} has no BRIN access method — falling back to btree (larger on disk, but the range scan still works).`), o);
365
+ } : (T(`[voltro:migrate] brin index '${e}' on '${n}': ${r} has no BRIN access method — falling back to btree (larger on disk, but the range scan still works).`), o);
366
366
  if (i === "hnsw") {
367
367
  if (r === "postgres") {
368
368
  let e = a?.hnsw?.m ?? 16, n = a?.hnsw?.efConstruction ?? 64, r = a?.hnsw?.opclass ?? t(a?.hnsw?.distance);
@@ -373,7 +373,7 @@ var _ = (e, t, n, r = 400) => {
373
373
  skip: !1
374
374
  };
375
375
  }
376
- return E(`[voltro:migrate] hnsw index '${e}' on '${n}': ${r} has no pgvector / HNSW access method — skipping. Nearest-neighbour queries on this column fall back to a sequential scan.`), {
376
+ return T(`[voltro:migrate] hnsw index '${e}' on '${n}': ${r} has no pgvector / HNSW access method — skipping. Nearest-neighbour queries on this column fall back to a sequential scan.`), {
377
377
  using: "",
378
378
  withSuffix: "",
379
379
  skip: !0
@@ -406,15 +406,15 @@ var _ = (e, t, n, r = 400) => {
406
406
  let i = t.columns.map((t) => e(t, r)).join(", ");
407
407
  o.push(`CREATE FULLTEXT INDEX ${e(t.name, r)} ON ${e(n.tableName, r)} (${i});`);
408
408
  } else if (r === "turso") throw Error(`@voltro/sql-turso: full-text index '${t.name}' on '${n.tableName}' is not supported — Turso's MVCC mode has no FTS5 virtual tables. Drop .fullTextIndex(), or use the 'sqlite' / 'postgres' dialect for this table.`);
409
- else r === "sqlite" ? o.push(...De(n.tableName, t, r)) : E(`[voltro:migrate] full-text index '${t.name}' on '${n.tableName}': ${r} uses a ranked LIKE search at query time (no native FTS catalog required).`);
409
+ else r === "sqlite" ? o.push(...De(n.tableName, t, r)) : T(`[voltro:migrate] full-text index '${t.name}' on '${n.tableName}': ${r} uses a ranked LIKE search at query time (no native FTS catalog required).`);
410
410
  for (let e of n.appliedIndexes) {
411
411
  if ((r === "mariadb" || r === "mssql") && e.fields.some((e) => typeof e != "string" && "jsonPath" in e)) {
412
- E(`[voltro:migrate] json-path index '${e.name}' on '${n.tableName}': ${r} cannot index a JSON expression directly — skipping. For an indexed JSON path on ${r}, add a generated column for the path (text().generatedAs(...) / .stored()) and .index([...]) it, then filter on that column instead of jsonField(...).`);
412
+ T(`[voltro:migrate] json-path index '${e.name}' on '${n.tableName}': ${r} cannot index a JSON expression directly — skipping. For an indexed JSON path on ${r}, add a generated column for the path (text().generatedAs(...) / .stored()) and .index([...]) it, then filter on that column instead of jsonField(...).`);
413
413
  continue;
414
414
  }
415
415
  if (e.unique && e.where !== void 0 && e.where.length > 0 && (r === "mysql" || r === "mariadb")) throw Error(`@voltro/migrate: uniqueActive index '${e.name}' on '${n.tableName}' cannot be expressed on ${r} — 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 ${r}, or move this table to postgres/sqlite/mssql.`);
416
416
  let t = "";
417
- e.where !== void 0 && e.where.length > 0 && (r === "mysql" || r === "mariadb" ? E(`[voltro:migrate] partial index '${e.name}' on '${n.tableName}': ${r} does not support WHERE clauses on indexes — emitting a full index`) : t = ` WHERE ${e.where}`);
417
+ e.where !== void 0 && e.where.length > 0 && (r === "mysql" || r === "mariadb" ? T(`[voltro:migrate] partial index '${e.name}' on '${n.tableName}': ${r} does not support WHERE clauses on indexes — emitting a full index`) : t = ` WHERE ${e.where}`);
418
418
  let i = d(e.name, n.tableName, e.fields, e.kind, e.kindOptions, t, e.unique === !0);
419
419
  i !== "" && o.push(i), e.fields.every((e) => typeof e == "string") && s.add(c(e.fields));
420
420
  }
@@ -431,7 +431,7 @@ CREATE TRIGGER framework_changes_${e.tableName}
431
431
  AFTER INSERT OR UPDATE OR DELETE ON "${e.tableName}"
432
432
  FOR EACH ROW EXECUTE FUNCTION framework_notify_change();
433
433
  `.trim(), je = (e) => e.some((e) => Object.values(e.fields).some((e) => e.type === "vector")), Me = (e) => e.some((e) => Object.values(e.fields).some((e) => e.spatial !== void 0)), Ne = (e) => {
434
- let t = new Map(e.map((e) => [e.tableName, e])), n = re(e.map((e) => e.tableName), (e) => {
434
+ let t = new Map(e.map((e) => [e.tableName, e])), n = ne(e.map((e) => e.tableName), (e) => {
435
435
  let n = t.get(e);
436
436
  return n ? Object.entries(n.fields).flatMap(([e, n]) => {
437
437
  if (n.type !== "reference" || !n.references) return [];
@@ -442,7 +442,7 @@ FOR EACH ROW EXECUTE FUNCTION framework_notify_change();
442
442
  }] : [];
443
443
  }) : [];
444
444
  }), r = [];
445
- for (let t of e) for (let [e, i] of Object.entries(t.fields)) i.type !== "reference" || !i.references || n.has(x(t.tableName, e)) && r.push({
445
+ for (let t of e) for (let [e, i] of Object.entries(t.fields)) i.type !== "reference" || !i.references || n.has(S(t.tableName, e)) && r.push({
446
446
  table: t.tableName,
447
447
  column: e,
448
448
  targetTable: i.references().tableName,
@@ -453,7 +453,7 @@ FOR EACH ROW EXECUTE FUNCTION framework_notify_change();
453
453
  if (!(i.has(e.tableName) || a.has(e.tableName))) {
454
454
  a.add(e.tableName);
455
455
  for (let [r, i] of Object.entries(e.fields)) {
456
- if (i.type !== "reference" || !i.references || n.has(x(e.tableName, r))) continue;
456
+ if (i.type !== "reference" || !i.references || n.has(S(e.tableName, r))) continue;
457
457
  let a = i.references();
458
458
  if (a.tableName === e.tableName) continue;
459
459
  let o = t.get(a.tableName);
@@ -468,7 +468,7 @@ FOR EACH ROW EXECUTE FUNCTION framework_notify_change();
468
468
  cyclic: r
469
469
  };
470
470
  }, Pe = (t, n, r = null) => {
471
- let i = (t) => r ? `${e(r, n)}.${e(t, n)}` : e(t, n), a = `${t.table}_${t.column}_fkey`, o = be(t.onDelete, n), s = be(t.onUpdate, n), c = ` ON DELETE ${o}${s === "NO ACTION" ? "" : ` ON UPDATE ${s}`}`, l = (r) => `ADD CONSTRAINT ${e(a, n)} FOREIGN KEY ${r ? "IF NOT EXISTS " : ""}(${e(t.column, n)}) REFERENCES ${i(t.targetTable)} (${e("id", n)})${c}`;
471
+ let i = (t) => r ? `${e(r, n)}.${e(t, n)}` : e(t, n), a = `${t.table}_${t.column}_fkey`, o = k(t.onDelete, n), s = k(t.onUpdate, n), c = ` ON DELETE ${o}${s === "NO ACTION" ? "" : ` ON UPDATE ${s}`}`, l = (r) => `ADD CONSTRAINT ${e(a, n)} FOREIGN KEY ${r ? "IF NOT EXISTS " : ""}(${e(t.column, n)}) REFERENCES ${i(t.targetTable)} (${e("id", n)})${c}`;
472
472
  switch (n) {
473
473
  case "postgres": return [
474
474
  "DO $$ BEGIN",
@@ -528,7 +528,7 @@ BEGIN
528
528
  views: r
529
529
  };
530
530
  }, A = (e, t) => {
531
- let { tables: n, views: i } = Re(e), { sorted: a, cyclic: o } = Ne(n.map((e) => b(e, t))), s = Fe(o, t), c = [];
531
+ let { tables: n, views: i } = Re(e), { sorted: a, cyclic: o } = Ne(n.map((e) => x(e, t))), s = Fe(o, t), c = [];
532
532
  t === "postgres" && je(a) && c.push("CREATE EXTENSION IF NOT EXISTS vector;"), t === "postgres" && Me(a) && c.push("CREATE EXTENSION IF NOT EXISTS postgis;");
533
533
  let l = Le(a, t);
534
534
  l && c.push(l);
@@ -569,43 +569,29 @@ BEGIN
569
569
  t && d.push(t);
570
570
  }
571
571
  return d.join("\n\n") + "\n";
572
- }, Ve = (t, n) => {
573
- if (n !== "postgres") return A(t, n);
574
- let { sorted: r, cyclic: i } = Ne(t), a = Fe(i, n), o = [], s = Le(r, n);
575
- s && o.push(s);
576
- let c = Ie(r, n);
577
- c && o.push(c);
578
- for (let e of r) o.push(Ee(e, n, null, a.get(e.tableName)));
579
- for (let e of i) o.push(Pe(e, n));
580
- for (let t of r) {
581
- let r = Object.entries(t.fields);
582
- if (r.length === 0) continue;
583
- let i = r.map(([r, i]) => {
584
- let o = Te(r, i, n, void 0, a.get(t.tableName)?.has(r) ?? !1);
585
- return `ALTER TABLE ${e(t.tableName, n)} ADD COLUMN IF NOT EXISTS ${o};`;
586
- });
587
- o.push(i.join("\n"));
588
- }
589
- for (let e of r) {
590
- let t = Oe(e, n);
591
- t && o.push(t);
592
- }
593
- let l = r.filter((e) => e.isReactive);
594
- if (l.length > 0) {
595
- o.push(ke);
596
- for (let e of l) o.push(Ae(e));
597
- }
598
- return o.join("\n\n") + "\n";
572
+ }, Ve = (e, t) => {
573
+ let { sorted: n, cyclic: r } = Ne(e), i = Fe(r, t), a = [], o = Le(n, t);
574
+ o && a.push(o);
575
+ let s = Ie(n, t);
576
+ s && a.push(s);
577
+ for (let e of n) a.push(Ee(e, t, null, i.get(e.tableName)));
578
+ for (let e of r) a.push(Pe(e, t));
579
+ let c = n.filter((e) => e.isReactive);
580
+ if (c.length > 0) {
581
+ a.push(ke);
582
+ for (let e of c) a.push(Ae(e));
583
+ }
584
+ return a.join("\n\n") + "\n";
599
585
  }, He = (e, t = "postgres") => d.gen(function* () {
600
586
  let n = yield* p.SqlClient;
601
- yield* T(n, Ge(n, A(e, t), t)).pipe(d.orDie);
587
+ yield* _e(n, Ge(n, A(e, t), t)).pipe(d.orDie);
602
588
  }), Ue = (e, t) => {
603
589
  let n = t.cause ?? {};
604
590
  return (n.errno === 1061 || n.code === "ER_DUP_KEYNAME") && /^\s*CREATE\s+(UNIQUE\s+|FULLTEXT\s+)?INDEX\b/i.test(e);
605
591
  }, We = (e) => d.gen(function* () {
606
592
  let t = yield* p.SqlClient;
607
- for (let n of Ke(e)) process.env.VOLTRO_MIGRATE_DEBUG === "1" && _e.debug(`EXEC: ${n.replace(/\s+/g, " ").slice(0, 180)}`), yield* t.unsafe(n).pipe(d.catchIf((e) => Ue(n, e), () => d.void), d.tapError((e) => d.sync(() => {
608
- _e.error(_("migrate: statement failed", n, e, 200));
593
+ for (let n of Ke(e)) process.env.VOLTRO_MIGRATE_DEBUG === "1" && ve.debug(`EXEC: ${n.replace(/\s+/g, " ").slice(0, 180)}`), yield* t.unsafe(n).pipe(d.catchIf((e) => Ue(n, e), () => d.void), d.tapError((e) => d.sync(() => {
594
+ ve.error(_("migrate: statement failed", n, e, 200));
609
595
  })), d.orDieWith((e) => Error(_("migrate: statement failed", n, e, 400).trim())));
610
596
  }), Ge = (e, t, n) => (n === "turso" ? We(t) : e.withTransaction(We(t))).pipe(d.orDie), Ke = (e) => {
611
597
  let t = [], n = "", r = !1;
@@ -626,13 +612,13 @@ BEGIN
626
612
  await d.runPromise(He(e, n).pipe(d.provide(t)));
627
613
  }, Je = (e, t, n = "postgres") => d.gen(function* () {
628
614
  let r = Be(e, n, t), i = yield* p.SqlClient;
629
- yield* T(i, Ge(i, r, n)).pipe(d.orDie);
615
+ yield* _e(i, Ge(i, r, n)).pipe(d.orDie);
630
616
  }), Ye = async (e, t, n, r = "postgres") => {
631
617
  await d.runPromise(Je(e, t, r).pipe(d.provide(n)));
632
618
  }, Xe = async (e, t, n = "postgres") => {
633
619
  await d.runPromise(d.gen(function* () {
634
620
  let t = Ve(e, n), r = yield* p.SqlClient;
635
- yield* T(r, Ge(r, t, n)).pipe(d.orDie);
621
+ yield* _e(r, Ge(r, t, n)).pipe(d.orDie);
636
622
  }).pipe(d.provide(t)));
637
623
  }, Ze = (e) => {
638
624
  if (e == null) return e;
@@ -752,12 +738,13 @@ BEGIN
752
738
  unique: !0
753
739
  } : e);
754
740
  }
755
- let r = e.appliedPrimaryKey ?? [];
741
+ let r = e.appliedPrimaryKey ?? [], i = e.previousTableName;
756
742
  return {
757
743
  name: e.tableName,
758
744
  columns: n,
759
745
  indexes: rt(e),
760
- ...r.length > 0 ? { primaryKey: [...r] } : {}
746
+ ...r.length > 0 ? { primaryKey: [...r] } : {},
747
+ ...i === void 0 ? {} : { renamedFrom: i }
761
748
  };
762
749
  }, at = (e) => {
763
750
  let t = /* @__PURE__ */ new Map();
@@ -767,7 +754,7 @@ BEGIN
767
754
  t.set(e.name, n.name);
768
755
  }
769
756
  }, N = (e, t) => {
770
- let n = e.map((e) => it(b(e, t)));
757
+ let n = e.map((e) => it(x(e, t)));
771
758
  return at(n), { tables: n };
772
759
  }, ot = "framework_changes_", st = (e, t) => d.gen(function* () {
773
760
  let n = t.filter((e) => !e.tableName.startsWith("_voltro_"));
@@ -803,19 +790,19 @@ BEGIN
803
790
  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.`);
804
791
  }
805
792
  return t.length > 0 ? t.join("\n") : void 0;
806
- }, lt = /* @__PURE__ */ new Set(["voltro_isr_cache"]), P = (e) => lt.has(e) || e.startsWith("_voltro_") || e.startsWith("_cloud_") || e.startsWith("cluster_"), ut = /__dropped_\d{14}$/, dt = (e) => ut.test(e), ft = {
793
+ }, lt = /* @__PURE__ */ new Set(["voltro_isr_cache"]), ut = (e) => lt.has(e) || e.startsWith("_voltro_") || e.startsWith("_cloud_") || e.startsWith("cluster_"), dt = /__dropped_\d{14}$/, ft = (e) => dt.test(e), pt = {
807
794
  postgres: !0,
808
795
  mysql: !0,
809
796
  mariadb: !0,
810
797
  mssql: !0,
811
798
  sqlite: !0
812
- }, pt = {
799
+ }, mt = {
813
800
  postgres: !0,
814
801
  mysql: !1,
815
802
  mariadb: !1,
816
803
  mssql: !0,
817
804
  sqlite: !0
818
- }, mt = (e) => {
805
+ }, ht = (e) => {
819
806
  switch (e) {
820
807
  case "add-column":
821
808
  case "drop-column":
@@ -825,43 +812,43 @@ BEGIN
825
812
  case "add-foreign-key":
826
813
  case "add-unique":
827
814
  case "add-unique-composite":
828
- case "add-check": return pt;
829
- default: return ft;
815
+ case "add-check": return mt;
816
+ default: return pt;
830
817
  }
831
- }, ht = (e, t) => {
818
+ }, gt = (e, t) => {
832
819
  let n = new Map(t.tables.map((e) => [e.name, e]));
833
820
  return new Map(e.map((e) => [e.tableName, {
834
821
  table: e,
835
822
  snapshot: n.get(e.tableName),
836
823
  columnDefs: e.fields
837
824
  }]));
838
- }, F = (e) => {
825
+ }, P = (e) => {
839
826
  if (typeof e != "object" || !e) return JSON.stringify(e);
840
- if (Array.isArray(e)) return `[${e.map(F).join(",")}]`;
827
+ if (Array.isArray(e)) return `[${e.map(P).join(",")}]`;
841
828
  let t = e;
842
- return `{${Object.keys(t).sort().map((e) => `${JSON.stringify(e)}:${F(t[e])}`).join(",")}}`;
843
- }, gt = (e) => {
829
+ return `{${Object.keys(t).sort().map((e) => `${JSON.stringify(e)}:${P(t[e])}`).join(",")}}`;
830
+ }, _t = (e) => {
844
831
  if (!e.hasDefault || e.defaultValue === void 0 || e.defaultValue === null) return null;
845
832
  let t = e.defaultValue;
846
833
  if (typeof t == "boolean") return t ? "__BOOL_TRUE__" : "__BOOL_FALSE__";
847
834
  if (typeof t == "number") return String(t);
848
- if (typeof t != "string") return F(t);
835
+ if (typeof t != "string") return P(t);
849
836
  let n = t.trim(), r = n.toLowerCase().replace(/\s+/g, "");
850
837
  if (r === "now" || r === "now()" || /^current_timestamp(\(\d*\))?$/.test(r) || r === "sysutcdatetime()" || r === "sysdatetime()" || r === "getutcdate()" || r === "getdate()") return "__NOW__";
851
838
  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);
852
839
  if (o) try {
853
- return F(JSON.parse(o[1]));
840
+ return P(JSON.parse(o[1]));
854
841
  } catch {}
855
842
  if (a.startsWith("{") || a.startsWith("[")) try {
856
- return F(JSON.parse(a));
843
+ return P(JSON.parse(a));
857
844
  } catch {}
858
845
  return /^-?\d+(\.\d+)?$/.test(a) ? String(Number(a)) : a;
859
- }, _t = (e, t) => {
860
- let n = gt(e), r = gt(t);
846
+ }, vt = (e, t) => {
847
+ let n = _t(e), r = _t(t);
861
848
  if (n === r) return !0;
862
849
  let i = (e) => e === "1" || e === "true" ? "__BOOL_TRUE__" : e === "0" || e === "false" ? "__BOOL_FALSE__" : e;
863
850
  return i(n) === i(r);
864
- }, I = (e) => {
851
+ }, F = (e) => {
865
852
  if (!e) return null;
866
853
  let t = (e) => e === "restrict" ? "noAction" : e;
867
854
  return {
@@ -870,25 +857,25 @@ BEGIN
870
857
  onDelete: t(e.onDelete),
871
858
  onUpdate: t(e.onUpdate)
872
859
  };
873
- }, vt = (e, t) => {
860
+ }, yt = (e, t) => {
874
861
  let n = e && e.length > 0 ? e : void 0, r = t && t.length > 0 ? t : void 0;
875
862
  if (!n && !r) return !0;
876
863
  if (!n || !r || n.length !== r.length) return !1;
877
864
  let i = [...n].sort(), a = [...r].sort();
878
865
  return i.every((e, t) => e === a[t]);
879
- }, yt = (e, t) => {
866
+ }, bt = (e, t) => {
880
867
  try {
881
- let n = /\((\d+)\)/.exec(D(e, t));
868
+ let n = /\((\d+)\)/.exec(E(e, t));
882
869
  return n ? Number(n[1]) : void 0;
883
870
  } catch {
884
871
  return;
885
872
  }
886
- }, bt = (e, t, n) => n === void 0 || u(n) ? !0 : e.type !== "text" || t.type !== "text" || yt(e, n) === t.maxLength, xt = (e, t, n) => e.type === t.type && e.nullable === t.nullable && e.unique === t.unique && _t(e, t) && bt(e, t, n) && JSON.stringify(I(e.references)) === JSON.stringify(I(t.references)) && vt(e.oneOf, t.oneOf), St = (e, t) => t.oneOf && t.oneOf.length > 0 ? L({
873
+ }, xt = (e, t, n) => n === void 0 || u(n) ? !0 : e.type !== "text" || t.type !== "text" || bt(e, n) === t.maxLength, St = (e, t, n) => e.type === t.type && e.nullable === t.nullable && e.unique === t.unique && vt(e, t) && xt(e, t, n) && JSON.stringify(F(e.references)) === JSON.stringify(F(t.references)) && yt(e.oneOf, t.oneOf), Ct = (e, t) => t.oneOf && t.oneOf.length > 0 ? I({
887
874
  kind: "add-check",
888
875
  table: e,
889
876
  column: t.name,
890
877
  values: t.oneOf
891
- }, "safe", `enum-membership CHECK on ${e}.${t.name}`) : void 0, Ct = (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])), wt = (e, t, n) => {
878
+ }, "safe", `enum-membership CHECK on ${e}.${t.name}`) : void 0, wt = (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])), Tt = (e, t, n) => {
892
879
  let r = new Map(t.columns.map((e) => [e.name, e])), i = new Map(e.columns.map((e) => [e.name, e])), a = [], o = [], s = [];
893
880
  for (let t of e.columns) {
894
881
  let e = r.get(t.name);
@@ -896,7 +883,7 @@ BEGIN
896
883
  a.push(t);
897
884
  continue;
898
885
  }
899
- xt(t, e, n) || s.push({
886
+ St(t, e, n) || s.push({
900
887
  declared: t,
901
888
  live: e
902
889
  });
@@ -907,47 +894,47 @@ BEGIN
907
894
  removed: o,
908
895
  changed: s
909
896
  };
910
- }, Tt = (e, t) => {
897
+ }, Et = (e, t) => {
911
898
  let n = new Map(t.indexes.map((e) => [e.name, e])), r = new Map(e.indexes.map((e) => [e.name, e])), i = [], a = [];
912
899
  for (let t of e.indexes) {
913
900
  let e = n.get(t.name);
914
- (!e || !Ct(t, e)) && i.push(t);
901
+ (!e || !wt(t, e)) && i.push(t);
915
902
  }
916
903
  for (let e of t.indexes) r.has(e.name) || a.push(e);
917
904
  return {
918
905
  added: i,
919
906
  removed: a
920
907
  };
921
- }, L = (e, t, n, r) => ({
908
+ }, I = (e, t, n, r) => ({
922
909
  op: e,
923
910
  classification: t,
924
- atomicByDialect: mt(e.kind),
911
+ atomicByDialect: ht(e.kind),
925
912
  ...n ? { reason: n } : {},
926
913
  ...r ? { blocked: r } : {}
927
- }), Et = (e, t, n) => {
914
+ }), Dt = (e, t, n) => {
928
915
  let r = {
929
916
  kind: "add-column",
930
917
  table: e,
931
918
  column: t
932
919
  };
933
- 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` });
934
- }, Dt = (e, t, n) => {
920
+ return t.nullable ? I(r, "safe", "nullable column add — no backfill needed") : t.hasDefault && t.defaultValue !== void 0 ? I(r, "needs-default", "NOT NULL with literal default — DDL DEFAULT will populate existing rows") : n?.backfill ? I(r, "needs-backfill", `backfill declared (kind=${n.backfill.kind}) — applier will run 3-step add/update/set-not-null`) : I(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` });
921
+ }, Ot = (e, t, n) => {
935
922
  let r = {
936
923
  kind: "drop-column",
937
924
  table: e,
938
925
  column: t.name
939
926
  };
940
- 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` });
941
- }, Ot = (e, t, n, r) => L({
927
+ return n?.dropped ? I(r, "lossy", `column dropped via \`${t.name}: dropped()\` marker — intentional`) : I(r, "lossy", "column missing from declared schema", { fix: `if intentional, add \`${t.name}: dropped()\` to the schema. If a typo, restore the field` });
928
+ }, kt = (e, t, n, r, i) => I({
942
929
  kind: "create-table",
943
930
  table: e,
944
931
  columns: t,
945
932
  indexes: n,
946
933
  ...r && r.length > 0 ? { primaryKey: r } : {}
947
- }, "safe", "new table — no data to preserve"), kt = (e) => L({
934
+ }, "safe", i ?? "new table — no data to preserve"), At = (e) => I({
948
935
  kind: "drop-table",
949
936
  table: e
950
- }, "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" }), At = 5e4, jt = (e, t, n, r) => {
937
+ }, "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" }), jt = 5e4, Mt = (e, t, n, r) => {
951
938
  let i = (n ?? 0) >= r, a;
952
939
  return a = t.unique ? t.columns.length === 1 ? {
953
940
  kind: "add-unique",
@@ -962,16 +949,16 @@ BEGIN
962
949
  kind: "add-index",
963
950
  table: e,
964
951
  index: t
965
- }, 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");
966
- }, Mt = (e, t) => t.unique && t.columns.length > 1 ? L({
952
+ }, i ? I(a, "online-required", `online build on ${n} rows — CONCURRENTLY / INPLACE / WITH(ONLINE=ON) depending on dialect`) : I(a, "safe", t.unique ? t.columns.length === 1 ? "add unique constraint" : "add composite UNIQUE constraint" : "add B-tree index");
953
+ }, Nt = (e, t) => t.unique && t.columns.length > 1 ? I({
967
954
  kind: "drop-unique-composite",
968
955
  table: e,
969
956
  name: t.name
970
- }, "safe", "drop composite UNIQUE constraint (no data loss — constraint is derived metadata)") : L({
957
+ }, "safe", "drop composite UNIQUE constraint (no data loss — constraint is derived metadata)") : I({
971
958
  kind: "drop-index",
972
959
  table: e,
973
960
  index: t.name
974
- }, "safe", "drop index (no data loss — index is derived data)"), Nt = (e, t) => {
961
+ }, "safe", "drop index (no data loss — index is derived data)"), Pt = (e, t) => {
975
962
  if (e === "reference") return "text";
976
963
  switch (t) {
977
964
  case "sqlite":
@@ -979,7 +966,7 @@ BEGIN
979
966
  case "mssql": return e === "json" ? "text" : e;
980
967
  default: return e;
981
968
  }
982
- }, Pt = (e, t, n, r, i, a) => {
969
+ }, Ft = (e, t, n, r, i, a) => {
983
970
  let o = [];
984
971
  if (t.nullable !== n.nullable) {
985
972
  let n = {
@@ -988,7 +975,7 @@ BEGIN
988
975
  column: t.name,
989
976
  toNullable: t.nullable
990
977
  };
991
- o.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`));
978
+ o.push(t.nullable ? I(n, "safe", `loosen ${e}.${t.name} to nullable`) : I(n, "needs-backfill", `tighten ${e}.${t.name} to NOT NULL — existing rows must already be non-null`));
992
979
  }
993
980
  if (t.unique !== n.unique) if (t.unique) {
994
981
  let n = {
@@ -996,13 +983,13 @@ BEGIN
996
983
  table: e,
997
984
  column: t.name
998
985
  }, r = (i ?? 0) >= a;
999
- o.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)`));
1000
- } else o.push(L({
986
+ o.push(r ? I(n, "online-required", `online unique build on ${i} rows — CONCURRENTLY / INPLACE / WITH(ONLINE=ON) depending on dialect`) : I(n, "safe", `add unique constraint on ${e}.${t.name} — existing rows must already be distinct (else the DB rejects at migrate)`));
987
+ } else o.push(I({
1001
988
  kind: "drop-unique",
1002
989
  table: e,
1003
990
  column: t.name
1004
991
  }, "safe", `drop unique constraint on ${e}.${t.name} — constraint is derived metadata, no data loss`));
1005
- if (Nt(t.type, r) !== Nt(n.type, r)) {
992
+ if (Pt(t.type, r) !== Pt(n.type, r)) {
1006
993
  let r = t.narrowedFrom;
1007
994
  if (r && r.from === n.type) {
1008
995
  let i = {
@@ -1013,7 +1000,7 @@ BEGIN
1013
1000
  to: t.type,
1014
1001
  ...r.using === void 0 ? {} : { using: r.using }
1015
1002
  };
1016
- o.push(L(i, "needs-backfill", `type change ${n.type} → ${t.type} on ${e}.${t.name} — narrowedFrom('${r.from}') declared` + (r.using ? ` with USING ${r.using}` : " (implicit cast)")));
1003
+ o.push(I(i, "needs-backfill", `type change ${n.type} → ${t.type} on ${e}.${t.name} — narrowedFrom('${r.from}') declared` + (r.using ? ` with USING ${r.using}` : " (implicit cast)")));
1017
1004
  } else {
1018
1005
  let r = {
1019
1006
  kind: "alter-column-type",
@@ -1022,20 +1009,20 @@ BEGIN
1022
1009
  from: n.type,
1023
1010
  to: t.type
1024
1011
  };
1025
- o.push(L(r, "lossy", `type change ${n.type} → ${t.type} on ${e}.${t.name} may not be value-preserving`, { fix: `acknowledge it on the column: \`.narrowedFrom('${n.type}', { using: '${t.name}::${t.type}' })\` (drop \`using\` if the cast is implicit), or use a file-based migration` }));
1012
+ o.push(I(r, "lossy", `type change ${n.type} → ${t.type} on ${e}.${t.name} may not be value-preserving`, { fix: `acknowledge it on the column: \`.narrowedFrom('${n.type}', { using: '${t.name}::${t.type}' })\` (drop \`using\` if the cast is implicit), or use a file-based migration` }));
1026
1013
  }
1027
1014
  }
1028
1015
  if (t.type === "text" && n.type === "text" && !u(r ?? "postgres") && t.maxLength !== n.maxLength) {
1029
1016
  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})`;
1030
- o.push(L({
1017
+ o.push(I({
1031
1018
  kind: "alter-column-type",
1032
1019
  table: e,
1033
1020
  column: t.name,
1034
1021
  from: "text",
1035
1022
  to: "text"
1036
- }, 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)}`, r ? void 0 : { fix: `check first: SELECT COUNT(*) FROM ${e} WHERE LENGTH(${t.name}) > ${String(t.maxLength)}` }));
1023
+ }, 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)}`));
1037
1024
  }
1038
- if (!_t(t, n)) {
1025
+ if (!vt(t, n)) {
1039
1026
  let n = {
1040
1027
  kind: "alter-column-default",
1041
1028
  table: e,
@@ -1043,18 +1030,18 @@ BEGIN
1043
1030
  hasDefault: t.hasDefault,
1044
1031
  ...t.defaultValue === void 0 ? {} : { defaultValue: t.defaultValue }
1045
1032
  };
1046
- o.push(L(n, "safe", `default change on ${e}.${t.name} affects only future inserts`));
1033
+ o.push(I(n, "safe", `default change on ${e}.${t.name} affects only future inserts`));
1047
1034
  }
1048
- if (!vt(t.oneOf, n.oneOf)) {
1049
- n.oneOf && n.oneOf.length > 0 && o.push(L({
1035
+ if (!yt(t.oneOf, n.oneOf)) {
1036
+ n.oneOf && n.oneOf.length > 0 && o.push(I({
1050
1037
  kind: "drop-check",
1051
1038
  table: e,
1052
1039
  column: t.name
1053
1040
  }, "safe", `drop stale enum CHECK on ${e}.${t.name}`));
1054
- let r = St(e, t);
1041
+ let r = Ct(e, t);
1055
1042
  r && o.push(r);
1056
1043
  }
1057
- if (JSON.stringify(I(t.references)) !== JSON.stringify(I(n.references)) && (n.references && o.push(L({
1044
+ if (JSON.stringify(F(t.references)) !== JSON.stringify(F(n.references)) && (n.references && o.push(I({
1058
1045
  kind: "drop-foreign-key",
1059
1046
  table: e,
1060
1047
  column: t.name
@@ -1068,17 +1055,17 @@ BEGIN
1068
1055
  ...t.references.onDelete ? { onDelete: t.references.onDelete } : {},
1069
1056
  ...t.references.onUpdate ? { onUpdate: t.references.onUpdate } : {}
1070
1057
  };
1071
- r === "null" && !t.nullable ? o.push(L(i, "lossy", `add FK ${e}.${t.name} → ${n}: 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` })) : r === "null" || r === "delete" ? o.push(L({
1058
+ r === "null" && !t.nullable ? o.push(I(i, "lossy", `add FK ${e}.${t.name} → ${n}: 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` })) : r === "null" || r === "delete" ? o.push(I({
1072
1059
  ...i,
1073
1060
  orphanPolicy: r
1074
- }, "lossy", r === "delete" ? `add FK ${e}.${t.name} → ${n}: orphanPolicy 'delete' first DELETES rows whose ${t.name} points at a missing ${n}` : `add FK ${e}.${t.name} → ${n}: orphanPolicy 'null' first NULLs ${t.name} where it points at a missing ${n}`)) : o.push(L(i, "needs-backfill", `add FK ${e}.${t.name} → ${n} — existing rows must already reference a valid ${n} (else set orphanPolicy:'null'/'delete')`));
1061
+ }, "lossy", r === "delete" ? `add FK ${e}.${t.name} → ${n}: orphanPolicy 'delete' first DELETES rows whose ${t.name} points at a missing ${n}` : `add FK ${e}.${t.name} → ${n}: orphanPolicy 'null' first NULLs ${t.name} where it points at a missing ${n}`)) : o.push(I(i, "needs-backfill", `add FK ${e}.${t.name} → ${n} — existing rows must already reference a valid ${n} (else set orphanPolicy:'null'/'delete')`));
1075
1062
  }
1076
1063
  return o;
1077
- }, Ft = (e, t, n) => {
1064
+ }, It = (e, t, n) => {
1078
1065
  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));
1079
1066
  for (let [n, c] of Object.entries(t)) {
1080
1067
  let t = c.renamedFrom;
1081
- t && o.has(t) && s.has(n) && (i.add(n), a.add(t), r.push(L({
1068
+ t && o.has(t) && s.has(n) && (i.add(n), a.add(t), r.push(I({
1082
1069
  kind: "rename-column",
1083
1070
  table: e.tableName,
1084
1071
  from: t,
@@ -1090,7 +1077,109 @@ BEGIN
1090
1077
  consumedAddedNames: i,
1091
1078
  consumedRemovedNames: a
1092
1079
  };
1093
- }, It = (e) => {
1080
+ }, Lt = /* @__PURE__ */ new Set([
1081
+ "postgres",
1082
+ "mysql",
1083
+ "mariadb",
1084
+ "mssql"
1085
+ ]), Rt = {
1086
+ ops: [],
1087
+ consumedAddedNames: /* @__PURE__ */ new Set(),
1088
+ consumedRemovedNames: /* @__PURE__ */ new Set()
1089
+ }, zt = (e) => !e.unique && !e.expression, Bt = (e, t, n, r, i) => {
1090
+ if (i === void 0 || !Lt.has(i)) return Rt;
1091
+ let a = t.added.filter((e) => zt(e) && !r.has(e.name));
1092
+ if (a.length === 0) return Rt;
1093
+ 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();
1094
+ for (let n of t.removed) {
1095
+ if (!zt(n)) continue;
1096
+ let t = o(n), r = a.filter((e) => !l.has(e.name) && s(e) === t);
1097
+ if (r.length !== 1) continue;
1098
+ let i = r[0];
1099
+ i.name !== n.name && (l.add(i.name), u.add(n.name), c.push(I({
1100
+ kind: "rename-index",
1101
+ table: e,
1102
+ from: n.name,
1103
+ to: i.name
1104
+ }, "safe", "rename index in place — catalog-only, no rebuild")));
1105
+ }
1106
+ return {
1107
+ ops: c,
1108
+ consumedAddedNames: l,
1109
+ consumedRemovedNames: u
1110
+ };
1111
+ }, Vt = (e, t, n) => {
1112
+ let r = [], i = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Set(), o = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Set();
1113
+ for (let t of e.tables) t.renamedFrom !== void 0 && (s.set(t.renamedFrom, (s.get(t.renamedFrom) ?? 0) + 1), c.add(t.renamedFrom));
1114
+ for (let c of e.tables) {
1115
+ let e = c.renamedFrom;
1116
+ if (e !== void 0 && e !== c.name && t.has(e)) {
1117
+ if (t.has(c.name)) {
1118
+ r.push(I({
1119
+ kind: "rename-table",
1120
+ from: e,
1121
+ to: c.name
1122
+ }, "needs-rename-annotation", `.renamedFrom('${e}') cannot be applied — both '${e}' and '${c.name}' exist in the database`, { fix: `decide which holds the real rows: move them into '${c.name}' and drop '${e}', or drop the empty '${c.name}' so the rename can run. '${e}' is left untouched until you do.` }));
1123
+ continue;
1124
+ }
1125
+ if (n.has(e)) {
1126
+ o.set(c.name, `.renamedFrom('${e}') NOT applied — '${e}' is still declared by this schema, so it belongs to that declaration. This table is created empty; that is the intended outcome when an app owns a table of the same name.`);
1127
+ continue;
1128
+ }
1129
+ if ((s.get(e) ?? 0) !== 1) {
1130
+ r.push(I({
1131
+ kind: "rename-table",
1132
+ from: e,
1133
+ to: c.name
1134
+ }, "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.` }));
1135
+ continue;
1136
+ }
1137
+ i.set(c.name, e), a.add(e), r.push(I({
1138
+ kind: "rename-table",
1139
+ from: e,
1140
+ to: c.name
1141
+ }, "safe", `rename via \`.renamedFrom('${e}')\` — catalog-only, the rows stay put`));
1142
+ }
1143
+ }
1144
+ return {
1145
+ ops: r,
1146
+ renamedInto: i,
1147
+ renamedFromNames: a,
1148
+ claimedOldNames: c,
1149
+ refusals: o
1150
+ };
1151
+ }, Ht = (e, t, n, r) => {
1152
+ if (t === void 0) return {
1153
+ live: e,
1154
+ ops: []
1155
+ };
1156
+ let i = r !== void 0 && Lt.has(r), a = [], o = e.indexes.map((e) => {
1157
+ if (!e.name.startsWith(t)) return e;
1158
+ let r = `${n}${e.name.slice(t.length)}`;
1159
+ return r === e.name ? e : e.name === `${t}_pkey` ? {
1160
+ ...e,
1161
+ name: r,
1162
+ table: n
1163
+ } : i ? (a.push(I({
1164
+ kind: "rename-index",
1165
+ table: n,
1166
+ from: e.name,
1167
+ to: r
1168
+ }, "safe", "auto-named index follows its renamed table — catalog-only, no rebuild")), {
1169
+ ...e,
1170
+ name: r,
1171
+ table: n
1172
+ }) : e;
1173
+ });
1174
+ return {
1175
+ live: {
1176
+ ...e,
1177
+ indexes: o,
1178
+ name: n
1179
+ },
1180
+ ops: a
1181
+ };
1182
+ }, Ut = (e) => {
1094
1183
  let t = {
1095
1184
  safe: 0,
1096
1185
  needsDefault: 0,
@@ -1125,46 +1214,51 @@ BEGIN
1125
1214
  break;
1126
1215
  }
1127
1216
  return t;
1128
- }, Lt = (e) => {
1129
- let t = N(e.declared, e.dialect), n = ht(e.declared, t), r = new Map(e.live.tables.map((e) => [e.name, e])), i = e.onlineAfter ?? At, a = [];
1130
- for (let e of t.tables) if (!r.has(e.name)) {
1131
- a.push(Ot(e.name, e.columns, e.indexes, e.primaryKey));
1217
+ }, Wt = (e) => {
1218
+ let t = N(e.declared, e.dialect), n = gt(e.declared, t), r = new Map(e.live.tables.map((e) => [e.name, e])), i = e.onlineAfter ?? jt, a = [], o = Vt(t, r, n);
1219
+ a.push(...o.ops);
1220
+ for (let e of t.tables) if (!o.renamedInto.has(e.name) && !r.has(e.name)) {
1221
+ a.push(kt(e.name, e.columns, e.indexes, e.primaryKey, o.refusals.get(e.name)));
1132
1222
  for (let t of e.columns) {
1133
- let n = St(e.name, t);
1223
+ let n = Ct(e.name, t);
1134
1224
  n && a.push(n);
1135
1225
  }
1136
1226
  }
1137
- let o = new Set(e.ignoreTables ?? []);
1138
- for (let t of e.live.tables) n.has(t.name) || P(t.name) || dt(t.name) || o.has(t.name) || a.push(kt(t.name));
1139
- for (let o of t.tables) {
1140
- let t = r.get(o.name);
1141
- if (!t) continue;
1142
- let s = n.get(o.name), c = wt(o, t, e.dialect), l = Tt(o, t), u = Ft(s.table, s.columnDefs, c);
1143
- a.push(...u.ops);
1144
- for (let e of c.removed) {
1145
- if (u.consumedRemovedNames.has(e.name) || dt(e.name)) continue;
1146
- let t = s.columnDefs[e.name];
1147
- a.push(Dt(o.name, e, t));
1227
+ let s = new Set(e.ignoreTables ?? []);
1228
+ for (let t of e.live.tables) n.has(t.name) || o.claimedOldNames.has(t.name) || ut(t.name) || ft(t.name) || s.has(t.name) || a.push(At(t.name));
1229
+ for (let s of t.tables) {
1230
+ let t = o.renamedInto.get(s.name), c = r.get(s.name) ?? (t === void 0 ? void 0 : r.get(t));
1231
+ if (!c) continue;
1232
+ let l = Ht(c, t, s.name, e.dialect);
1233
+ a.push(...l.ops);
1234
+ let u = l.live, d = n.get(s.name), f = Tt(s, u, e.dialect), p = Et(s, u), m = It(d.table, d.columnDefs, f);
1235
+ a.push(...m.ops);
1236
+ for (let e of f.removed) {
1237
+ if (m.consumedRemovedNames.has(e.name) || ft(e.name)) continue;
1238
+ let t = d.columnDefs[e.name];
1239
+ a.push(Ot(s.name, e, t));
1148
1240
  }
1149
- for (let e of c.added) {
1150
- if (u.consumedAddedNames.has(e.name)) continue;
1151
- let t = s.columnDefs[e.name];
1152
- a.push(Et(o.name, e, t));
1153
- let n = St(o.name, e);
1241
+ for (let e of f.added) {
1242
+ if (m.consumedAddedNames.has(e.name)) continue;
1243
+ let t = d.columnDefs[e.name];
1244
+ a.push(Dt(s.name, e, t));
1245
+ let n = Ct(s.name, e);
1154
1246
  n && a.push(n);
1155
1247
  }
1156
- for (let e of l.added) a.push(jt(o.name, e, t.rowCount, i));
1157
- for (let e of l.removed) a.push(Mt(o.name, e));
1158
- for (let { declared: n, live: r } of c.changed) a.push(...Pt(o.name, n, r, e.dialect, t.rowCount, i));
1159
- }
1160
- let s = new Set(a.flatMap((e) => e.op.kind === "create-table" ? [e.op.table] : [])), c = new Map(t.tables.map((e) => [e.name, e])), l = (e) => {
1161
- let t = c.get(e);
1162
- return t ? t.columns.flatMap((e) => e.references && s.has(e.references.table) ? [{
1248
+ let h = new Map(m.ops.flatMap((e) => e.op.kind === "rename-column" ? [[e.op.from, e.op.to]] : [])), g = Bt(s.name, p, h, new Set(u.indexes.map((e) => e.name)), e.dialect);
1249
+ a.push(...g.ops);
1250
+ for (let e of p.added) g.consumedAddedNames.has(e.name) || a.push(Mt(s.name, e, u.rowCount, i));
1251
+ for (let e of p.removed) g.consumedRemovedNames.has(e.name) || a.push(Nt(s.name, e));
1252
+ for (let { declared: t, live: n } of f.changed) a.push(...Ft(s.name, t, n, e.dialect, u.rowCount, i));
1253
+ }
1254
+ 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) => {
1255
+ let t = l.get(e);
1256
+ return t ? t.columns.flatMap((e) => e.references && c.has(e.references.table) ? [{
1163
1257
  column: e.name,
1164
1258
  target: e.references.table
1165
1259
  }] : []) : [];
1166
- }, u = re([...s], l), d = [];
1167
- for (let e of t.tables) if (s.has(e.name)) for (let t of e.columns) !t.references || !u.has(x(e.name, t.name)) || d.push(L({
1260
+ }, d = ne([...c], u), f = [];
1261
+ for (let e of t.tables) if (c.has(e.name)) for (let t of e.columns) !t.references || !d.has(S(e.name, t.name)) || f.push(I({
1168
1262
  kind: "add-foreign-key",
1169
1263
  table: e.name,
1170
1264
  column: t.name,
@@ -1173,14 +1267,14 @@ BEGIN
1173
1267
  ...t.references.onDelete ? { onDelete: t.references.onDelete } : {},
1174
1268
  ...t.references.onUpdate ? { onUpdate: t.references.onUpdate } : {}
1175
1269
  }, "safe", `deferred FK ${e.name}.${t.name} → ${t.references.table} — breaks a create-time table cycle`));
1176
- if (u.size > 0) {
1270
+ if (d.size > 0) {
1177
1271
  let e = (e) => e.references ? Object.fromEntries(Object.entries(e).filter(([e]) => e !== "references")) : e;
1178
1272
  for (let t = 0; t < a.length; t += 1) {
1179
1273
  let n = a[t];
1180
1274
  if (n.op.kind !== "create-table") continue;
1181
1275
  let r = n.op;
1182
- if (!r.columns.some((e) => u.has(x(r.table, e.name)))) continue;
1183
- let i = r.columns.map((t) => u.has(x(r.table, t.name)) ? e(t) : t);
1276
+ if (!r.columns.some((e) => d.has(S(r.table, e.name)))) continue;
1277
+ let i = r.columns.map((t) => d.has(S(r.table, t.name)) ? e(t) : t);
1184
1278
  a[t] = {
1185
1279
  ...n,
1186
1280
  op: {
@@ -1189,26 +1283,27 @@ BEGIN
1189
1283
  }
1190
1284
  };
1191
1285
  }
1192
- a.push(...d);
1286
+ a.push(...f);
1193
1287
  }
1194
- let f = new Map(t.tables.map((e) => [e.name, e])), p = /* @__PURE__ */ new Map(), m = (e, t = /* @__PURE__ */ new Set()) => {
1195
- let n = p.get(e);
1288
+ let p = new Map(t.tables.map((e) => [e.name, e])), m = /* @__PURE__ */ new Map(), h = (e, t = /* @__PURE__ */ new Set()) => {
1289
+ let n = m.get(e);
1196
1290
  if (n !== void 0) return n;
1197
1291
  if (t.has(e)) return 0;
1198
- let r = f.get(e);
1292
+ let r = p.get(e);
1199
1293
  if (!r) return 0;
1200
1294
  let i = new Set(t).add(e), a = 0;
1201
1295
  for (let t of r.columns) {
1202
1296
  let n = t.references?.table;
1203
- n && n !== e && !u.has(x(e, t.name)) && (a = Math.max(a, m(n, i) + 1));
1297
+ n && n !== e && !d.has(S(e, t.name)) && (a = Math.max(a, h(n, i) + 1));
1204
1298
  }
1205
- return p.set(e, a), a;
1206
- }, h = (e) => e === "create-table" ? 0 : e === "drop-table" ? 2 : 1, g = (e) => {
1299
+ return m.set(e, a), a;
1300
+ }, g = (e) => e === "rename-table" ? -1 : e === "create-table" ? 0 : e === "drop-table" ? 2 : 1, ee = (e) => {
1207
1301
  let t = "table" in e ? e.table : "";
1208
- return e.kind === "create-table" ? m(t) : e.kind === "drop-table" ? -m(t) : 0;
1209
- }, ee = {
1302
+ return e.kind === "create-table" ? h(t) : e.kind === "drop-table" ? -h(t) : 0;
1303
+ }, _ = {
1210
1304
  "add-column": 0,
1211
1305
  "rename-column": 1,
1306
+ "rename-index": 1,
1212
1307
  "alter-column-nullability": 2,
1213
1308
  "alter-column-type": 2,
1214
1309
  "alter-column-default": 2,
@@ -1223,23 +1318,23 @@ BEGIN
1223
1318
  "add-unique-composite": 5,
1224
1319
  "add-foreign-key": 5,
1225
1320
  "add-check": 5
1226
- }, _ = (e) => ee[e] ?? 9, v = [...a].sort((e, t) => {
1227
- let n = h(e.op.kind), r = h(t.op.kind);
1321
+ }, v = (e) => _[e] ?? 9, y = [...a].sort((e, t) => {
1322
+ let n = g(e.op.kind), r = g(t.op.kind);
1228
1323
  if (n !== r) return n - r;
1229
- let i = g(e.op), a = g(t.op);
1324
+ let i = ee(e.op), a = ee(t.op);
1230
1325
  if (i !== a) return i - a;
1231
1326
  let o = "table" in e.op ? e.op.table : "", s = "table" in t.op ? t.op.table : "";
1232
1327
  if (o !== s) return o.localeCompare(s);
1233
- let c = _(e.op.kind), l = _(t.op.kind);
1328
+ let c = v(e.op.kind), l = v(t.op.kind);
1234
1329
  return c === l ? e.op.kind.localeCompare(t.op.kind) : c - l;
1235
1330
  });
1236
1331
  return {
1237
- operations: v,
1332
+ operations: y,
1238
1333
  fromFingerprint: j(e.live),
1239
1334
  toFingerprint: j(t),
1240
- summary: It(v)
1335
+ summary: Ut(y)
1241
1336
  };
1242
- }, Rt = (e) => {
1337
+ }, Gt = (e) => {
1243
1338
  let t = /[`"[]?([A-Za-z_][A-Za-z0-9_]*)[`"\]]?\s*(?:in\b|=)/i.exec(e);
1244
1339
  if (!t) return null;
1245
1340
  let n = [...e.matchAll(/'((?:[^']|'')*)'/g)].map((e) => e[1].replace(/''/g, "'"));
@@ -1247,7 +1342,7 @@ BEGIN
1247
1342
  column: t[1],
1248
1343
  values: n
1249
1344
  };
1250
- }, zt = (e, t) => {
1345
+ }, Kt = (e, t) => {
1251
1346
  if (t === "vector") return "vector";
1252
1347
  switch (e) {
1253
1348
  case "text":
@@ -1274,7 +1369,7 @@ BEGIN
1274
1369
  case "USER-DEFINED": return "text";
1275
1370
  default: return "text";
1276
1371
  }
1277
- }, R = (e) => {
1372
+ }, L = (e) => {
1278
1373
  switch (e.toUpperCase()) {
1279
1374
  case "CASCADE": return "cascade";
1280
1375
  case "RESTRICT": return "restrict";
@@ -1282,25 +1377,25 @@ BEGIN
1282
1377
  case "SET DEFAULT": return "noAction";
1283
1378
  default: return "noAction";
1284
1379
  }
1285
- }, Bt = (e, t) => {
1380
+ }, qt = (e, t) => {
1286
1381
  let n = e !== void 0 && e !== "" ? Number(e) : NaN;
1287
1382
  return Number.isInteger(n) && n > 0 ? n : t;
1288
- }, Vt = () => Bt(process.env.VOLTRO_INTROSPECT_BATCH, 20), Ht = 300, Ut = () => {
1383
+ }, Jt = () => qt(process.env.VOLTRO_INTROSPECT_BATCH, 20), Yt = 300, Xt = () => {
1289
1384
  let e = process.env.VOLTRO_INTROSPECT_TIMEOUT_MS;
1290
- return e !== void 0 && e.trim() === "0" ? 0 : Bt(e, 3e4);
1291
- }, Wt = (e, t) => {
1385
+ return e !== void 0 && e.trim() === "0" ? 0 : qt(e, 3e4);
1386
+ }, Zt = (e, t) => {
1292
1387
  let n = Number.isFinite(t) && t >= 1 ? Math.floor(t) : 1, r = [];
1293
1388
  for (let t = 0; t < e.length; t += n) r.push(e.slice(t, t + n));
1294
1389
  return r;
1295
- }, Gt = (e) => {
1296
- let t = Ut(), n = d.gen(function* () {
1390
+ }, Qt = (e) => {
1391
+ let t = Xt(), n = d.gen(function* () {
1297
1392
  t > 0 && (yield* e.unsafe(`SET LOCAL statement_timeout = ${t}`));
1298
- let n = (t) => e.unsafe("(" + t.map((e) => `'${e.replace(/'/g, "''")}'`).join(", ") + ")"), r = (t) => e.unsafe(String(Math.max(0, Math.trunc(t)))), i = Vt(), a = (e, t) => d.gen(function* () {
1393
+ let n = (t) => e.unsafe("(" + t.map((e) => `'${e.replace(/'/g, "''")}'`).join(", ") + ")"), r = (t) => e.unsafe(String(Math.max(0, Math.trunc(t)))), i = Jt(), a = (e, t) => d.gen(function* () {
1299
1394
  let r = [];
1300
- for (let a of Wt(e, i)) a.length !== 0 && r.push(...yield* t(n(a)));
1395
+ for (let a of Zt(e, i)) a.length !== 0 && r.push(...yield* t(n(a)));
1301
1396
  return r;
1302
1397
  }), o = [];
1303
- for (let t = 0;; t += Ht) {
1398
+ for (let t = 0;; t += Yt) {
1304
1399
  let n = yield* e`
1305
1400
  SELECT c.relname AS table_name,
1306
1401
  COALESCE(c.reltuples::bigint, 0) AS row_count
@@ -1308,9 +1403,9 @@ BEGIN
1308
1403
  JOIN pg_namespace n ON n.oid = c.relnamespace
1309
1404
  WHERE n.nspname = current_schema() AND c.relkind = 'r'
1310
1405
  ORDER BY c.relname
1311
- LIMIT ${r(Ht)} OFFSET ${r(t)}
1406
+ LIMIT ${r(Yt)} OFFSET ${r(t)}
1312
1407
  `;
1313
- if (o.push(...n), n.length < Ht) break;
1408
+ if (o.push(...n), n.length < Yt) break;
1314
1409
  }
1315
1410
  let s = /* @__PURE__ */ new Set(), c = [];
1316
1411
  for (let e of o) s.has(e.table_name) || (s.add(e.table_name), c.push(e));
@@ -1396,7 +1491,7 @@ BEGIN
1396
1491
  AND c.relname IN ${t}
1397
1492
  )
1398
1493
  SELECT * FROM ix ORDER BY table_name, index_name, position
1399
- `), _ = /* @__PURE__ */ new Map(), v = /* @__PURE__ */ new Map(), te = /* @__PURE__ */ new Map(), y = /* @__PURE__ */ new Map(), ne = /* @__PURE__ */ new Map(), b = /* @__PURE__ */ new Map();
1494
+ `), _ = /* @__PURE__ */ new Map(), v = /* @__PURE__ */ new Map(), y = /* @__PURE__ */ new Map(), b = /* @__PURE__ */ new Map(), te = /* @__PURE__ */ new Map(), x = /* @__PURE__ */ new Map();
1400
1495
  for (let e of u) {
1401
1496
  let t = _.get(e.table_name);
1402
1497
  t || (t = [], _.set(e.table_name, t)), t.push(e);
@@ -1405,25 +1500,25 @@ BEGIN
1405
1500
  let t = v.get(e.table_name);
1406
1501
  t || (t = /* @__PURE__ */ new Set(), v.set(e.table_name, t)), t.add(e.column_name);
1407
1502
  }
1408
- let x = /* @__PURE__ */ new Map();
1503
+ let S = /* @__PURE__ */ new Map();
1409
1504
  for (let e of p) {
1410
- let t = `${e.table_name}\u0000${e.constraint_name}`, n = x.get(t);
1505
+ let t = `${e.table_name}\u0000${e.constraint_name}`, n = S.get(t);
1411
1506
  n || (n = {
1412
1507
  table: e.table_name,
1413
1508
  columns: []
1414
- }, x.set(t, n)), n.columns.push({
1509
+ }, S.set(t, n)), n.columns.push({
1415
1510
  name: e.column_name,
1416
1511
  position: e.position
1417
1512
  });
1418
1513
  }
1419
- for (let [e, t] of x) {
1514
+ for (let [e, t] of S) {
1420
1515
  let n = [...t.columns].sort((e, t) => e.position - t.position).map((e) => e.name);
1421
1516
  if (n.length === 1) {
1422
- let e = te.get(t.table);
1423
- e || (e = /* @__PURE__ */ new Set(), te.set(t.table, e)), e.add(n[0]);
1517
+ let e = y.get(t.table);
1518
+ e || (e = /* @__PURE__ */ new Set(), y.set(t.table, e)), e.add(n[0]);
1424
1519
  } else {
1425
- let r = y.get(t.table);
1426
- r || (r = [], y.set(t.table, r)), r.push({
1520
+ let r = b.get(t.table);
1521
+ r || (r = [], b.set(t.table, r)), r.push({
1427
1522
  name: e.slice(e.indexOf("\0") + 1),
1428
1523
  table: t.table,
1429
1524
  columns: n,
@@ -1432,28 +1527,28 @@ BEGIN
1432
1527
  }
1433
1528
  }
1434
1529
  for (let e of g) {
1435
- let t = ne.get(e.source_table);
1436
- t || (t = [], ne.set(e.source_table, t)), t.push(e);
1530
+ let t = te.get(e.source_table);
1531
+ t || (t = [], te.set(e.source_table, t)), t.push(e);
1437
1532
  }
1438
1533
  for (let e of ee) {
1439
- let t = b.get(e.table_name);
1440
- t || (t = /* @__PURE__ */ new Map(), b.set(e.table_name, t));
1534
+ let t = x.get(e.table_name);
1535
+ t || (t = /* @__PURE__ */ new Map(), x.set(e.table_name, t));
1441
1536
  let n = t.get(e.index_name);
1442
1537
  n || (n = [], t.set(e.index_name, n)), n.push(e);
1443
1538
  }
1444
- let re = [];
1539
+ let ne = [];
1445
1540
  for (let e of c) {
1446
- let t = /* @__PURE__ */ new Set(), n = (_.get(e.table_name) ?? []).filter((e) => t.has(e.column_name) ? !1 : (t.add(e.column_name), !0)), r = v.get(e.table_name) ?? /* @__PURE__ */ new Set(), i = te.get(e.table_name) ?? /* @__PURE__ */ new Set(), a = ne.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) => {
1447
- 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" : zt(t.data_type, t.udt_name), c = a ? {
1541
+ let t = /* @__PURE__ */ new Set(), n = (_.get(e.table_name) ?? []).filter((e) => t.has(e.column_name) ? !1 : (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 = te.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) => {
1542
+ 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" : Kt(t.data_type, t.udt_name), c = a ? {
1448
1543
  table: a.target_table,
1449
1544
  column: a.target_column,
1450
- onDelete: R(a.delete_rule),
1451
- onUpdate: R(a.update_rule)
1545
+ onDelete: L(a.delete_rule),
1546
+ onUpdate: L(a.update_rule)
1452
1547
  } : void 0, l = h.get(`${e.table_name}.${t.column_name}`);
1453
1548
  return {
1454
1549
  name: t.column_name,
1455
1550
  type: s,
1456
- ...V(t.data_type, t.character_maximum_length) === void 0 ? {} : { maxLength: V(t.data_type, t.character_maximum_length) },
1551
+ ...B(t.data_type, t.character_maximum_length) === void 0 ? {} : { maxLength: B(t.data_type, t.character_maximum_length) },
1457
1552
  nullable: t.is_nullable === "YES",
1458
1553
  unique: i.has(t.column_name) || n && t.column_name === "id",
1459
1554
  hasDefault: t.column_default !== null,
@@ -1461,7 +1556,7 @@ BEGIN
1461
1556
  ...c ? { references: c } : {},
1462
1557
  ...l ? { oneOf: l } : {}
1463
1558
  };
1464
- }), l = [], u = b.get(e.table_name);
1559
+ }), l = [], u = x.get(e.table_name);
1465
1560
  if (u) for (let [t, n] of u) {
1466
1561
  let r = /* @__PURE__ */ new Set(), i = [...n].filter((e) => e.column_name !== null && e.position !== null).sort((e, t) => (e.position ?? 0) - (t.position ?? 0)).filter((e) => {
1467
1562
  let t = e.position;
@@ -1477,7 +1572,7 @@ BEGIN
1477
1572
  ...a ? { expression: !0 } : {}
1478
1573
  });
1479
1574
  }
1480
- for (let t of y.get(e.table_name) ?? []) l.push(t);
1575
+ for (let t of b.get(e.table_name) ?? []) l.push(t);
1481
1576
  r.size > 0 && l.push({
1482
1577
  name: `${e.table_name}_pkey`,
1483
1578
  table: e.table_name,
@@ -1485,20 +1580,20 @@ BEGIN
1485
1580
  unique: !0
1486
1581
  });
1487
1582
  let d = Number(e.row_count ?? 0);
1488
- re.push({
1583
+ ne.push({
1489
1584
  name: e.table_name,
1490
1585
  columns: c,
1491
1586
  indexes: l,
1492
1587
  ...d > 0 ? { rowCount: d } : {}
1493
1588
  });
1494
1589
  }
1495
- return { tables: re };
1590
+ return { tables: ne };
1496
1591
  });
1497
1592
  return (t > 0 ? e.withTransaction(n) : n).pipe(d.catchAll((e) => {
1498
1593
  let n = `${String(e)} ${String(e.cause ?? "")}`.toLowerCase();
1499
1594
  return n.includes("statement timeout") || n.includes("57014") ? d.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.`)) : d.fail(e);
1500
1595
  }));
1501
- }, Kt = (e, t) => {
1596
+ }, $t = (e, t) => {
1502
1597
  switch (e.toLowerCase()) {
1503
1598
  case "varchar":
1504
1599
  case "char":
@@ -1530,21 +1625,21 @@ BEGIN
1530
1625
  case "json": return "json";
1531
1626
  default: return "text";
1532
1627
  }
1533
- }, z = (e) => e.map((e) => {
1628
+ }, R = (e) => e.map((e) => {
1534
1629
  let t = e, n = {};
1535
1630
  for (let e of Object.keys(t)) n[e.toLowerCase()] = t[e];
1536
1631
  return n;
1537
- }), qt = (e) => d.gen(function* () {
1538
- let t = z(yield* e`
1632
+ }), en = (e) => d.gen(function* () {
1633
+ let t = R(yield* e`
1539
1634
  SELECT table_name, COALESCE(table_rows, 0) AS table_rows
1540
1635
  FROM information_schema.tables
1541
1636
  WHERE table_schema = DATABASE() AND table_type = 'BASE TABLE'
1542
- ORDER BY table_name`), n = z(yield* e`
1637
+ ORDER BY table_name`), n = R(yield* e`
1543
1638
  SELECT table_name, column_name, data_type, column_type, is_nullable, column_default, column_key,
1544
1639
  character_maximum_length
1545
1640
  FROM information_schema.columns
1546
1641
  WHERE table_schema = DATABASE()
1547
- ORDER BY table_name, ordinal_position`), r = z(yield* e`
1642
+ ORDER BY table_name, ordinal_position`), r = R(yield* e`
1548
1643
  SELECT k.table_name AS source_table,
1549
1644
  k.column_name AS source_column,
1550
1645
  k.referenced_table_name AS target_table,
@@ -1554,11 +1649,11 @@ BEGIN
1554
1649
  JOIN information_schema.referential_constraints r
1555
1650
  ON k.constraint_name = r.constraint_name
1556
1651
  AND k.table_schema = r.constraint_schema
1557
- WHERE k.table_schema = DATABASE() AND k.referenced_table_name IS NOT NULL`), i = z(yield* e`
1652
+ WHERE k.table_schema = DATABASE() AND k.referenced_table_name IS NOT NULL`), i = R(yield* e`
1558
1653
  SELECT table_name, index_name, non_unique, column_name, seq_in_index
1559
1654
  FROM information_schema.statistics
1560
1655
  WHERE table_schema = DATABASE() AND index_name <> 'PRIMARY'
1561
- ORDER BY table_name, index_name, seq_in_index`), a = z(yield* e`
1656
+ ORDER BY table_name, index_name, seq_in_index`), a = R(yield* e`
1562
1657
  SELECT table_name, check_clause
1563
1658
  FROM information_schema.check_constraints
1564
1659
  WHERE constraint_schema = DATABASE()`.unprepared.pipe(d.orElseSucceed(() => []))), o = /* @__PURE__ */ new Set(), s = /* @__PURE__ */ new Map();
@@ -1568,7 +1663,7 @@ BEGIN
1568
1663
  o.add(`${e.table_name}.${t[1]}`);
1569
1664
  continue;
1570
1665
  }
1571
- let n = Rt(e.check_clause);
1666
+ let n = Gt(e.check_clause);
1572
1667
  n && s.set(`${e.table_name}.${n.column}`, n.values);
1573
1668
  }
1574
1669
  let c = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new Map(), u = /* @__PURE__ */ new Map();
@@ -1591,17 +1686,17 @@ BEGIN
1591
1686
  let t = c.get(e.table_name) ?? [], n = l.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(), d = u.get(e.table_name);
1592
1687
  if (d) for (let e of d.values()) e.length === 1 && e[0].non_unique === 0 && a.add(e[0].column_name);
1593
1688
  let p = t.map((t) => {
1594
- let n = i.includes(t.column_name) && i.length === 1, c = r.get(t.column_name), l = c ? "reference" : n && t.column_name === "id" ? "id" : o.has(`${e.table_name}.${t.column_name}`) ? "json" : Kt(t.data_type, t.column_type), u = c ? {
1689
+ let n = i.includes(t.column_name) && i.length === 1, c = r.get(t.column_name), l = c ? "reference" : n && t.column_name === "id" ? "id" : o.has(`${e.table_name}.${t.column_name}`) ? "json" : $t(t.data_type, t.column_type), u = c ? {
1595
1690
  table: c.target_table,
1596
1691
  column: c.target_column,
1597
- onDelete: R(c.delete_rule),
1598
- onUpdate: R(c.update_rule)
1692
+ onDelete: L(c.delete_rule),
1693
+ onUpdate: L(c.update_rule)
1599
1694
  } : void 0, d = a.has(t.column_name) || n && t.column_name === "id", f = t.column_default === "NULL" ? null : t.column_default, p = s.get(`${e.table_name}.${t.column_name}`);
1600
1695
  return {
1601
1696
  name: t.column_name,
1602
1697
  type: l,
1603
1698
  nullable: t.is_nullable === "YES",
1604
- ...V(t.data_type, t.character_maximum_length) === void 0 ? {} : { maxLength: V(t.data_type, t.character_maximum_length) },
1699
+ ...B(t.data_type, t.character_maximum_length) === void 0 ? {} : { maxLength: B(t.data_type, t.character_maximum_length) },
1605
1700
  unique: d,
1606
1701
  hasDefault: f !== null,
1607
1702
  ...f === null ? {} : { defaultValue: f },
@@ -1633,10 +1728,10 @@ BEGIN
1633
1728
  });
1634
1729
  }
1635
1730
  return { tables: f };
1636
- }), Jt = (e) => {
1731
+ }), tn = (e) => {
1637
1732
  let t = e.toUpperCase();
1638
1733
  return t.includes("INT") ? "integer" : t.includes("REAL") || t.includes("FLOA") || t.includes("DOUB") ? "real" : t.includes("BLOB") ? "bytes" : "text";
1639
- }, Yt = (e) => d.gen(function* () {
1734
+ }, nn = (e) => d.gen(function* () {
1640
1735
  let t = yield* e`
1641
1736
  SELECT name, sql FROM sqlite_master
1642
1737
  WHERE type = 'table' AND name NOT LIKE 'sqlite_%'
@@ -1653,11 +1748,11 @@ BEGIN
1653
1748
  d.set(t.name, r), t.unique === 1 && r.length === 1 && f.add(r[0]);
1654
1749
  }
1655
1750
  let p = o.map((e) => {
1656
- let n = u.length === 1 && u[0] === e.name, r = l.get(e.name), i = r ? "reference" : n && e.name === "id" ? "id" : Jt(e.type), a = r ? {
1751
+ let n = u.length === 1 && u[0] === e.name, r = l.get(e.name), i = r ? "reference" : n && e.name === "id" ? "id" : tn(e.type), a = r ? {
1657
1752
  table: r.table,
1658
1753
  column: r.to,
1659
- onDelete: R(r.on_delete),
1660
- onUpdate: R(r.on_update)
1754
+ onDelete: L(r.on_delete),
1755
+ onUpdate: L(r.on_update)
1661
1756
  } : void 0, o = t.get(e.name);
1662
1757
  return {
1663
1758
  name: e.name,
@@ -1692,7 +1787,7 @@ BEGIN
1692
1787
  });
1693
1788
  }
1694
1789
  return { tables: r };
1695
- }), Xt = (e) => {
1790
+ }), rn = (e) => {
1696
1791
  switch (e.toLowerCase()) {
1697
1792
  case "int":
1698
1793
  case "smallint":
@@ -1714,7 +1809,7 @@ BEGIN
1714
1809
  case "image": return "bytes";
1715
1810
  default: return "text";
1716
1811
  }
1717
- }, B = (e) => e === !0 || e === 1, Zt = (e) => d.gen(function* () {
1812
+ }, z = (e) => e === !0 || e === 1, an = (e) => d.gen(function* () {
1718
1813
  let t = yield* e`
1719
1814
  SELECT TABLE_NAME AS table_name FROM INFORMATION_SCHEMA.TABLES
1720
1815
  WHERE TABLE_TYPE = 'BASE TABLE' ORDER BY TABLE_NAME`, n = yield* e`
@@ -1771,21 +1866,21 @@ BEGIN
1771
1866
  let t = s.get(e) ?? [], n = c.get(e) ?? [], r = new Map(n.map((e) => [e.source_column, e])), i = new Set(n.map((e) => e.source_column)), a = l.get(e), d = [], f = /* @__PURE__ */ new Set();
1772
1867
  if (a) for (let [, e] of a) {
1773
1868
  let t = [...e].sort((e, t) => e.key_ordinal - t.key_ordinal);
1774
- if (B(t[0].is_primary)) for (let e of t) d.push(e.column_name);
1775
- else B(t[0].is_unique) && t.length === 1 && f.add(t[0].column_name);
1869
+ if (z(t[0].is_primary)) for (let e of t) d.push(e.column_name);
1870
+ else z(t[0].is_unique) && t.length === 1 && f.add(t[0].column_name);
1776
1871
  }
1777
1872
  let p = t.map((t) => {
1778
- let n = d.length === 1 && d[0] === t.column_name, i = r.get(t.column_name), a = i ? "reference" : n && t.column_name === "id" ? "id" : Xt(t.data_type), s = i ? {
1873
+ let n = d.length === 1 && d[0] === t.column_name, i = r.get(t.column_name), a = i ? "reference" : n && t.column_name === "id" ? "id" : rn(t.data_type), s = i ? {
1779
1874
  table: i.target_table,
1780
1875
  column: i.target_column,
1781
- onDelete: Qt(i.delete_rule),
1782
- onUpdate: Qt(i.update_rule)
1783
- } : void 0, c = t.column_default === null ? null : $t(t.column_default), l = o.get(`${e}.${t.column_name}`);
1876
+ onDelete: on(i.delete_rule),
1877
+ onUpdate: on(i.update_rule)
1878
+ } : void 0, c = t.column_default === null ? null : sn(t.column_default), l = o.get(`${e}.${t.column_name}`);
1784
1879
  return {
1785
1880
  name: t.column_name,
1786
1881
  type: a,
1787
1882
  nullable: t.is_nullable === "YES",
1788
- ...V(t.data_type, t.character_maximum_length) === void 0 ? {} : { maxLength: V(t.data_type, t.character_maximum_length) },
1883
+ ...B(t.data_type, t.character_maximum_length) === void 0 ? {} : { maxLength: B(t.data_type, t.character_maximum_length) },
1789
1884
  unique: f.has(t.column_name) || n && t.column_name === "id",
1790
1885
  hasDefault: c !== null,
1791
1886
  ...c === null ? {} : { defaultValue: c },
@@ -1795,11 +1890,11 @@ BEGIN
1795
1890
  }), m = [];
1796
1891
  if (a) for (let [t, n] of a) {
1797
1892
  let r = [...n].sort((e, t) => e.key_ordinal - t.key_ordinal);
1798
- B(r[0].is_primary) || r.length === 1 && B(r[0].is_unique) || r.length === 1 && !B(r[0].is_unique) && i.has(r[0].column_name) && t !== `${e}_${r[0].column_name}_idx` || m.push({
1893
+ z(r[0].is_primary) || r.length === 1 && z(r[0].is_unique) || r.length === 1 && !z(r[0].is_unique) && i.has(r[0].column_name) && t !== `${e}_${r[0].column_name}_idx` || m.push({
1799
1894
  name: t,
1800
1895
  table: e,
1801
1896
  columns: r.map((e) => e.column_name),
1802
- unique: B(r[0].is_unique)
1897
+ unique: z(r[0].is_unique)
1803
1898
  });
1804
1899
  }
1805
1900
  d.length > 0 && m.push({
@@ -1814,48 +1909,48 @@ BEGIN
1814
1909
  });
1815
1910
  }
1816
1911
  return { tables: u };
1817
- }), Qt = (e) => {
1912
+ }), on = (e) => {
1818
1913
  switch (e.toUpperCase().replace(/_/g, " ")) {
1819
1914
  case "CASCADE": return "cascade";
1820
1915
  case "SET NULL": return "setNull";
1821
1916
  case "SET DEFAULT": return "noAction";
1822
1917
  default: return "noAction";
1823
1918
  }
1824
- }, $t = (e) => {
1919
+ }, sn = (e) => {
1825
1920
  let t = e.trim();
1826
1921
  for (; t.startsWith("(") && t.endsWith(")");) t = t.slice(1, -1).trim();
1827
1922
  return t.startsWith("N'") && t.endsWith("'") ? t = t.slice(2, -1) : t.startsWith("'") && t.endsWith("'") && (t = t.slice(1, -1)), t;
1828
- }, en = /* @__PURE__ */ new Set([
1923
+ }, cn = /* @__PURE__ */ new Set([
1829
1924
  "character varying",
1830
1925
  "varchar",
1831
1926
  "nvarchar",
1832
1927
  "char",
1833
1928
  "character",
1834
1929
  "nchar"
1835
- ]), V = (e, t) => {
1836
- if (!en.has(e.toLowerCase())) return;
1930
+ ]), B = (e, t) => {
1931
+ if (!cn.has(e.toLowerCase())) return;
1837
1932
  let n = Number(t);
1838
1933
  if (!(!Number.isFinite(n) || n <= 0)) return n;
1839
- }, H = (e) => e.onDialectOrElse({
1840
- mysql: () => qt(e),
1841
- mssql: () => Zt(e),
1842
- sqlite: () => Yt(e),
1843
- orElse: () => Gt(e)
1844
- }), tn = (e, t) => `${t}(${e.precision ?? 38}, ${e.scale ?? 0})`, U = (e, t) => {
1934
+ }, V = (e) => e.onDialectOrElse({
1935
+ mysql: () => en(e),
1936
+ mssql: () => an(e),
1937
+ sqlite: () => nn(e),
1938
+ orElse: () => Qt(e)
1939
+ }), ln = (e, t) => `${t}(${e.precision ?? 38}, ${e.scale ?? 0})`, H = (e, t) => {
1845
1940
  if (!(e.type === "text" && e.maxLength !== void 0) && !e.spatial && e.type !== "vector" && e.type !== "array" && e.type !== "enum") return;
1846
1941
  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;
1847
1942
  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.`);
1848
- return D(e, t);
1849
- }, W = (e) => {
1850
- let t = U(e, "postgres");
1851
- return t === void 0 ? nn(e) : t;
1852
- }, nn = (e) => {
1943
+ return E(e, t);
1944
+ }, U = (e) => {
1945
+ let t = H(e, "postgres");
1946
+ return t === void 0 ? un(e) : t;
1947
+ }, un = (e) => {
1853
1948
  switch (e.type) {
1854
1949
  case "id": return "text";
1855
1950
  case "text": return "text";
1856
1951
  case "integer": return "integer";
1857
1952
  case "real": return "double precision";
1858
- case "decimal": return tn(e, "NUMERIC");
1953
+ case "decimal": return ln(e, "NUMERIC");
1859
1954
  case "bigint": return "bigint";
1860
1955
  case "boolean": return "boolean";
1861
1956
  case "timestamp": return "timestamptz";
@@ -1869,15 +1964,15 @@ BEGIN
1869
1964
  case "interval": return "interval";
1870
1965
  case "raw": return e.rawDdl ?? "text";
1871
1966
  }
1872
- }, rn = (e) => {
1873
- let t = U(e, "mariadb");
1967
+ }, W = (e) => {
1968
+ let t = H(e, "mariadb");
1874
1969
  if (t !== void 0) return t;
1875
1970
  switch (e.type) {
1876
1971
  case "id": return "VARCHAR(64)";
1877
1972
  case "text": return e.hasDefault && e.defaultValue !== void 0 || e.oneOf && e.oneOf.length > 0 ? "VARCHAR(255)" : "LONGTEXT";
1878
1973
  case "integer": return "INT";
1879
1974
  case "real": return "DOUBLE";
1880
- case "decimal": return tn(e, "DECIMAL");
1975
+ case "decimal": return ln(e, "DECIMAL");
1881
1976
  case "bigint": return "BIGINT";
1882
1977
  case "boolean": return "TINYINT(1)";
1883
1978
  case "timestamp": return "DATETIME(6)";
@@ -1891,32 +1986,32 @@ BEGIN
1891
1986
  case "interval": return "BIGINT";
1892
1987
  case "raw": return e.rawDdl ?? "LONGTEXT";
1893
1988
  }
1894
- }, G = (e) => `"${e}"`, K = (e) => `\`${e.replace(/`/g, "``")}\``, an = (e, t) => `ALTER TABLE ${t(e.table)} DROP COLUMN IF EXISTS ${t(e.column)};`, on = (e) => `ALTER TABLE ${K(e.table)} DROP COLUMN IF EXISTS ${K(e.column)}, ALGORITHM=COPY;`, sn = (e, t) => `ALTER TABLE ${t(e.table)} RENAME COLUMN ${t(e.from)} TO ${t(e.to)};`, cn = (e, t, n) => `ALTER TABLE ${n(e.table)} RENAME COLUMN ${n(e.column)} TO ${n(`${e.column}${Nn(t)}`)};`, ln = (e, t, n) => e.hasDefault && e.defaultValue !== void 0 ? `ALTER TABLE ${t(e.table)} ALTER COLUMN ${t(e.column)} SET ${un(e, n)};` : `ALTER TABLE ${t(e.table)} ALTER COLUMN ${t(e.column)} DROP DEFAULT;`, un = (e, t) => {
1989
+ }, G = (e) => `"${e}"`, K = (e) => `\`${e.replace(/`/g, "``")}\``, dn = (e, t) => `ALTER TABLE ${t(e.table)} DROP COLUMN IF EXISTS ${t(e.column)};`, fn = (e) => `ALTER TABLE ${K(e.table)} DROP COLUMN IF EXISTS ${K(e.column)}, ALGORITHM=COPY;`, pn = (e, t) => `ALTER TABLE ${t(e.table)} RENAME COLUMN ${t(e.from)} TO ${t(e.to)};`, mn = (e, t, n) => `ALTER TABLE ${n(e.table)} RENAME COLUMN ${n(e.column)} TO ${n(`${e.column}${zn(t)}`)};`, hn = (e, t, n) => e.hasDefault && e.defaultValue !== void 0 ? `ALTER TABLE ${t(e.table)} ALTER COLUMN ${t(e.column)} SET ${gn(e, n)};` : `ALTER TABLE ${t(e.table)} ALTER COLUMN ${t(e.column)} DROP DEFAULT;`, gn = (e, t) => {
1895
1990
  let n = t(e.defaultValue);
1896
1991
  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.`);
1897
1992
  return n;
1898
- }, q = (e, t, n) => e.find((e) => e.tableName === t)?.fields[n], dn = (e, t, n) => {
1993
+ }, q = (e, t, n) => e.find((e) => e.tableName === t)?.fields[n], _n = (e, t, n) => {
1899
1994
  let r = q(e, t, n);
1900
1995
  return r ? nt(n, r) : void 0;
1901
- }, fn = (e, t, n) => {
1902
- let r = n ?? e.nullable, i = ve(e, "mariadb");
1996
+ }, vn = (e, t, n) => {
1997
+ let r = n ?? e.nullable, i = ye(e, "mariadb");
1903
1998
  return [
1904
1999
  K(t),
1905
- D(e, "mariadb"),
2000
+ E(e, "mariadb"),
1906
2001
  r ? null : "NOT NULL",
1907
2002
  i
1908
2003
  ].filter(Boolean).join(" ");
1909
- }, pn = (e, t) => e == null ? null : Array.isArray(e) ? mn(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" ? O(e, "mysql") : null, mn = (e, t, n) => ye(e, t ?? { type: "json" }, n), hn = (e, t) => e == null ? null : Array.isArray(e) ? mn(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" ? O(e, "postgres") : null, J = (e, t) => {
2004
+ }, yn = (e, t) => e == null ? null : Array.isArray(e) ? bn(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" ? D(e, "mysql") : null, bn = (e, t, n) => be(e, t ?? { type: "json" }, n), xn = (e, t) => e == null ? null : Array.isArray(e) ? bn(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" ? D(e, "postgres") : null, J = (e, t) => {
1910
2005
  if (!e.generatedAs) return null;
1911
2006
  let { expr: n, stored: r } = e.generatedAs;
1912
2007
  return t === "postgres" ? `GENERATED ALWAYS AS (${n}) STORED` : t === "mssql" ? `AS (${n})${r ? " PERSISTED" : ""}` : `GENERATED ALWAYS AS (${n}) ${r ? "STORED" : "VIRTUAL"}`;
1913
- }, gn = (e) => {
1914
- if (e.type === "id" && e.idScheme?.kind === "numeric") return k(e.name, "postgres");
2008
+ }, Sn = (e) => {
2009
+ if (e.type === "id" && e.idScheme?.kind === "numeric") return O(e.name, "postgres");
1915
2010
  let t = J(e, "postgres");
1916
- if (t) return `${G(e.name)} ${W(e)} ${t}`;
1917
- let n = [G(e.name), W(e)];
2011
+ if (t) return `${G(e.name)} ${U(e)} ${t}`;
2012
+ let n = [G(e.name), U(e)];
1918
2013
  if (e.type === "id" && n.push("PRIMARY KEY"), e.nullable || n.push("NOT NULL"), e.unique && e.type !== "id" && n.push("UNIQUE"), e.hasDefault) {
1919
- let t = hn(e.defaultValue, e);
2014
+ let t = xn(e.defaultValue, e);
1920
2015
  t && n.push(t);
1921
2016
  }
1922
2017
  return e.references && (n.push(`REFERENCES ${G(e.references.table)} (${G(e.references.column)})`), e.references.onDelete && n.push(`ON DELETE ${{
@@ -1925,20 +2020,20 @@ BEGIN
1925
2020
  setNull: "SET NULL",
1926
2021
  noAction: "NO ACTION"
1927
2022
  }[e.references.onDelete]}`)), n.join(" ");
1928
- }, _n = (e, t) => e.primaryKey && e.primaryKey.length > 0 ? `,\n PRIMARY KEY (${e.primaryKey.map(t).join(", ")})` : "", vn = (e) => {
1929
- let t = e.columns.map((e) => ` ${gn(e)}`).join(",\n"), n = [`CREATE TABLE IF NOT EXISTS ${G(e.table)} (\n${t}${_n(e, G)}\n)`];
1930
- for (let t of e.indexes) t.name !== `${e.table}_pkey` && n.push(`CREATE ${t.unique ? "UNIQUE " : ""}INDEX IF NOT EXISTS ${G(t.name)} ON ${G(e.table)} (${t.columns.map(Rn).join(", ")})`);
2023
+ }, Cn = (e, t) => e.primaryKey && e.primaryKey.length > 0 ? `,\n PRIMARY KEY (${e.primaryKey.map(t).join(", ")})` : "", wn = (e) => {
2024
+ let t = e.columns.map((e) => ` ${Sn(e)}`).join(",\n"), n = [`CREATE TABLE IF NOT EXISTS ${G(e.table)} (\n${t}${Cn(e, G)}\n)`];
2025
+ for (let t of e.indexes) t.name !== `${e.table}_pkey` && n.push(`CREATE ${t.unique ? "UNIQUE " : ""}INDEX IF NOT EXISTS ${G(t.name)} ON ${G(e.table)} (${t.columns.map(Wn).join(", ")})`);
1931
2026
  return n;
1932
- }, yn = 191, bn = (e) => {
1933
- let t = rn(e).toUpperCase();
2027
+ }, Tn = 191, En = (e) => {
2028
+ let t = W(e).toUpperCase();
1934
2029
  return t.endsWith("TEXT") || t.endsWith("BLOB");
1935
- }, xn = (e) => {
1936
- if (e.type === "id" && e.idScheme?.kind === "numeric") return k(e.name, "mariadb");
2030
+ }, Dn = (e) => {
2031
+ if (e.type === "id" && e.idScheme?.kind === "numeric") return O(e.name, "mariadb");
1937
2032
  let t = J(e, "mariadb");
1938
- if (t) return `${K(e.name)} ${rn(e)} ${t}`;
1939
- let n = [K(e.name), rn(e)];
1940
- if (e.type === "id" && n.push("PRIMARY KEY"), e.nullable || n.push("NOT NULL"), e.unique && e.type !== "id" && !bn(e) && n.push("UNIQUE"), e.hasDefault) {
1941
- let t = pn(e.defaultValue, e);
2033
+ if (t) return `${K(e.name)} ${W(e)} ${t}`;
2034
+ let n = [K(e.name), W(e)];
2035
+ if (e.type === "id" && n.push("PRIMARY KEY"), e.nullable || n.push("NOT NULL"), e.unique && e.type !== "id" && !En(e) && n.push("UNIQUE"), e.hasDefault) {
2036
+ let t = yn(e.defaultValue, e);
1942
2037
  t && n.push(t);
1943
2038
  }
1944
2039
  return e.references && (n.push(`REFERENCES ${K(e.references.table)} (${K(e.references.column)})`), e.references.onDelete && n.push(`ON DELETE ${{
@@ -1947,26 +2042,26 @@ BEGIN
1947
2042
  setNull: "SET NULL",
1948
2043
  noAction: "NO ACTION"
1949
2044
  }[e.references.onDelete]}`)), n.join(" ");
1950
- }, Sn = (e) => {
2045
+ }, On = (e) => {
1951
2046
  let t = new Map(e.columns.map((e) => [e.name, e])), n = (e) => {
1952
2047
  let n = t.get(e);
1953
- return n && bn(n) ? `${K(e)}(${yn})` : K(e);
1954
- }, r = e.columns.map((e) => ` ${xn(e)}`).join(",\n"), i = [`CREATE TABLE IF NOT EXISTS ${K(e.table)} (\n${r}${_n(e, n)}\n)`];
1955
- for (let t of e.columns) t.unique && t.type !== "id" && bn(t) && i.push(`CREATE UNIQUE INDEX IF NOT EXISTS ${K(`${e.table}_${t.name}_key`)} ON ${K(e.table)} (${n(t.name)})`);
2048
+ return n && En(n) ? `${K(e)}(${Tn})` : K(e);
2049
+ }, r = e.columns.map((e) => ` ${Dn(e)}`).join(",\n"), i = [`CREATE TABLE IF NOT EXISTS ${K(e.table)} (\n${r}${Cn(e, n)}\n)`];
2050
+ for (let t of e.columns) t.unique && t.type !== "id" && En(t) && i.push(`CREATE UNIQUE INDEX IF NOT EXISTS ${K(`${e.table}_${t.name}_key`)} ON ${K(e.table)} (${n(t.name)})`);
1956
2051
  for (let t of e.indexes) t.name !== `${e.table}_pkey` && i.push(`CREATE ${t.unique ? "UNIQUE " : ""}INDEX IF NOT EXISTS ${K(t.name)} ON ${K(e.table)} (${t.columns.map(n).join(", ")})`);
1957
2052
  return i;
1958
- }, Cn = {
2053
+ }, kn = {
1959
2054
  cascade: "CASCADE",
1960
2055
  restrict: "RESTRICT",
1961
2056
  setNull: "SET NULL",
1962
2057
  noAction: "NO ACTION"
1963
- }, wn = {
2058
+ }, An = {
1964
2059
  cascade: "CASCADE",
1965
2060
  restrict: "NO ACTION",
1966
2061
  setNull: "SET NULL",
1967
2062
  noAction: "NO ACTION"
1968
- }, Tn = (e) => {
1969
- let t = U(e, "sqlite");
2063
+ }, jn = (e) => {
2064
+ let t = H(e, "sqlite");
1970
2065
  if (t !== void 0) return t;
1971
2066
  switch (e.type) {
1972
2067
  case "integer":
@@ -1977,29 +2072,29 @@ BEGIN
1977
2072
  case "bytes": return "BLOB";
1978
2073
  default: return "TEXT";
1979
2074
  }
1980
- }, Y = (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" ? O(e, "sqlite") : null, En = (e) => {
1981
- if (e.type === "id" && e.idScheme?.kind === "numeric") return k(e.name, "sqlite");
2075
+ }, Y = (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" ? D(e, "sqlite") : null, Mn = (e) => {
2076
+ if (e.type === "id" && e.idScheme?.kind === "numeric") return O(e.name, "sqlite");
1982
2077
  let t = J(e, "sqlite");
1983
- if (t) return `${G(e.name)} ${Tn(e)} ${t}`;
1984
- let n = [G(e.name), Tn(e)];
2078
+ if (t) return `${G(e.name)} ${jn(e)} ${t}`;
2079
+ let n = [G(e.name), jn(e)];
1985
2080
  if (e.type === "id" && n.push("PRIMARY KEY"), e.nullable || n.push("NOT NULL"), e.unique && e.type !== "id" && n.push("UNIQUE"), e.hasDefault) {
1986
2081
  let t = Y(e.defaultValue, "CURRENT_TIMESTAMP");
1987
2082
  t && n.push(t);
1988
2083
  }
1989
- if (e.references && (n.push(`REFERENCES ${G(e.references.table)} (${G(e.references.column)})`), e.references.onDelete && n.push(`ON DELETE ${Cn[e.references.onDelete]}`)), e.oneOf && e.oneOf.length > 0) {
2084
+ if (e.references && (n.push(`REFERENCES ${G(e.references.table)} (${G(e.references.column)})`), e.references.onDelete && n.push(`ON DELETE ${kn[e.references.onDelete]}`)), e.oneOf && e.oneOf.length > 0) {
1990
2085
  let t = e.oneOf.map((e) => `'${e.replace(/'/g, "''")}'`).join(", ");
1991
2086
  n.push(`CHECK (${G(e.name)} IN (${t}))`);
1992
2087
  }
1993
2088
  return n.join(" ");
1994
- }, Dn = (e) => {
1995
- let t = e.columns.map((e) => ` ${En(e)}`).join(",\n"), n = [`CREATE TABLE IF NOT EXISTS ${G(e.table)} (\n${t}${_n(e, G)}\n)`];
2089
+ }, Nn = (e) => {
2090
+ let t = e.columns.map((e) => ` ${Mn(e)}`).join(",\n"), n = [`CREATE TABLE IF NOT EXISTS ${G(e.table)} (\n${t}${Cn(e, G)}\n)`];
1996
2091
  for (let t of e.indexes) t.name !== `${e.table}_pkey` && n.push(`CREATE ${t.unique ? "UNIQUE " : ""}INDEX IF NOT EXISTS ${G(t.name)} ON ${G(e.table)} (${t.columns.map(G).join(", ")})`);
1997
2092
  return n;
1998
2093
  }, X = (e, t) => {
1999
2094
  let n = t.find((t) => t.tableName === e);
2000
2095
  if (!n) return [];
2001
2096
  let r = N([n]).tables[0], i = `${e}__voltro_rebuild`, a = r.columns.map((e) => G(e.name)).join(", "), o = [
2002
- ...Dn({
2097
+ ...Nn({
2003
2098
  kind: "create-table",
2004
2099
  table: i,
2005
2100
  columns: r.columns,
@@ -2012,25 +2107,25 @@ BEGIN
2012
2107
  ];
2013
2108
  for (let t of r.indexes) t.name !== `${e}_pkey` && o.push(`CREATE ${t.unique ? "UNIQUE " : ""}INDEX IF NOT EXISTS ${G(t.name)} ON ${G(e)} (${t.columns.map(G).join(", ")})`);
2014
2109
  return o;
2015
- }, On = (e, t, n, r) => {
2110
+ }, Pn = (e, t, n, r) => {
2016
2111
  let i = r ?? e.nullable;
2017
- return `ALTER TABLE ${Z(n)} ALTER COLUMN ${Z(t)} ${D(e, "mssql")} ${i ? "NULL" : "NOT NULL"};`;
2018
- }, kn = (e) => {
2112
+ return `ALTER TABLE ${Z(n)} ALTER COLUMN ${Z(t)} ${E(e, "mssql")} ${i ? "NULL" : "NOT NULL"};`;
2113
+ }, Fn = (e) => {
2019
2114
  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 ${Z(e.table)} DROP CONSTRAINT [' + @dc + ']');`;
2020
2115
  if (!e.hasDefault) return t;
2021
2116
  let n = Y(e.defaultValue, "SYSUTCDATETIME()");
2022
2117
  if (!n) return t;
2023
2118
  let r = n.replace(/^DEFAULT\s+/i, "");
2024
2119
  return `${t} ALTER TABLE ${Z(e.table)} ADD DEFAULT ${r} FOR ${Z(e.column)};`;
2025
- }, Z = (e) => `[${e.replace(/]/g, "]]")}]`, An = (e) => {
2026
- let t = U(e, "mssql");
2120
+ }, Z = (e) => `[${e.replace(/]/g, "]]")}]`, In = (e) => {
2121
+ let t = H(e, "mssql");
2027
2122
  if (t !== void 0) return t;
2028
2123
  switch (e.type) {
2029
2124
  case "id":
2030
2125
  case "reference": return "NVARCHAR(64)";
2031
2126
  case "integer": return "INT";
2032
2127
  case "real": return "FLOAT";
2033
- case "decimal": return tn(e, "DECIMAL");
2128
+ case "decimal": return ln(e, "DECIMAL");
2034
2129
  case "bigint": return "BIGINT";
2035
2130
  case "boolean": return "BIT";
2036
2131
  case "timestamp": return "DATETIME2(6)";
@@ -2038,34 +2133,40 @@ BEGIN
2038
2133
  case "bytes": return "VARBINARY(MAX)";
2039
2134
  default: return "NVARCHAR(MAX)";
2040
2135
  }
2041
- }, jn = (e, t) => {
2042
- if (e.type === "id" && e.idScheme?.kind === "numeric") return k(e.name, "mssql");
2043
- let n = e.type === "text" && t?.has(e.name) ? "NVARCHAR(450)" : An(e), r = J(e, "mssql");
2136
+ }, Ln = (e, t) => {
2137
+ if (e.type === "id" && e.idScheme?.kind === "numeric") return O(e.name, "mssql");
2138
+ let n = e.type === "text" && t?.has(e.name) ? "NVARCHAR(450)" : In(e), r = J(e, "mssql");
2044
2139
  if (r) return `${Z(e.name)} ${r}`;
2045
2140
  let i = [Z(e.name), n];
2046
2141
  if (e.type === "id" && i.push("PRIMARY KEY"), e.nullable || i.push("NOT NULL"), e.unique && e.type !== "id" && i.push("UNIQUE"), e.hasDefault) {
2047
2142
  let t = Y(e.defaultValue, "SYSUTCDATETIME()");
2048
2143
  t && i.push(t);
2049
2144
  }
2050
- return e.references && (i.push(`REFERENCES ${Z(e.references.table)} (${Z(e.references.column)})`), e.references.onDelete && i.push(`ON DELETE ${wn[e.references.onDelete]}`)), i.join(" ");
2051
- }, Mn = (e) => {
2052
- let t = (e) => e.replace(/'/g, "''"), n = new Set(e.indexes.flatMap((e) => e.columns)), r = e.columns.map((e) => ` ${jn(e, n)}`).join(",\n"), i = `CREATE TABLE ${Z(e.table)} (\n${r}${_n(e, Z)}\n)`, a = [`IF OBJECT_ID(N'${t(e.table)}', N'U') IS NULL EXEC(N'${t(i)}')`];
2145
+ return e.references && (i.push(`REFERENCES ${Z(e.references.table)} (${Z(e.references.column)})`), e.references.onDelete && i.push(`ON DELETE ${An[e.references.onDelete]}`)), i.join(" ");
2146
+ }, Rn = (e) => {
2147
+ let t = (e) => e.replace(/'/g, "''"), n = new Set(e.indexes.flatMap((e) => e.columns)), r = e.columns.map((e) => ` ${Ln(e, n)}`).join(",\n"), i = `CREATE TABLE ${Z(e.table)} (\n${r}${Cn(e, Z)}\n)`, a = [`IF OBJECT_ID(N'${t(e.table)}', N'U') IS NULL EXEC(N'${t(i)}')`];
2053
2148
  for (let n of e.indexes) {
2054
2149
  if (n.name === `${e.table}_pkey`) continue;
2055
2150
  let r = `CREATE ${n.unique ? "UNIQUE " : ""}INDEX ${Z(n.name)} ON ${Z(e.table)} (${n.columns.map(Z).join(", ")})`;
2056
2151
  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)}')`);
2057
2152
  }
2058
2153
  return a;
2059
- }, Nn = (e) => `__dropped_${e.replace(/[-:T.Z]/g, "").slice(0, 14)}`, Pn = (e, t) => `DROP TABLE IF EXISTS ${t(e.table)};`, Fn = (e, t, n) => {
2060
- let r = `${e.table}${Nn(t)}`;
2154
+ }, zn = (e) => `__dropped_${e.replace(/[-:T.Z]/g, "").slice(0, 14)}`, Bn = (e, t) => `DROP TABLE IF EXISTS ${t(e.table)};`, Vn = (e, t, n) => {
2155
+ let r = `${e.table}${zn(t)}`;
2061
2156
  return `ALTER TABLE ${n(e.table)} RENAME TO ${n(r)};`;
2062
- }, In = (e, t, n) => {
2157
+ }, Hn = (e, t, n) => {
2063
2158
  let r = q(e, t, n);
2064
- return r ? bn({ type: r.type }) : !1;
2065
- }, Ln = (e, t, n) => In(e, t, n) ? `${K(n)}(${yn})` : K(n), Rn = (e) => e.startsWith("(") ? e : G(e), zn = (e, t) => `CREATE ${e.index.unique ? "UNIQUE " : ""}INDEX ${t ? "CONCURRENTLY " : ""}IF NOT EXISTS ${G(e.index.name)} ON ${G(e.table)} (${e.index.columns.map(Rn).join(", ")});`, Bn = (e, t) => `CREATE ${e.index.unique ? "UNIQUE " : ""}INDEX IF NOT EXISTS ${K(e.index.name)} ON ${K(e.table)} (${e.index.columns.map((n) => Ln(t, e.table, n)).join(", ")});`, Vn = (e) => `DROP INDEX IF EXISTS ${G(e.index)};`, Hn = (e) => `DROP INDEX ${K(e.index)} ON ${K(e.table)};`, Un = (e) => `DROP INDEX IF EXISTS ${Z(e.index)} ON ${Z(e.table)};`, Wn = (e) => {
2159
+ return r ? En({ type: r.type }) : !1;
2160
+ }, Un = (e, t, n) => Hn(e, t, n) ? `${K(n)}(${Tn})` : K(n), Wn = (e) => e.startsWith("(") ? e : G(e), Gn = (e, t) => `CREATE ${e.index.unique ? "UNIQUE " : ""}INDEX ${t ? "CONCURRENTLY " : ""}IF NOT EXISTS ${G(e.index.name)} ON ${G(e.table)} (${e.index.columns.map(Wn).join(", ")});`, Kn = (e, t) => `CREATE ${e.index.unique ? "UNIQUE " : ""}INDEX IF NOT EXISTS ${K(e.index.name)} ON ${K(e.table)} (${e.index.columns.map((n) => Un(t, e.table, n)).join(", ")});`, qn = (e) => `DROP INDEX IF EXISTS ${G(e.index)};`, Jn = (e) => `DROP INDEX ${K(e.index)} ON ${K(e.table)};`, Yn = (e) => `DROP INDEX IF EXISTS ${Z(e.index)} ON ${Z(e.table)};`, Xn = (e, t) => `ALTER TABLE ${t(e.from)} RENAME TO ${t(e.to)};`, Zn = (e) => {
2161
+ let t = (e) => e.replace(/'/g, "''");
2162
+ return `EXEC sp_rename N'${t(e.from)}', N'${t(e.to)}';`;
2163
+ }, Qn = (e) => `ALTER INDEX ${G(e.from)} RENAME TO ${G(e.to)};`, $n = (e) => `ALTER TABLE ${K(e.table)} RENAME INDEX ${K(e.from)} TO ${K(e.to)};`, er = (e) => {
2164
+ let t = (e) => e.replace(/'/g, "''");
2165
+ return `EXEC sp_rename N'${t(e.table)}.${t(e.from)}', N'${t(e.to)}', N'INDEX';`;
2166
+ }, tr = (e) => {
2066
2167
  let t = (e) => e.replace(/'/g, "''"), n = `CREATE ${e.index.unique ? "UNIQUE " : ""}INDEX ${Z(e.index.name)} ON ${Z(e.table)} (${e.index.columns.map(Z).join(", ")})`;
2067
2168
  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)}');`;
2068
- }, Gn = (e, t, n) => {
2169
+ }, nr = (e, t, n) => {
2069
2170
  let r = n.find((t) => t.tableName === e);
2070
2171
  if (!r) return [];
2071
2172
  let i = [];
@@ -2074,13 +2175,13 @@ BEGIN
2074
2175
  t && t.type === "text" && !t.generatedAs && i.push(`ALTER TABLE ${Z(e)} ALTER COLUMN ${Z(n)} NVARCHAR(450) ${t.nullable ? "NULL" : "NOT NULL"};`);
2075
2176
  }
2076
2177
  return i;
2077
- }, Kn = (e) => `ALTER TABLE ${G(e.table)} ADD CONSTRAINT ${G(`${e.table}_${e.column}_key`)} UNIQUE (${G(e.column)});`, qn = (e, t) => `ALTER TABLE ${K(e.table)} ADD CONSTRAINT ${K(`${e.table}_${e.column}_key`)} UNIQUE (${Ln(t, e.table, e.column)});`, Jn = (e) => {
2178
+ }, rr = (e) => `ALTER TABLE ${G(e.table)} ADD CONSTRAINT ${G(`${e.table}_${e.column}_key`)} UNIQUE (${G(e.column)});`, ir = (e, t) => `ALTER TABLE ${K(e.table)} ADD CONSTRAINT ${K(`${e.table}_${e.column}_key`)} UNIQUE (${Un(t, e.table, e.column)});`, ar = (e) => {
2078
2179
  let t = e.fields.map((e) => G(e)).join(", ");
2079
2180
  return `ALTER TABLE ${G(e.table)} ADD CONSTRAINT ${G(e.name)} UNIQUE (${t});`;
2080
- }, Yn = (e, t) => {
2081
- let n = e.fields.map((n) => Ln(t, e.table, n)).join(", ");
2181
+ }, or = (e, t) => {
2182
+ let n = e.fields.map((n) => Un(t, e.table, n)).join(", ");
2082
2183
  return `ALTER TABLE ${K(e.table)} ADD CONSTRAINT ${K(e.name)} UNIQUE (${n});`;
2083
- }, Xn = (e) => `ALTER TABLE ${G(e.table)} DROP CONSTRAINT IF EXISTS ${G(e.name)};`, Zn = (e) => `ALTER TABLE ${K(e.table)} DROP INDEX ${K(e.name)};`, Qn = (e) => `ALTER TABLE ${G(e.table)} DROP CONSTRAINT IF EXISTS ${G(`${e.table}_${e.column}_key`)};`, $n = (e) => `ALTER TABLE ${K(e.table)} DROP INDEX ${K(`${e.table}_${e.column}_key`)};`, er = (e, t) => {
2184
+ }, sr = (e) => `ALTER TABLE ${G(e.table)} DROP CONSTRAINT IF EXISTS ${G(e.name)};`, cr = (e) => `ALTER TABLE ${K(e.table)} DROP INDEX ${K(e.name)};`, lr = (e) => `ALTER TABLE ${G(e.table)} DROP CONSTRAINT IF EXISTS ${G(`${e.table}_${e.column}_key`)};`, ur = (e) => `ALTER TABLE ${K(e.table)} DROP INDEX ${K(`${e.table}_${e.column}_key`)};`, dr = (e, t) => {
2084
2185
  let n = [], r = t(e.table), i = t(e.column), a = t(e.targetTable), o = t(e.targetColumn);
2085
2186
  if (e.orphanPolicy) {
2086
2187
  let t = `${i} IS NOT NULL AND ${i} NOT IN (SELECT ${o} FROM ${a})`;
@@ -2098,11 +2199,11 @@ BEGIN
2098
2199
  setNull: "SET NULL",
2099
2200
  noAction: "NO ACTION"
2100
2201
  }[e.onDelete]}`), n.push(s.join(" ") + ";"), n;
2101
- }, tr = (e) => `ALTER TABLE ${G(e.table)} DROP CONSTRAINT IF EXISTS ${G(`${e.table}_${e.column}_fkey`)};`, nr = (e) => `ALTER TABLE ${K(e.table)} DROP FOREIGN KEY ${K(`${e.table}_${e.column}_fkey`)};`, rr = (e, t) => {
2202
+ }, fr = (e) => `ALTER TABLE ${G(e.table)} DROP CONSTRAINT IF EXISTS ${G(`${e.table}_${e.column}_fkey`)};`, pr = (e) => `ALTER TABLE ${K(e.table)} DROP FOREIGN KEY ${K(`${e.table}_${e.column}_fkey`)};`, mr = (e, t) => {
2102
2203
  let n = e.values.map((e) => `'${e.replace(/'/g, "''")}'`).join(", ");
2103
2204
  return `ALTER TABLE ${t(e.table)} ADD CONSTRAINT ${t(`${e.table}_${e.column}_check`)} CHECK (${t(e.column)} IN (${n}));`;
2104
- }, ir = (e) => `ALTER TABLE ${G(e.table)} DROP CONSTRAINT IF EXISTS ${G(`${e.table}_${e.column}_check`)};`, ar = (e) => `ALTER TABLE ${K(e.table)} DROP CHECK ${K(`${e.table}_${e.column}_check`)};`, or = (e, t, n, r) => {
2105
- let i = e.column, a = r === "mariadb", o = a ? K : r === "mssql" ? Z : G, s = a ? rn(i) : r === "mssql" ? An(i) : r === "sqlite" ? Tn(i) : W(i), c = r === "mssql" ? "ADD" : "ADD COLUMN", l = (e) => a ? pn(e, i) : r === "mssql" ? Y(e, "SYSUTCDATETIME()") : r === "sqlite" ? Y(e, "CURRENT_TIMESTAMP") : hn(e, i), u = J(i, r);
2205
+ }, hr = (e) => `ALTER TABLE ${G(e.table)} DROP CONSTRAINT IF EXISTS ${G(`${e.table}_${e.column}_check`)};`, gr = (e) => `ALTER TABLE ${K(e.table)} DROP CHECK ${K(`${e.table}_${e.column}_check`)};`, _r = (e, t, n, r) => {
2206
+ let i = e.column, a = r === "mariadb", o = a ? K : r === "mssql" ? Z : G, s = a ? W(i) : r === "mssql" ? In(i) : r === "sqlite" ? jn(i) : U(i), c = r === "mssql" ? "ADD" : "ADD COLUMN", l = (e) => a ? yn(e, i) : r === "mssql" ? Y(e, "SYSUTCDATETIME()") : r === "sqlite" ? Y(e, "CURRENT_TIMESTAMP") : xn(e, i), u = J(i, r);
2106
2207
  if (u) {
2107
2208
  let t = r === "mssql" ? `${o(i.name)} ${u}` : `${o(i.name)} ${s} ${u}`;
2108
2209
  return {
@@ -2130,7 +2231,7 @@ BEGIN
2130
2231
  post: f ? [f] : []
2131
2232
  };
2132
2233
  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;
2133
- }, sr = (e) => {
2234
+ }, vr = (e) => {
2134
2235
  let t = new Map(e.map((e) => [e.tableName, e]));
2135
2236
  return (e, n) => {
2136
2237
  let r = t.get(e);
@@ -2155,21 +2256,21 @@ BEGIN
2155
2256
  })), d.mapError((e) => {
2156
2257
  let r = _(`applier: statement failed (op=${n})`, t, e, 400).trim();
2157
2258
  return Object.assign(e, { message: r });
2158
- }), d.map(() => void 0)), $ = (e, t, n) => d.forEach(t, (t) => Q(e, t, n), { discard: !0 }), cr = (e, t, n) => d.gen(function* () {
2159
- let r = process.hrtime.bigint(), i = sr(n.declared), a = t.op;
2259
+ }), d.map(() => void 0)), $ = (e, t, n) => d.forEach(t, (t) => Q(e, t, n), { discard: !0 }), yr = (e, t, n) => d.gen(function* () {
2260
+ let r = process.hrtime.bigint(), i = vr(n.declared), a = t.op;
2160
2261
  switch (a.kind) {
2161
2262
  case "create-table": {
2162
2263
  let t = yield* e.onDialectOrElse({
2163
- mysql: () => d.succeed(Sn(a)),
2164
- mssql: () => d.succeed(Mn(a)),
2165
- sqlite: () => d.succeed(Dn(a)),
2166
- orElse: () => d.succeed(vn(a))
2264
+ mysql: () => d.succeed(On(a)),
2265
+ mssql: () => d.succeed(Rn(a)),
2266
+ sqlite: () => d.succeed(Nn(a)),
2267
+ orElse: () => d.succeed(wn(a))
2167
2268
  });
2168
2269
  for (let n of t) yield* Q(e, n, a.kind);
2169
2270
  break;
2170
2271
  }
2171
2272
  case "drop-table": {
2172
- let t = process.env.VOLTRO_SOFT_DROP === "1", n = (/* @__PURE__ */ new Date()).toISOString(), r = (e) => t ? Fn(a, n, e) : Pn(a, e);
2273
+ let t = process.env.VOLTRO_SOFT_DROP === "1", n = (/* @__PURE__ */ new Date()).toISOString(), r = (e) => t ? Vn(a, n, e) : Bn(a, e);
2173
2274
  yield* e.onDialectOrElse({
2174
2275
  mysql: () => Q(e, r(K), a.kind),
2175
2276
  orElse: () => Q(e, r(G), a.kind)
@@ -2179,71 +2280,85 @@ BEGIN
2179
2280
  case "drop-column": {
2180
2281
  let t = process.env.VOLTRO_SOFT_DROP === "1", n = (/* @__PURE__ */ new Date()).toISOString();
2181
2282
  yield* e.onDialectOrElse({
2182
- mysql: () => Q(e, t ? cn(a, n, K) : on(a), a.kind),
2183
- orElse: () => Q(e, t ? cn(a, n, G) : an(a, G), a.kind)
2283
+ mysql: () => Q(e, t ? mn(a, n, K) : fn(a), a.kind),
2284
+ orElse: () => Q(e, t ? mn(a, n, G) : dn(a, G), a.kind)
2184
2285
  });
2185
2286
  break;
2186
2287
  }
2187
2288
  case "rename-column":
2188
2289
  yield* e.onDialectOrElse({
2189
- mysql: () => Q(e, sn(a, K), a.kind),
2290
+ mysql: () => Q(e, pn(a, K), a.kind),
2190
2291
  mssql: () => Q(e, `EXEC sp_rename N'${a.table.replace(/'/g, "''")}.${a.from.replace(/'/g, "''")}', N'${a.to.replace(/'/g, "''")}', 'COLUMN';`, a.kind),
2191
- orElse: () => Q(e, sn(a, G), a.kind)
2292
+ orElse: () => Q(e, pn(a, G), a.kind)
2192
2293
  });
2193
2294
  break;
2194
2295
  case "add-index":
2195
2296
  yield* e.onDialectOrElse({
2196
- mysql: () => Q(e, Bn(a, n.declared), a.kind),
2197
- mssql: () => $(e, [...Gn(a.table, a.index.columns, n.declared), Wn(a)], a.kind),
2198
- orElse: () => Q(e, zn(a, t.classification === "online-required"), a.kind)
2297
+ mysql: () => Q(e, Kn(a, n.declared), a.kind),
2298
+ mssql: () => $(e, [...nr(a.table, a.index.columns, n.declared), tr(a)], a.kind),
2299
+ orElse: () => Q(e, Gn(a, t.classification === "online-required"), a.kind)
2199
2300
  });
2200
2301
  break;
2201
2302
  case "drop-index":
2202
2303
  yield* e.onDialectOrElse({
2203
- mysql: () => Q(e, Hn(a), a.kind),
2204
- mssql: () => Q(e, Un(a), a.kind),
2205
- orElse: () => Q(e, Vn(a), a.kind)
2304
+ mysql: () => Q(e, Jn(a), a.kind),
2305
+ mssql: () => Q(e, Yn(a), a.kind),
2306
+ orElse: () => Q(e, qn(a), a.kind)
2307
+ });
2308
+ break;
2309
+ case "rename-table":
2310
+ yield* e.onDialectOrElse({
2311
+ mysql: () => Q(e, Xn(a, K), a.kind),
2312
+ mssql: () => Q(e, Zn(a), a.kind),
2313
+ orElse: () => Q(e, Xn(a, G), a.kind)
2314
+ });
2315
+ break;
2316
+ case "rename-index":
2317
+ yield* e.onDialectOrElse({
2318
+ mysql: () => Q(e, $n(a), a.kind),
2319
+ mssql: () => Q(e, er(a), a.kind),
2320
+ orElse: () => Q(e, Qn(a), a.kind)
2206
2321
  });
2207
2322
  break;
2208
2323
  case "add-unique":
2209
2324
  yield* e.onDialectOrElse({
2210
- mysql: () => Q(e, qn(a, n.declared), a.kind),
2325
+ mysql: () => Q(e, ir(a, n.declared), a.kind),
2211
2326
  sqlite: () => $(e, X(a.table, n.declared), a.kind),
2212
- mssql: () => $(e, [...Gn(a.table, [a.column], n.declared), Kn(a)], a.kind),
2213
- orElse: () => Q(e, Kn(a), a.kind)
2327
+ mssql: () => $(e, [...nr(a.table, [a.column], n.declared), rr(a)], a.kind),
2328
+ orElse: () => Q(e, rr(a), a.kind)
2214
2329
  });
2215
2330
  break;
2216
2331
  case "drop-unique":
2217
2332
  yield* e.onDialectOrElse({
2218
- mysql: () => Q(e, $n(a), a.kind),
2333
+ mysql: () => Q(e, ur(a), a.kind),
2219
2334
  sqlite: () => $(e, X(a.table, n.declared), a.kind),
2220
- orElse: () => Q(e, Qn(a), a.kind)
2335
+ orElse: () => Q(e, lr(a), a.kind)
2221
2336
  });
2222
2337
  break;
2223
2338
  case "add-unique-composite":
2224
2339
  yield* e.onDialectOrElse({
2225
- mysql: () => Q(e, Yn(a, n.declared), a.kind),
2340
+ mysql: () => Q(e, or(a, n.declared), a.kind),
2226
2341
  sqlite: () => $(e, X(a.table, n.declared), a.kind),
2227
- mssql: () => $(e, [...Gn(a.table, a.fields, n.declared), Jn(a)], a.kind),
2228
- orElse: () => Q(e, Jn(a), a.kind)
2342
+ mssql: () => $(e, [...nr(a.table, a.fields, n.declared), ar(a)], a.kind),
2343
+ orElse: () => Q(e, ar(a), a.kind)
2229
2344
  });
2230
2345
  break;
2231
2346
  case "drop-unique-composite":
2232
2347
  yield* e.onDialectOrElse({
2233
- mysql: () => Q(e, Zn(a), a.kind),
2348
+ mysql: () => Q(e, cr(a), a.kind),
2234
2349
  sqlite: () => $(e, X(a.table, n.declared), a.kind),
2235
- orElse: () => Q(e, Xn(a), a.kind)
2350
+ orElse: () => Q(e, sr(a), a.kind)
2236
2351
  });
2237
2352
  break;
2238
2353
  case "add-foreign-key":
2239
2354
  yield* e.onDialectOrElse({
2240
- mysql: () => $(e, er(a, K), a.kind),
2355
+ mysql: () => $(e, dr(a, K), a.kind),
2241
2356
  sqlite: () => $(e, X(a.table, n.declared), a.kind),
2242
- orElse: () => $(e, er(a, G), a.kind)
2357
+ orElse: () => $(e, dr(a, G), a.kind)
2243
2358
  });
2244
2359
  break;
2245
2360
  case "add-column": {
2246
- let n = or(a, t, i, yield* e.onDialectOrElse({
2361
+ let n = _r(a, t, i, yield* e.onDialectOrElse({
2247
2362
  mysql: () => d.succeed("mariadb"),
2248
2363
  mssql: () => d.succeed("mssql"),
2249
2364
  sqlite: () => d.succeed("sqlite"),
@@ -2289,37 +2404,37 @@ BEGIN
2289
2404
  yield* e.onDialectOrElse({
2290
2405
  mysql: () => {
2291
2406
  let t = q(n.declared, a.table, a.column);
2292
- return t ? Q(e, `ALTER TABLE ${K(a.table)} MODIFY COLUMN ${fn(t, a.column, a.toNullable)};`, a.kind) : d.die(/* @__PURE__ */ Error(`alter-column-nullability on mariadb needs the declared column '${a.table}.${a.column}' (to render MODIFY COLUMN); it was not in ctx.declared.`));
2407
+ return t ? Q(e, `ALTER TABLE ${K(a.table)} MODIFY COLUMN ${vn(t, a.column, a.toNullable)};`, a.kind) : d.die(/* @__PURE__ */ Error(`alter-column-nullability on mariadb needs the declared column '${a.table}.${a.column}' (to render MODIFY COLUMN); it was not in ctx.declared.`));
2293
2408
  },
2294
2409
  mssql: () => {
2295
2410
  let t = q(n.declared, a.table, a.column);
2296
- return t ? Q(e, On(t, a.column, a.table, a.toNullable), a.kind) : d.die(/* @__PURE__ */ Error(`alter-column-nullability on mssql needs the declared column '${a.table}.${a.column}'.`));
2411
+ return t ? Q(e, Pn(t, a.column, a.table, a.toNullable), a.kind) : d.die(/* @__PURE__ */ Error(`alter-column-nullability on mssql needs the declared column '${a.table}.${a.column}'.`));
2297
2412
  },
2298
2413
  sqlite: () => $(e, X(a.table, n.declared), a.kind),
2299
2414
  orElse: () => Q(e, `ALTER TABLE ${G(a.table)} ALTER COLUMN ${G(a.column)} ${a.toNullable ? "DROP NOT NULL" : "SET NOT NULL"};`, a.kind)
2300
2415
  });
2301
2416
  break;
2302
2417
  case "alter-column-default": {
2303
- let t = dn(n.declared, a.table, a.column);
2418
+ let t = _n(n.declared, a.table, a.column);
2304
2419
  yield* e.onDialectOrElse({
2305
- mysql: () => Q(e, ln(a, K, (e) => pn(e, t)), a.kind),
2306
- mssql: () => Q(e, kn(a), a.kind),
2420
+ mysql: () => Q(e, hn(a, K, (e) => yn(e, t)), a.kind),
2421
+ mssql: () => Q(e, Fn(a), a.kind),
2307
2422
  sqlite: () => $(e, X(a.table, n.declared), a.kind),
2308
- orElse: () => Q(e, ln(a, G, (e) => hn(e, t)), a.kind)
2423
+ orElse: () => Q(e, hn(a, G, (e) => xn(e, t)), a.kind)
2309
2424
  });
2310
2425
  break;
2311
2426
  }
2312
2427
  case "alter-column-type": {
2313
- let r = W(dn(n.declared, a.table, a.column) ?? { type: a.to }), i = a.using ? ` USING ${a.using}` : "";
2428
+ let r = U(_n(n.declared, a.table, a.column) ?? { type: a.to }), i = a.using ? ` USING ${a.using}` : "";
2314
2429
  if (t.classification !== "online-required") {
2315
2430
  yield* e.onDialectOrElse({
2316
2431
  mysql: () => {
2317
2432
  let t = q(n.declared, a.table, a.column);
2318
- return t ? Q(e, `ALTER TABLE ${K(a.table)} MODIFY COLUMN ${fn(t, a.column)};`, a.kind) : d.die(/* @__PURE__ */ Error(`alter-column-type on mariadb needs the declared column '${a.table}.${a.column}' (to render MODIFY COLUMN); it was not in ctx.declared.`));
2433
+ return t ? Q(e, `ALTER TABLE ${K(a.table)} MODIFY COLUMN ${vn(t, a.column)};`, a.kind) : d.die(/* @__PURE__ */ Error(`alter-column-type on mariadb needs the declared column '${a.table}.${a.column}' (to render MODIFY COLUMN); it was not in ctx.declared.`));
2319
2434
  },
2320
2435
  mssql: () => {
2321
2436
  let t = q(n.declared, a.table, a.column);
2322
- return t ? Q(e, On(t, a.column, a.table), a.kind) : d.die(/* @__PURE__ */ Error(`alter-column-type on mssql needs the declared column '${a.table}.${a.column}'.`));
2437
+ return t ? Q(e, Pn(t, a.column, a.table), a.kind) : d.die(/* @__PURE__ */ Error(`alter-column-type on mssql needs the declared column '${a.table}.${a.column}'.`));
2323
2438
  },
2324
2439
  sqlite: () => $(e, X(a.table, n.declared), a.kind),
2325
2440
  orElse: () => Q(e, `ALTER TABLE ${G(a.table)} ALTER COLUMN ${G(a.column)} TYPE ${r}${i};`, a.kind)
@@ -2343,23 +2458,23 @@ BEGIN
2343
2458
  }
2344
2459
  case "drop-foreign-key":
2345
2460
  yield* e.onDialectOrElse({
2346
- mysql: () => Q(e, nr(a), a.kind),
2461
+ mysql: () => Q(e, pr(a), a.kind),
2347
2462
  sqlite: () => $(e, X(a.table, n.declared), a.kind),
2348
- orElse: () => Q(e, tr(a), a.kind)
2463
+ orElse: () => Q(e, fr(a), a.kind)
2349
2464
  });
2350
2465
  break;
2351
2466
  case "add-check":
2352
2467
  yield* e.onDialectOrElse({
2353
- mysql: () => Q(e, rr(a, K), a.kind),
2468
+ mysql: () => Q(e, mr(a, K), a.kind),
2354
2469
  sqlite: () => $(e, X(a.table, n.declared), a.kind),
2355
- orElse: () => Q(e, rr(a, G), a.kind)
2470
+ orElse: () => Q(e, mr(a, G), a.kind)
2356
2471
  });
2357
2472
  break;
2358
2473
  case "drop-check":
2359
2474
  yield* e.onDialectOrElse({
2360
- mysql: () => Q(e, ar(a), a.kind),
2475
+ mysql: () => Q(e, gr(a), a.kind),
2361
2476
  sqlite: () => $(e, X(a.table, n.declared), a.kind),
2362
- orElse: () => Q(e, ir(a), a.kind)
2477
+ orElse: () => Q(e, hr(a), a.kind)
2363
2478
  });
2364
2479
  break;
2365
2480
  }
@@ -2368,7 +2483,7 @@ BEGIN
2368
2483
  status: "applied",
2369
2484
  durationMs: Number((process.hrtime.bigint() - r) / 1000000n)
2370
2485
  };
2371
- }), lr = (e, t, n) => d.gen(function* () {
2486
+ }), br = (e, t, n) => d.gen(function* () {
2372
2487
  let r = t.operations.filter((e) => e.blocked);
2373
2488
  if (r.length > 0) return yield* d.die(/* @__PURE__ */ Error(`applyPlan: refusing to execute — ${r.length} blocked operations. Run \`voltro db plan\` to see the fixes.`));
2374
2489
  yield* C(e);
@@ -2381,9 +2496,9 @@ BEGIN
2381
2496
  }), i = r ? t.operations.filter((e) => e.classification !== "online-required") : [], o = r ? t.operations.filter((e) => e.classification === "online-required") : t.operations;
2382
2497
  i.length > 0 && (yield* e.withTransaction(d.gen(function* () {
2383
2498
  let e = yield* p.SqlClient;
2384
- for (let t of i) a.push(yield* cr(e, t, n));
2499
+ for (let t of i) a.push(yield* yr(e, t, n));
2385
2500
  })));
2386
- for (let t of o) a.push(yield* cr(e, t, n));
2501
+ for (let t of o) a.push(yield* yr(e, t, n));
2387
2502
  } finally {
2388
2503
  yield* w(e).pipe(d.orDie);
2389
2504
  }
@@ -2417,19 +2532,19 @@ BEGIN
2417
2532
  source: n.source,
2418
2533
  ...n.notes ? { notes: n.notes } : {}
2419
2534
  };
2420
- }), ur = (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"), dr = (e) => e`
2535
+ }), xr = (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"), Sr = (e) => e`
2421
2536
  SELECT fingerprint
2422
2537
  FROM _voltro_migration_plans
2423
2538
  ORDER BY ${e("appliedAt")} DESC
2424
2539
  LIMIT 1
2425
- `.pipe(d.map((e) => e.length > 0 ? e[0].fingerprint : void 0), d.catchAll(() => d.succeed(void 0))), fr = (e) => e.onDialectOrElse({
2540
+ `.pipe(d.map((e) => e.length > 0 ? e[0].fingerprint : void 0), d.catchAll(() => d.succeed(void 0))), Cr = (e) => e.onDialectOrElse({
2426
2541
  pg: () => "postgres",
2427
2542
  mysql: () => "mysql",
2428
2543
  mssql: () => "mssql",
2429
2544
  sqlite: () => "sqlite",
2430
2545
  orElse: () => "sqlite"
2431
- }), pr = (e, t) => d.gen(function* () {
2432
- let n = j(N(t, fr(e))), r = yield* dr(e);
2546
+ }), wr = (e, t) => d.gen(function* () {
2547
+ let n = j(N(t, Cr(e))), r = yield* Sr(e);
2433
2548
  return r === n ? {
2434
2549
  kind: "up-to-date",
2435
2550
  fingerprint: n
@@ -2438,23 +2553,23 @@ BEGIN
2438
2553
  expected: n,
2439
2554
  ...r === void 0 ? {} : { actual: r }
2440
2555
  };
2441
- }), mr = [
2556
+ }), Tr = [
2442
2557
  "pgeagertest_",
2443
2558
  "mig_e2e_",
2444
2559
  "mig_test_",
2445
2560
  "mysqleagertest_",
2446
2561
  "mssqleagertest_",
2447
2562
  "sqliteeagertest_"
2448
- ], hr = (e) => mr.some((t) => e.startsWith(t)), gr = (e, t) => d.gen(function* () {
2563
+ ], Er = (e) => Tr.some((t) => e.startsWith(t)), Dr = (e, t) => d.gen(function* () {
2449
2564
  if (process.env.VOLTRO_TEST_FIXTURE_GC === "off") return [];
2450
- let n = t.filter((e) => hr(e.name)).map((e) => e.name);
2565
+ let n = t.filter((e) => Er(e.name)).map((e) => e.name);
2451
2566
  if (n.length === 0) return [];
2452
2567
  for (let t of n) yield* e.unsafe(`DROP TABLE IF EXISTS "${t}" CASCADE`).pipe(d.catchAll(() => d.void));
2453
2568
  return n;
2454
- }), _r = () => {
2569
+ }), Or = () => {
2455
2570
  let e = (process.env.VOLTRO_DB_IGNORE_TABLES ?? "").split(",").map((e) => e.trim()).filter((e) => e.length > 0);
2456
2571
  return e.length > 0 ? { ignoreTables: e } : {};
2457
- }, vr = (e) => {
2572
+ }, kr = (e) => {
2458
2573
  if (e === void 0) return;
2459
2574
  let t = e.trim();
2460
2575
  if (t === "") return;
@@ -2464,73 +2579,73 @@ BEGIN
2464
2579
  kind: "tables",
2465
2580
  tables: new Set(n)
2466
2581
  } : void 0;
2467
- }, yr = (e) => typeof e.table == "string" ? e.table : void 0, br = (e, t = { kind: "all" }) => ({
2582
+ }, Ar = (e) => typeof e.table == "string" ? e.table : void 0, jr = (e, t = { kind: "all" }) => ({
2468
2583
  ...e,
2469
2584
  operations: e.operations.map((e) => {
2470
2585
  if (!e.blocked || e.classification !== "lossy") return e;
2471
2586
  if (t?.kind === "tables") {
2472
- let n = yr(e.op);
2587
+ let n = Ar(e.op);
2473
2588
  if (n === void 0 || !t.tables.has(n)) return e;
2474
2589
  }
2475
2590
  let { blocked: n, ...r } = e;
2476
2591
  return r;
2477
2592
  })
2478
- }), xr = (e, t, n) => t === "postgres" ? st(e, n).pipe(d.flatMap((e) => {
2593
+ }), Mr = (e, t, n) => t === "postgres" ? st(e, n).pipe(d.flatMap((e) => {
2479
2594
  let t = ct(e);
2480
2595
  return t === void 0 ? d.void : d.logWarning(`auto-migrate: ${t}`).pipe(d.annotateLogs({ scope: "voltro:migrate" }));
2481
- }), d.catchAll(() => d.void)) : d.void, Sr = (e, t, n) => d.gen(function* () {
2482
- let r = fr(e), i = t.filter((e) => !P(e.tableName));
2596
+ }), d.catchAll(() => d.void)) : d.void, Nr = (e, t, n) => d.gen(function* () {
2597
+ let r = Cr(e), i = t;
2483
2598
  if (process.env.VOLTRO_MIGRATE_FORCE !== "1") {
2484
2599
  let t = j(N(i, r));
2485
- if ((yield* dr(e)) === t) return yield* xr(e, r, i), {
2600
+ if ((yield* Sr(e)) === t) return yield* Mr(e, r, i), {
2486
2601
  kind: "up-to-date",
2487
2602
  fingerprint: t
2488
2603
  };
2489
2604
  }
2490
- let a = yield* H(e), o = yield* gr(e, a.tables);
2605
+ let a = yield* V(e), o = yield* Dr(e, a.tables);
2491
2606
  o.length > 0 && (yield* d.logInfo(`auto-migrate: reaped ${o.length} test-fixture leftover(s)`).pipe(d.annotateLogs({
2492
2607
  scope: "voltro:migrate",
2493
2608
  count: o.length
2494
- })), a = yield* H(e));
2495
- let s = Lt({
2609
+ })), a = yield* V(e));
2610
+ let s = new Set(t.map((e) => e.tableName)), c = (e) => e.filter((e) => !ut(e.name) || s.has(e.name)), l = Wt({
2496
2611
  declared: i,
2497
- live: { tables: a.tables.filter((e) => !P(e.name)) },
2612
+ live: { tables: c(a.tables) },
2498
2613
  dialect: r,
2499
- ..._r()
2614
+ ...Or()
2500
2615
  });
2501
- if (s.summary.blocked > 0) {
2502
- let e = s.operations.filter((e) => e.blocked).every((e) => e.classification === "lossy"), t = vr(process.env.VOLTRO_DESTRUCTIVE_OK);
2503
- if (t === void 0 || !e || (s = br(s, t), s.operations.some((e) => e.blocked))) return {
2616
+ if (l.summary.blocked > 0) {
2617
+ let e = l.operations.filter((e) => e.blocked).every((e) => e.classification === "lossy"), t = kr(process.env.VOLTRO_DESTRUCTIVE_OK);
2618
+ if (t === void 0 || !e || (l = jr(l, t), l.operations.some((e) => e.blocked))) return {
2504
2619
  kind: "refused-blocked",
2505
- plan: s
2620
+ plan: l
2506
2621
  };
2507
2622
  }
2508
- return s.operations.length === 0 ? {
2623
+ return l.operations.length === 0 ? {
2509
2624
  kind: "up-to-date",
2510
- fingerprint: s.toFingerprint
2625
+ fingerprint: l.toFingerprint
2511
2626
  } : {
2512
2627
  kind: "applied",
2513
- applied: yield* lr(e, s, {
2628
+ applied: yield* br(e, l, {
2514
2629
  declared: t,
2515
2630
  appliedBy: n.appliedBy,
2516
2631
  environment: n.environment === "prod" ? "dev" : n.environment,
2517
2632
  source: "auto-diff",
2518
2633
  replan: (e) => d.gen(function* () {
2519
- let t = yield* H(e);
2520
- return Lt({
2634
+ let t = yield* V(e);
2635
+ return Wt({
2521
2636
  declared: i,
2522
- live: { tables: t.tables.filter((e) => !P(e.name)) },
2637
+ live: { tables: c(t.tables) },
2523
2638
  dialect: r,
2524
- ..._r()
2639
+ ...Or()
2525
2640
  });
2526
2641
  })
2527
2642
  }),
2528
- plan: s
2643
+ plan: l
2529
2644
  };
2530
- }), Cr = (e, t, n) => process.env.VOLTRO_AUTO_MIGRATE === "0" ? d.succeed({
2645
+ }), Pr = (e, t, n) => process.env.VOLTRO_AUTO_MIGRATE === "0" ? d.succeed({
2531
2646
  kind: "skipped",
2532
2647
  reason: "VOLTRO_AUTO_MIGRATE=0"
2533
- }) : n.environment === "prod" ? pr(e, t) : Sr(e, t, n), wr = (e, t) => {
2648
+ }) : n.environment === "prod" ? wr(e, t) : Nr(e, t, n), Fr = (e, t) => {
2534
2649
  switch (e.kind) {
2535
2650
  case "skipped": return `auto-migrate: skipped (${e.reason})`;
2536
2651
  case "up-to-date": return `auto-migrate: schema up to date (${t}, fingerprint=${M(e.fingerprint)})`;
@@ -2540,7 +2655,7 @@ BEGIN
2540
2655
  }
2541
2656
  case "prod-mismatch": return `auto-migrate: SCHEMA FINGERPRINT MISMATCH — declared=${M(e.expected)}` + (e.actual ? ` live=${M(e.actual)}` : " live=<no _voltro_migration_plans row>") + ". Run `voltro db apply --plan plan.json` from the deploy pipeline before serving.";
2542
2657
  case "refused-blocked": {
2543
- 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` + ur(e.plan), c = [""];
2658
+ 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` + xr(e.plan), c = [""];
2544
2659
  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) {
2545
2660
  let t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map();
2546
2661
  for (let r of e.plan.operations) {
@@ -2557,7 +2672,7 @@ BEGIN
2557
2672
  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");
2558
2673
  }
2559
2674
  }
2560
- }, Tr = /* @__PURE__ */ new Set([
2675
+ }, Ir = /* @__PURE__ */ new Set([
2561
2676
  "node_modules",
2562
2677
  "dist",
2563
2678
  "build",
@@ -2566,11 +2681,11 @@ BEGIN
2566
2681
  ".next",
2567
2682
  ".git",
2568
2683
  ".framework"
2569
- ]), Er = async (e) => {
2684
+ ]), Lr = async (e) => {
2570
2685
  let t = [], n = async (e) => {
2571
2686
  let r = await h.readdir(e, { withFileTypes: !0 }).catch(() => []);
2572
2687
  for (let i of r) {
2573
- if (Tr.has(i.name)) continue;
2688
+ if (Ir.has(i.name)) continue;
2574
2689
  let r = g(e, i.name);
2575
2690
  i.isDirectory() ? await n(r) : i.isFile() && l.test(i.name) && t.push(r);
2576
2691
  }
@@ -2579,7 +2694,7 @@ BEGIN
2579
2694
  let n = e.split("/").pop() ?? e, r = t.split("/").pop() ?? t;
2580
2695
  return n.localeCompare(r);
2581
2696
  });
2582
- }, Dr = async (e) => {
2697
+ }, Rr = async (e) => {
2583
2698
  let t = [];
2584
2699
  for (let n of e) {
2585
2700
  let e = (await import(ee(n).href)).default;
@@ -2593,11 +2708,11 @@ BEGIN
2593
2708
  });
2594
2709
  }
2595
2710
  return t;
2596
- }, Or = (e) => e`
2711
+ }, zr = (e) => e`
2597
2712
  SELECT ${e("id")}
2598
2713
  FROM ${e("_voltro_migration_plans")}
2599
2714
  WHERE ${e("source")} = 'file'
2600
- `.pipe(d.map((e) => e.map((e) => e.id)), d.catchAll(() => d.succeed([]))), kr = (e, t, n, r) => d.gen(function* () {
2715
+ `.pipe(d.map((e) => e.map((e) => e.id)), d.catchAll(() => d.succeed([]))), Br = (e, t, n, r) => d.gen(function* () {
2601
2716
  let i = Date.now(), a = (/* @__PURE__ */ new Date()).toISOString(), o = {
2602
2717
  sql: e,
2603
2718
  log: {
@@ -2630,9 +2745,9 @@ BEGIN
2630
2745
  ${r}, ${n}, ${"file"},
2631
2746
  ${c}, ${a}, ${t.migration.description})
2632
2747
  `, { durationMs: c };
2633
- }), Ar = (e, t) => d.gen(function* () {
2748
+ }), Vr = (e, t) => d.gen(function* () {
2634
2749
  let n = yield* d.tryPromise({
2635
- try: () => Er(g(t, "migrations")),
2750
+ try: () => Lr(g(t, "migrations")),
2636
2751
  catch: (e) => e
2637
2752
  });
2638
2753
  if (n.length === 0) return {
@@ -2640,20 +2755,20 @@ BEGIN
2640
2755
  skipped: []
2641
2756
  };
2642
2757
  let r = yield* d.tryPromise({
2643
- try: () => Dr(n),
2758
+ try: () => Rr(n),
2644
2759
  catch: (e) => e
2645
2760
  });
2646
2761
  if (r.length === 0) return {
2647
2762
  pending: [],
2648
2763
  skipped: []
2649
2764
  };
2650
- let i = new Set(yield* Or(e));
2765
+ let i = new Set(yield* zr(e));
2651
2766
  return {
2652
2767
  pending: r.filter((e) => !i.has(e.migration.id)),
2653
2768
  skipped: r.filter((e) => i.has(e.migration.id)).map((e) => e.migration.id)
2654
2769
  };
2655
- }), jr = (e, t) => Ar(e, t).pipe(d.map((e) => e.pending.map((e) => e.migration.id))), Mr = (e, t) => d.gen(function* () {
2656
- let { pending: n, skipped: r } = yield* Ar(e, t.projectRoot);
2770
+ }), Hr = (e, t) => Vr(e, t).pipe(d.map((e) => e.pending.map((e) => e.migration.id))), Ur = (e, t) => d.gen(function* () {
2771
+ let { pending: n, skipped: r } = yield* Vr(e, t.projectRoot);
2657
2772
  if (n.length === 0) return {
2658
2773
  applied: [],
2659
2774
  skipped: r
@@ -2667,7 +2782,7 @@ BEGIN
2667
2782
  id: r.migration.id,
2668
2783
  file: r.file
2669
2784
  }));
2670
- let { durationMs: n } = yield* kr(e, r, t.env, t.appliedBy);
2785
+ let { durationMs: n } = yield* Br(e, r, t.env, t.appliedBy);
2671
2786
  i.push({
2672
2787
  id: r.migration.id,
2673
2788
  durationMs: n
@@ -2684,18 +2799,18 @@ BEGIN
2684
2799
  applied: i,
2685
2800
  skipped: r
2686
2801
  };
2687
- }), Nr = (e, t) => e`
2802
+ }), Wr = (e, t) => e`
2688
2803
  SELECT ${e("id")}
2689
2804
  FROM ${e("_voltro_migration_plans")}
2690
2805
  WHERE ${e("id")} = ${t} AND ${e("source")} = 'file'
2691
2806
  LIMIT 1
2692
- `, Pr = (e, t) => d.gen(function* () {
2693
- if (!(yield* Nr(e, t.id))[0]) return yield* d.fail(/* @__PURE__ */ Error(`rollback: ${t.id} not found in _voltro_migration_plans (file source)`));
2807
+ `, Gr = (e, t) => d.gen(function* () {
2808
+ if (!(yield* Wr(e, t.id))[0]) return yield* d.fail(/* @__PURE__ */ Error(`rollback: ${t.id} not found in _voltro_migration_plans (file source)`));
2694
2809
  let n = yield* d.tryPromise({
2695
- try: () => Er(g(t.projectRoot, "migrations")),
2810
+ try: () => Lr(g(t.projectRoot, "migrations")),
2696
2811
  catch: (e) => e
2697
2812
  }), r = (yield* d.tryPromise({
2698
- try: () => Dr(n),
2813
+ try: () => Rr(n),
2699
2814
  catch: (e) => e
2700
2815
  })).find((e) => e.migration.id === t.id);
2701
2816
  if (!r) return yield* d.fail(/* @__PURE__ */ Error(`rollback: file for migration ${t.id} not found on disk under ${t.projectRoot}/migrations/`));
@@ -2728,7 +2843,7 @@ BEGIN
2728
2843
  } finally {
2729
2844
  yield* w(e).pipe(d.orDie);
2730
2845
  }
2731
- }), Fr = (e) => d.gen(function* () {
2846
+ }), Kr = (e) => d.gen(function* () {
2732
2847
  let t = yield* p.SqlClient, n = yield* t`
2733
2848
  SELECT id, fingerprint, appliedAt FROM _voltro_migration_plans
2734
2849
  WHERE source = 'auto-diff'
@@ -2773,10 +2888,10 @@ BEGIN
2773
2888
  snapshotFingerprint: e.fingerprint,
2774
2889
  snapshotId: i
2775
2890
  };
2776
- }), Ir = (e, ...t) => ({
2891
+ }), qr = (e, ...t) => ({
2777
2892
  _tag: "RawSqlFragment",
2778
2893
  strings: [...e],
2779
2894
  values: [...t]
2780
- }), Lr = (e) => typeof e == "object" && !!e && e._tag === "RawSqlFragment";
2895
+ }), Jr = (e) => typeof e == "object" && !!e && e._tag === "RawSqlFragment";
2781
2896
  //#endregion
2782
- export { l as FILE_MIGRATION_PATTERN, ot as REACTIVE_TRIGGER_PREFIX, S as VOLTRO_MIGRATION_LOCK_KEY, C as acquireMigrationLock, Je as applyNamespacedSchema, lr as applyPlan, He as applySchema, Wt as chunkTables, N as declaredSnapshot, ye as defaultArrayClause, ve as defaultClause, O as defaultJsonClause, wr as describeOutcome, vr as destructiveScope, st as detectReactiveTriggerDrift, an as emitDropColumnDdl, on as emitDropColumnDdlMysql, Ve as emitFrameworkBootstrapSql, ze as emitNamespaceProvisionDdl, Be as emitNamespacedSchemaSql, A as emitSchemaSql, j as fingerprintSchema, ct as formatReactiveTriggerDrift, _r as ignoreTablesFromEnv, H as introspectSchema, o as isFileMigration, Lr as isRawSqlFragment, zt as mapPgType, s as migration, k as numericIdSql, Rt as parseEnumCheck, jr as pendingFileMigrationIds, Lt as planMigrations, Ye as provisionTenantNamespace, w as releaseMigrationLock, xn as renderColumnMysql, gn as renderColumnPg, Pr as rollbackFileBasedMigration, Mr as runFileBasedMigrations, Xe as runFrameworkBootstrap, qe as runMigrate, Cr as runPlannedMigrations, M as shortFingerprint, nt as snapshotColumn, Ir as sql, D as sqlType, Fr as squashMigrationPlans, br as unblockLossy, T as withMigrationLock };
2897
+ export { l as FILE_MIGRATION_PATTERN, ot as REACTIVE_TRIGGER_PREFIX, re as VOLTRO_MIGRATION_LOCK_KEY, C as acquireMigrationLock, Je as applyNamespacedSchema, br as applyPlan, He as applySchema, Zt as chunkTables, N as declaredSnapshot, be as defaultArrayClause, ye as defaultClause, D as defaultJsonClause, Fr as describeOutcome, kr as destructiveScope, st as detectReactiveTriggerDrift, dn as emitDropColumnDdl, fn as emitDropColumnDdlMysql, Ve as emitFrameworkBootstrapSql, ze as emitNamespaceProvisionDdl, Be as emitNamespacedSchemaSql, A as emitSchemaSql, j as fingerprintSchema, ct as formatReactiveTriggerDrift, Or as ignoreTablesFromEnv, V as introspectSchema, o as isFileMigration, Jr as isRawSqlFragment, Kt as mapPgType, s as migration, O as numericIdSql, Gt as parseEnumCheck, Hr as pendingFileMigrationIds, Wt as planMigrations, Ye as provisionTenantNamespace, w as releaseMigrationLock, Dn as renderColumnMysql, Sn as renderColumnPg, Gr as rollbackFileBasedMigration, Ur as runFileBasedMigrations, Xe as runFrameworkBootstrap, qe as runMigrate, Pr as runPlannedMigrations, M as shortFingerprint, nt as snapshotColumn, qr as sql, E as sqlType, Kr as squashMigrationPlans, jr as unblockLossy, _e as withMigrationLock };