@voltro/database 0.17.0 → 0.18.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
@@ -834,12 +834,12 @@ BEGIN
834
834
  snapshot: n.get(e.tableName),
835
835
  columnDefs: e.fields
836
836
  }]));
837
- }, mt = (e) => (t, n) => t.name === e ? -1 : n.name === e ? 1 : t.name.localeCompare(n.name), F = (e) => {
837
+ }, F = (e) => {
838
838
  if (typeof e != "object" || !e) return JSON.stringify(e);
839
839
  if (Array.isArray(e)) return `[${e.map(F).join(",")}]`;
840
840
  let t = e;
841
841
  return `{${Object.keys(t).sort().map((e) => `${JSON.stringify(e)}:${F(t[e])}`).join(",")}}`;
842
- }, ht = (e) => {
842
+ }, mt = (e) => {
843
843
  if (!e.hasDefault || e.defaultValue === void 0 || e.defaultValue === null) return null;
844
844
  let t = e.defaultValue;
845
845
  if (typeof t == "boolean") return t ? "__BOOL_TRUE__" : "__BOOL_FALSE__";
@@ -855,8 +855,8 @@ BEGIN
855
855
  return F(JSON.parse(a));
856
856
  } catch {}
857
857
  return /^-?\d+(\.\d+)?$/.test(a) ? String(Number(a)) : a;
858
- }, gt = (e, t) => {
859
- let n = ht(e), r = ht(t);
858
+ }, ht = (e, t) => {
859
+ let n = mt(e), r = mt(t);
860
860
  if (n === r) return !0;
861
861
  let i = (e) => e === "1" || e === "true" ? "__BOOL_TRUE__" : e === "0" || e === "false" ? "__BOOL_FALSE__" : e;
862
862
  return i(n) === i(r);
@@ -869,18 +869,18 @@ BEGIN
869
869
  onDelete: t(e.onDelete),
870
870
  onUpdate: t(e.onUpdate)
871
871
  };
872
- }, _t = (e, t) => {
872
+ }, gt = (e, t) => {
873
873
  let n = e && e.length > 0 ? e : void 0, r = t && t.length > 0 ? t : void 0;
874
874
  if (!n && !r) return !0;
875
875
  if (!n || !r || n.length !== r.length) return !1;
876
876
  let i = [...n].sort(), a = [...r].sort();
877
877
  return i.every((e, t) => e === a[t]);
878
- }, vt = (e, t) => e.type === t.type && e.nullable === t.nullable && e.unique === t.unique && gt(e, t) && JSON.stringify(I(e.references)) === JSON.stringify(I(t.references)) && _t(e.oneOf, t.oneOf), yt = (e, t) => t.oneOf && t.oneOf.length > 0 ? L({
878
+ }, _t = (e, t) => e.type === t.type && e.nullable === t.nullable && e.unique === t.unique && ht(e, t) && JSON.stringify(I(e.references)) === JSON.stringify(I(t.references)) && gt(e.oneOf, t.oneOf), vt = (e, t) => t.oneOf && t.oneOf.length > 0 ? L({
879
879
  kind: "add-check",
880
880
  table: e,
881
881
  column: t.name,
882
882
  values: t.oneOf
883
- }, "safe", `enum-membership CHECK on ${e}.${t.name}`) : void 0, bt = (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])), xt = (e, t) => {
883
+ }, "safe", `enum-membership CHECK on ${e}.${t.name}`) : void 0, yt = (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])), bt = (e, t) => {
884
884
  let n = new Map(t.columns.map((e) => [e.name, e])), r = new Map(e.columns.map((e) => [e.name, e])), i = [], a = [], o = [];
885
885
  for (let t of e.columns) {
886
886
  let e = n.get(t.name);
@@ -888,7 +888,7 @@ BEGIN
888
888
  i.push(t);
889
889
  continue;
890
890
  }
891
- vt(t, e) || o.push({
891
+ _t(t, e) || o.push({
892
892
  declared: t,
893
893
  live: e
894
894
  });
@@ -899,11 +899,11 @@ BEGIN
899
899
  removed: a,
900
900
  changed: o
901
901
  };
902
- }, St = (e, t) => {
902
+ }, xt = (e, t) => {
903
903
  let n = new Map(t.indexes.map((e) => [e.name, e])), r = new Map(e.indexes.map((e) => [e.name, e])), i = [], a = [];
904
904
  for (let t of e.indexes) {
905
905
  let e = n.get(t.name);
906
- (!e || !bt(t, e)) && i.push(t);
906
+ (!e || !yt(t, e)) && i.push(t);
907
907
  }
908
908
  for (let e of t.indexes) r.has(e.name) || a.push(e);
909
909
  return {
@@ -916,30 +916,30 @@ BEGIN
916
916
  atomicByDialect: ft(e.kind),
917
917
  ...n ? { reason: n } : {},
918
918
  ...r ? { blocked: r } : {}
919
- }), Ct = (e, t, n) => {
919
+ }), St = (e, t, n) => {
920
920
  let r = {
921
921
  kind: "add-column",
922
922
  table: e,
923
923
  column: t
924
924
  };
925
925
  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` });
926
- }, wt = (e, t, n) => {
926
+ }, Ct = (e, t, n) => {
927
927
  let r = {
928
928
  kind: "drop-column",
929
929
  table: e,
930
930
  column: t.name
931
931
  };
932
932
  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` });
933
- }, Tt = (e, t, n, r) => L({
933
+ }, wt = (e, t, n, r) => L({
934
934
  kind: "create-table",
935
935
  table: e,
936
936
  columns: t,
937
937
  indexes: n,
938
938
  ...r && r.length > 0 ? { primaryKey: r } : {}
939
- }, "safe", "new table — no data to preserve"), Et = (e) => L({
939
+ }, "safe", "new table — no data to preserve"), Tt = (e) => L({
940
940
  kind: "drop-table",
941
941
  table: e
942
- }, "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" }), Dt = 5e4, Ot = (e, t, n, r) => {
942
+ }, "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" }), Et = 5e4, Dt = (e, t, n, r) => {
943
943
  let i = (n ?? 0) >= r, a;
944
944
  return a = t.unique ? t.columns.length === 1 ? {
945
945
  kind: "add-unique",
@@ -955,7 +955,7 @@ BEGIN
955
955
  table: e,
956
956
  index: t
957
957
  }, 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");
958
- }, kt = (e, t) => t.unique && t.columns.length > 1 ? L({
958
+ }, Ot = (e, t) => t.unique && t.columns.length > 1 ? L({
959
959
  kind: "drop-unique-composite",
960
960
  table: e,
961
961
  name: t.name
@@ -963,7 +963,7 @@ BEGIN
963
963
  kind: "drop-index",
964
964
  table: e,
965
965
  index: t.name
966
- }, "safe", "drop index (no data loss — index is derived data)"), At = (e, t) => {
966
+ }, "safe", "drop index (no data loss — index is derived data)"), kt = (e, t) => {
967
967
  if (e === "reference") return "text";
968
968
  switch (t) {
969
969
  case "sqlite":
@@ -971,7 +971,7 @@ BEGIN
971
971
  case "mssql": return e === "json" ? "text" : e;
972
972
  default: return e;
973
973
  }
974
- }, jt = (e, t, n, r, i, a) => {
974
+ }, At = (e, t, n, r, i, a) => {
975
975
  let o = [];
976
976
  if (t.nullable !== n.nullable) {
977
977
  let n = {
@@ -994,7 +994,7 @@ BEGIN
994
994
  table: e,
995
995
  column: t.name
996
996
  }, "safe", `drop unique constraint on ${e}.${t.name} — constraint is derived metadata, no data loss`));
997
- if (At(t.type, r) !== At(n.type, r)) {
997
+ if (kt(t.type, r) !== kt(n.type, r)) {
998
998
  let r = t.narrowedFrom;
999
999
  if (r && r.from === n.type) {
1000
1000
  let i = {
@@ -1017,7 +1017,7 @@ BEGIN
1017
1017
  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` }));
1018
1018
  }
1019
1019
  }
1020
- if (!gt(t, n)) {
1020
+ if (!ht(t, n)) {
1021
1021
  let n = {
1022
1022
  kind: "alter-column-default",
1023
1023
  table: e,
@@ -1027,13 +1027,13 @@ BEGIN
1027
1027
  };
1028
1028
  o.push(L(n, "safe", `default change on ${e}.${t.name} affects only future inserts`));
1029
1029
  }
1030
- if (!_t(t.oneOf, n.oneOf)) {
1030
+ if (!gt(t.oneOf, n.oneOf)) {
1031
1031
  n.oneOf && n.oneOf.length > 0 && o.push(L({
1032
1032
  kind: "drop-check",
1033
1033
  table: e,
1034
1034
  column: t.name
1035
1035
  }, "safe", `drop stale enum CHECK on ${e}.${t.name}`));
1036
- let r = yt(e, t);
1036
+ let r = vt(e, t);
1037
1037
  r && o.push(r);
1038
1038
  }
1039
1039
  if (JSON.stringify(I(t.references)) !== JSON.stringify(I(n.references)) && (n.references && o.push(L({
@@ -1056,7 +1056,7 @@ BEGIN
1056
1056
  }, "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')`));
1057
1057
  }
1058
1058
  return o;
1059
- }, Mt = (e, t, n) => {
1059
+ }, jt = (e, t, n) => {
1060
1060
  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));
1061
1061
  for (let [n, c] of Object.entries(t)) {
1062
1062
  let t = c.renamedFrom;
@@ -1072,7 +1072,7 @@ BEGIN
1072
1072
  consumedAddedNames: i,
1073
1073
  consumedRemovedNames: a
1074
1074
  };
1075
- }, Nt = (e) => {
1075
+ }, Mt = (e) => {
1076
1076
  let t = {
1077
1077
  safe: 0,
1078
1078
  needsDefault: 0,
@@ -1107,37 +1107,37 @@ BEGIN
1107
1107
  break;
1108
1108
  }
1109
1109
  return t;
1110
- }, Pt = (e) => {
1111
- let t = N(e.declared, e.dialect), n = pt(e.declared, t), r = new Map(e.live.tables.map((e) => [e.name, e])), i = e.onlineAfter ?? Dt, a = [];
1110
+ }, Nt = (e) => {
1111
+ let t = N(e.declared, e.dialect), n = pt(e.declared, t), r = new Map(e.live.tables.map((e) => [e.name, e])), i = e.onlineAfter ?? Et, a = [];
1112
1112
  for (let e of t.tables) if (!r.has(e.name)) {
1113
- a.push(Tt(e.name, e.columns, e.indexes, e.primaryKey));
1113
+ a.push(wt(e.name, e.columns, e.indexes, e.primaryKey));
1114
1114
  for (let t of e.columns) {
1115
- let n = yt(e.name, t);
1115
+ let n = vt(e.name, t);
1116
1116
  n && a.push(n);
1117
1117
  }
1118
1118
  }
1119
1119
  let o = new Set(e.ignoreTables ?? []);
1120
- for (let t of e.live.tables) n.has(t.name) || P(t.name) || o.has(t.name) || a.push(Et(t.name));
1120
+ for (let t of e.live.tables) n.has(t.name) || P(t.name) || o.has(t.name) || a.push(Tt(t.name));
1121
1121
  for (let o of t.tables) {
1122
1122
  let t = r.get(o.name);
1123
1123
  if (!t) continue;
1124
- let s = n.get(o.name), c = xt(o, t), l = St(o, t), u = Mt(s.table, s.columnDefs, c);
1124
+ let s = n.get(o.name), c = bt(o, t), l = xt(o, t), u = jt(s.table, s.columnDefs, c);
1125
1125
  a.push(...u.ops);
1126
1126
  for (let e of c.removed) {
1127
1127
  if (u.consumedRemovedNames.has(e.name)) continue;
1128
1128
  let t = s.columnDefs[e.name];
1129
- a.push(wt(o.name, e, t));
1129
+ a.push(Ct(o.name, e, t));
1130
1130
  }
1131
1131
  for (let e of c.added) {
1132
1132
  if (u.consumedAddedNames.has(e.name)) continue;
1133
1133
  let t = s.columnDefs[e.name];
1134
- a.push(Ct(o.name, e, t));
1135
- let n = yt(o.name, e);
1134
+ a.push(St(o.name, e, t));
1135
+ let n = vt(o.name, e);
1136
1136
  n && a.push(n);
1137
1137
  }
1138
- for (let e of l.added) a.push(Ot(o.name, e, t.rowCount, i));
1139
- for (let e of l.removed) a.push(kt(o.name, e));
1140
- for (let { declared: n, live: r } of c.changed) a.push(...jt(o.name, n, r, e.dialect, t.rowCount, i));
1138
+ for (let e of l.added) a.push(Dt(o.name, e, t.rowCount, i));
1139
+ for (let e of l.removed) a.push(Ot(o.name, e));
1140
+ for (let { declared: n, live: r } of c.changed) a.push(...At(o.name, n, r, e.dialect, t.rowCount, i));
1141
1141
  }
1142
1142
  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) => {
1143
1143
  let t = c.get(e);
@@ -1219,9 +1219,9 @@ BEGIN
1219
1219
  operations: v,
1220
1220
  fromFingerprint: j(e.live),
1221
1221
  toFingerprint: j(t),
1222
- summary: Nt(v)
1222
+ summary: Mt(v)
1223
1223
  };
1224
- }, Ft = (e) => {
1224
+ }, Pt = (e) => {
1225
1225
  let t = /[`"[]?([A-Za-z_][A-Za-z0-9_]*)[`"\]]?\s*(?:in\b|=)/i.exec(e);
1226
1226
  if (!t) return null;
1227
1227
  let n = [...e.matchAll(/'((?:[^']|'')*)'/g)].map((e) => e[1].replace(/''/g, "'"));
@@ -1229,7 +1229,7 @@ BEGIN
1229
1229
  column: t[1],
1230
1230
  values: n
1231
1231
  };
1232
- }, It = (e, t) => {
1232
+ }, Ft = (e, t) => {
1233
1233
  if (t === "vector") return "vector";
1234
1234
  switch (e) {
1235
1235
  case "text":
@@ -1264,25 +1264,25 @@ BEGIN
1264
1264
  case "SET DEFAULT": return "noAction";
1265
1265
  default: return "noAction";
1266
1266
  }
1267
- }, Lt = (e, t) => {
1267
+ }, It = (e, t) => {
1268
1268
  let n = e !== void 0 && e !== "" ? Number(e) : NaN;
1269
1269
  return Number.isInteger(n) && n > 0 ? n : t;
1270
- }, Rt = () => Lt(process.env.VOLTRO_INTROSPECT_BATCH, 20), zt = 300, Bt = () => {
1270
+ }, Lt = () => It(process.env.VOLTRO_INTROSPECT_BATCH, 20), Rt = 300, zt = () => {
1271
1271
  let e = process.env.VOLTRO_INTROSPECT_TIMEOUT_MS;
1272
- return e !== void 0 && e.trim() === "0" ? 0 : Lt(e, 3e4);
1273
- }, Vt = (e, t) => {
1272
+ return e !== void 0 && e.trim() === "0" ? 0 : It(e, 3e4);
1273
+ }, Bt = (e, t) => {
1274
1274
  let n = Number.isFinite(t) && t >= 1 ? Math.floor(t) : 1, r = [];
1275
1275
  for (let t = 0; t < e.length; t += n) r.push(e.slice(t, t + n));
1276
1276
  return r;
1277
- }, Ht = (e) => {
1278
- let t = Bt(), n = d.gen(function* () {
1277
+ }, Vt = (e) => {
1278
+ let t = zt(), n = d.gen(function* () {
1279
1279
  t > 0 && (yield* e.unsafe(`SET LOCAL statement_timeout = ${t}`));
1280
- let n = (t) => e.unsafe("(" + t.map((e) => `'${e.replace(/'/g, "''")}'`).join(", ") + ")"), r = (t) => e.unsafe(String(Math.max(0, Math.trunc(t)))), i = Rt(), a = (e, t) => d.gen(function* () {
1280
+ let n = (t) => e.unsafe("(" + t.map((e) => `'${e.replace(/'/g, "''")}'`).join(", ") + ")"), r = (t) => e.unsafe(String(Math.max(0, Math.trunc(t)))), i = Lt(), a = (e, t) => d.gen(function* () {
1281
1281
  let r = [];
1282
- for (let a of Vt(e, i)) a.length !== 0 && r.push(...yield* t(n(a)));
1282
+ for (let a of Bt(e, i)) a.length !== 0 && r.push(...yield* t(n(a)));
1283
1283
  return r;
1284
1284
  }), o = [];
1285
- for (let t = 0;; t += zt) {
1285
+ for (let t = 0;; t += Rt) {
1286
1286
  let n = yield* e`
1287
1287
  SELECT c.relname AS table_name,
1288
1288
  COALESCE(c.reltuples::bigint, 0) AS row_count
@@ -1290,9 +1290,9 @@ BEGIN
1290
1290
  JOIN pg_namespace n ON n.oid = c.relnamespace
1291
1291
  WHERE n.nspname = current_schema() AND c.relkind = 'r'
1292
1292
  ORDER BY c.relname
1293
- LIMIT ${r(zt)} OFFSET ${r(t)}
1293
+ LIMIT ${r(Rt)} OFFSET ${r(t)}
1294
1294
  `;
1295
- if (o.push(...n), n.length < zt) break;
1295
+ if (o.push(...n), n.length < Rt) break;
1296
1296
  }
1297
1297
  let s = /* @__PURE__ */ new Set(), c = [];
1298
1298
  for (let e of o) s.has(e.table_name) || (s.add(e.table_name), c.push(e));
@@ -1425,7 +1425,7 @@ BEGIN
1425
1425
  let ne = [];
1426
1426
  for (let e of c) {
1427
1427
  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 = b.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) => {
1428
- 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" : It(t.data_type, t.udt_name), c = a ? {
1428
+ 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" : Ft(t.data_type, t.udt_name), c = a ? {
1429
1429
  table: a.target_table,
1430
1430
  column: a.target_column,
1431
1431
  onDelete: R(a.delete_rule),
@@ -1478,7 +1478,7 @@ BEGIN
1478
1478
  let n = `${String(e)} ${String(e.cause ?? "")}`.toLowerCase();
1479
1479
  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);
1480
1480
  }));
1481
- }, Ut = (e, t) => {
1481
+ }, Ht = (e, t) => {
1482
1482
  switch (e.toLowerCase()) {
1483
1483
  case "varchar":
1484
1484
  case "char":
@@ -1514,7 +1514,7 @@ BEGIN
1514
1514
  let t = e, n = {};
1515
1515
  for (let e of Object.keys(t)) n[e.toLowerCase()] = t[e];
1516
1516
  return n;
1517
- }), Wt = (e) => d.gen(function* () {
1517
+ }), Ut = (e) => d.gen(function* () {
1518
1518
  let t = z(yield* e`
1519
1519
  SELECT table_name, COALESCE(table_rows, 0) AS table_rows
1520
1520
  FROM information_schema.tables
@@ -1547,7 +1547,7 @@ BEGIN
1547
1547
  o.add(`${e.table_name}.${t[1]}`);
1548
1548
  continue;
1549
1549
  }
1550
- let n = Ft(e.check_clause);
1550
+ let n = Pt(e.check_clause);
1551
1551
  n && s.set(`${e.table_name}.${n.column}`, n.values);
1552
1552
  }
1553
1553
  let c = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new Map(), u = /* @__PURE__ */ new Map();
@@ -1570,7 +1570,7 @@ BEGIN
1570
1570
  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);
1571
1571
  if (d) for (let e of d.values()) e.length === 1 && e[0].non_unique === 0 && a.add(e[0].column_name);
1572
1572
  let p = t.map((t) => {
1573
- 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" : Ut(t.data_type, t.column_type), u = c ? {
1573
+ 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" : Ht(t.data_type, t.column_type), u = c ? {
1574
1574
  table: c.target_table,
1575
1575
  column: c.target_column,
1576
1576
  onDelete: R(c.delete_rule),
@@ -1611,10 +1611,10 @@ BEGIN
1611
1611
  });
1612
1612
  }
1613
1613
  return { tables: f };
1614
- }), Gt = (e) => {
1614
+ }), Wt = (e) => {
1615
1615
  let t = e.toUpperCase();
1616
1616
  return t.includes("INT") ? "integer" : t.includes("REAL") || t.includes("FLOA") || t.includes("DOUB") ? "real" : t.includes("BLOB") ? "bytes" : "text";
1617
- }, Kt = (e) => d.gen(function* () {
1617
+ }, Gt = (e) => d.gen(function* () {
1618
1618
  let t = yield* e`
1619
1619
  SELECT name, sql FROM sqlite_master
1620
1620
  WHERE type = 'table' AND name NOT LIKE 'sqlite_%'
@@ -1631,7 +1631,7 @@ BEGIN
1631
1631
  d.set(t.name, r), t.unique === 1 && r.length === 1 && f.add(r[0]);
1632
1632
  }
1633
1633
  let p = o.map((e) => {
1634
- let n = u.length === 1 && u[0] === e.name, r = l.get(e.name), i = r ? "reference" : n && e.name === "id" ? "id" : Gt(e.type), a = r ? {
1634
+ let n = u.length === 1 && u[0] === e.name, r = l.get(e.name), i = r ? "reference" : n && e.name === "id" ? "id" : Wt(e.type), a = r ? {
1635
1635
  table: r.table,
1636
1636
  column: r.to,
1637
1637
  onDelete: R(r.on_delete),
@@ -1670,7 +1670,7 @@ BEGIN
1670
1670
  });
1671
1671
  }
1672
1672
  return { tables: r };
1673
- }), qt = (e) => {
1673
+ }), Kt = (e) => {
1674
1674
  switch (e.toLowerCase()) {
1675
1675
  case "int":
1676
1676
  case "smallint":
@@ -1692,7 +1692,7 @@ BEGIN
1692
1692
  case "image": return "bytes";
1693
1693
  default: return "text";
1694
1694
  }
1695
- }, B = (e) => e === !0 || e === 1, Jt = (e) => d.gen(function* () {
1695
+ }, B = (e) => e === !0 || e === 1, qt = (e) => d.gen(function* () {
1696
1696
  let t = yield* e`
1697
1697
  SELECT TABLE_NAME AS table_name FROM INFORMATION_SCHEMA.TABLES
1698
1698
  WHERE TABLE_TYPE = 'BASE TABLE' ORDER BY TABLE_NAME`, n = yield* e`
@@ -1752,12 +1752,12 @@ BEGIN
1752
1752
  else B(t[0].is_unique) && t.length === 1 && f.add(t[0].column_name);
1753
1753
  }
1754
1754
  let p = t.map((t) => {
1755
- 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" : qt(t.data_type), s = i ? {
1755
+ 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" : Kt(t.data_type), s = i ? {
1756
1756
  table: i.target_table,
1757
1757
  column: i.target_column,
1758
- onDelete: Yt(i.delete_rule),
1759
- onUpdate: Yt(i.update_rule)
1760
- } : void 0, c = t.column_default === null ? null : Xt(t.column_default), l = o.get(`${e}.${t.column_name}`);
1758
+ onDelete: Jt(i.delete_rule),
1759
+ onUpdate: Jt(i.update_rule)
1760
+ } : void 0, c = t.column_default === null ? null : Yt(t.column_default), l = o.get(`${e}.${t.column_name}`);
1761
1761
  return {
1762
1762
  name: t.column_name,
1763
1763
  type: a,
@@ -1790,37 +1790,37 @@ BEGIN
1790
1790
  });
1791
1791
  }
1792
1792
  return { tables: u };
1793
- }), Yt = (e) => {
1793
+ }), Jt = (e) => {
1794
1794
  switch (e.toUpperCase().replace(/_/g, " ")) {
1795
1795
  case "CASCADE": return "cascade";
1796
1796
  case "SET NULL": return "setNull";
1797
1797
  case "SET DEFAULT": return "noAction";
1798
1798
  default: return "noAction";
1799
1799
  }
1800
- }, Xt = (e) => {
1800
+ }, Yt = (e) => {
1801
1801
  let t = e.trim();
1802
1802
  for (; t.startsWith("(") && t.endsWith(")");) t = t.slice(1, -1).trim();
1803
1803
  return t.startsWith("N'") && t.endsWith("'") ? t = t.slice(2, -1) : t.startsWith("'") && t.endsWith("'") && (t = t.slice(1, -1)), t;
1804
1804
  }, V = (e) => e.onDialectOrElse({
1805
- mysql: () => Wt(e),
1806
- mssql: () => Jt(e),
1807
- sqlite: () => Kt(e),
1808
- orElse: () => Ht(e)
1809
- }), Zt = (e, t) => `${t}(${e.precision ?? 38}, ${e.scale ?? 0})`, H = (e, t) => {
1805
+ mysql: () => Ut(e),
1806
+ mssql: () => qt(e),
1807
+ sqlite: () => Gt(e),
1808
+ orElse: () => Vt(e)
1809
+ }), Xt = (e, t) => `${t}(${e.precision ?? 38}, ${e.scale ?? 0})`, H = (e, t) => {
1810
1810
  if (!e.spatial && e.type !== "vector" && e.type !== "array" && e.type !== "enum") return;
1811
1811
  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;
1812
1812
  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.`);
1813
1813
  return E(e, t);
1814
1814
  }, U = (e) => {
1815
1815
  let t = H(e, "postgres");
1816
- return t === void 0 ? Qt(e) : t;
1817
- }, Qt = (e) => {
1816
+ return t === void 0 ? Zt(e) : t;
1817
+ }, Zt = (e) => {
1818
1818
  switch (e.type) {
1819
1819
  case "id": return "text";
1820
1820
  case "text": return "text";
1821
1821
  case "integer": return "integer";
1822
1822
  case "real": return "double precision";
1823
- case "decimal": return Zt(e, "NUMERIC");
1823
+ case "decimal": return Xt(e, "NUMERIC");
1824
1824
  case "bigint": return "bigint";
1825
1825
  case "boolean": return "boolean";
1826
1826
  case "timestamp": return "timestamptz";
@@ -1842,7 +1842,7 @@ BEGIN
1842
1842
  case "text": return e.hasDefault && e.defaultValue !== void 0 || e.oneOf && e.oneOf.length > 0 ? "VARCHAR(255)" : "LONGTEXT";
1843
1843
  case "integer": return "INT";
1844
1844
  case "real": return "DOUBLE";
1845
- case "decimal": return Zt(e, "DECIMAL");
1845
+ case "decimal": return Xt(e, "DECIMAL");
1846
1846
  case "bigint": return "BIGINT";
1847
1847
  case "boolean": return "TINYINT(1)";
1848
1848
  case "timestamp": return "DATETIME(6)";
@@ -1856,14 +1856,14 @@ BEGIN
1856
1856
  case "interval": return "BIGINT";
1857
1857
  case "raw": return e.rawDdl ?? "LONGTEXT";
1858
1858
  }
1859
- }, G = (e) => `"${e}"`, K = (e) => `\`${e.replace(/`/g, "``")}\``, $t = (e, t) => `ALTER TABLE ${t(e.table)} DROP COLUMN IF EXISTS ${t(e.column)};`, en = (e) => `ALTER TABLE ${K(e.table)} DROP COLUMN IF EXISTS ${K(e.column)}, ALGORITHM=COPY;`, tn = (e, t) => `ALTER TABLE ${t(e.table)} RENAME COLUMN ${t(e.from)} TO ${t(e.to)};`, nn = (e, t, n) => `ALTER TABLE ${n(e.table)} RENAME COLUMN ${n(e.column)} TO ${n(`${e.column}${On(t)}`)};`, rn = (e, t, n) => e.hasDefault && e.defaultValue !== void 0 ? `ALTER TABLE ${t(e.table)} ALTER COLUMN ${t(e.column)} SET ${an(e, n)};` : `ALTER TABLE ${t(e.table)} ALTER COLUMN ${t(e.column)} DROP DEFAULT;`, an = (e, t) => {
1859
+ }, G = (e) => `"${e}"`, K = (e) => `\`${e.replace(/`/g, "``")}\``, Qt = (e, t) => `ALTER TABLE ${t(e.table)} DROP COLUMN IF EXISTS ${t(e.column)};`, $t = (e) => `ALTER TABLE ${K(e.table)} DROP COLUMN IF EXISTS ${K(e.column)}, ALGORITHM=COPY;`, en = (e, t) => `ALTER TABLE ${t(e.table)} RENAME COLUMN ${t(e.from)} TO ${t(e.to)};`, tn = (e, t, n) => `ALTER TABLE ${n(e.table)} RENAME COLUMN ${n(e.column)} TO ${n(`${e.column}${Dn(t)}`)};`, nn = (e, t, n) => e.hasDefault && e.defaultValue !== void 0 ? `ALTER TABLE ${t(e.table)} ALTER COLUMN ${t(e.column)} SET ${rn(e, n)};` : `ALTER TABLE ${t(e.table)} ALTER COLUMN ${t(e.column)} DROP DEFAULT;`, rn = (e, t) => {
1860
1860
  let n = t(e.defaultValue);
1861
1861
  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.`);
1862
1862
  return n;
1863
- }, q = (e, t, n) => e.find((e) => e.tableName === t)?.fields[n], on = (e, t, n) => {
1863
+ }, q = (e, t, n) => e.find((e) => e.tableName === t)?.fields[n], an = (e, t, n) => {
1864
1864
  let r = q(e, t, n);
1865
1865
  return r ? nt(n, r) : void 0;
1866
- }, sn = (e, t, n) => {
1866
+ }, on = (e, t, n) => {
1867
1867
  let r = n ?? e.nullable, i = ye(e, "mariadb");
1868
1868
  return [
1869
1869
  K(t),
@@ -1871,17 +1871,17 @@ BEGIN
1871
1871
  r ? null : "NOT NULL",
1872
1872
  i
1873
1873
  ].filter(Boolean).join(" ");
1874
- }, cn = (e, t) => e == null ? null : Array.isArray(e) ? ln(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, ln = (e, t, n) => be(e, t ?? { type: "json" }, n), un = (e, t) => e == null ? null : Array.isArray(e) ? ln(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) => {
1874
+ }, sn = (e, t) => e == null ? null : Array.isArray(e) ? cn(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, cn = (e, t, n) => be(e, t ?? { type: "json" }, n), ln = (e, t) => e == null ? null : Array.isArray(e) ? cn(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) => {
1875
1875
  if (!e.generatedAs) return null;
1876
1876
  let { expr: n, stored: r } = e.generatedAs;
1877
1877
  return t === "postgres" ? `GENERATED ALWAYS AS (${n}) STORED` : t === "mssql" ? `AS (${n})${r ? " PERSISTED" : ""}` : `GENERATED ALWAYS AS (${n}) ${r ? "STORED" : "VIRTUAL"}`;
1878
- }, dn = (e) => {
1878
+ }, un = (e) => {
1879
1879
  if (e.type === "id" && e.idScheme?.kind === "numeric") return O(e.name, "postgres");
1880
1880
  let t = J(e, "postgres");
1881
1881
  if (t) return `${G(e.name)} ${U(e)} ${t}`;
1882
1882
  let n = [G(e.name), U(e)];
1883
1883
  if (e.type === "id" && n.push("PRIMARY KEY"), e.nullable || n.push("NOT NULL"), e.unique && e.type !== "id" && n.push("UNIQUE"), e.hasDefault) {
1884
- let t = un(e.defaultValue, e);
1884
+ let t = ln(e.defaultValue, e);
1885
1885
  t && n.push(t);
1886
1886
  }
1887
1887
  return e.references && (n.push(`REFERENCES ${G(e.references.table)} (${G(e.references.column)})`), e.references.onDelete && n.push(`ON DELETE ${{
@@ -1890,20 +1890,20 @@ BEGIN
1890
1890
  setNull: "SET NULL",
1891
1891
  noAction: "NO ACTION"
1892
1892
  }[e.references.onDelete]}`)), n.join(" ");
1893
- }, fn = (e, t) => e.primaryKey && e.primaryKey.length > 0 ? `,\n PRIMARY KEY (${e.primaryKey.map(t).join(", ")})` : "", pn = (e) => {
1894
- let t = e.columns.map((e) => ` ${dn(e)}`).join(",\n"), n = [`CREATE TABLE IF NOT EXISTS ${G(e.table)} (\n${t}${fn(e, G)}\n)`];
1895
- 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(Nn).join(", ")})`);
1893
+ }, dn = (e, t) => e.primaryKey && e.primaryKey.length > 0 ? `,\n PRIMARY KEY (${e.primaryKey.map(t).join(", ")})` : "", fn = (e) => {
1894
+ let t = e.columns.map((e) => ` ${un(e)}`).join(",\n"), n = [`CREATE TABLE IF NOT EXISTS ${G(e.table)} (\n${t}${dn(e, G)}\n)`];
1895
+ 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(Mn).join(", ")})`);
1896
1896
  return n;
1897
- }, mn = 191, hn = (e) => {
1897
+ }, pn = 191, mn = (e) => {
1898
1898
  let t = W(e).toUpperCase();
1899
1899
  return t.endsWith("TEXT") || t.endsWith("BLOB");
1900
- }, gn = (e) => {
1900
+ }, hn = (e) => {
1901
1901
  if (e.type === "id" && e.idScheme?.kind === "numeric") return O(e.name, "mariadb");
1902
1902
  let t = J(e, "mariadb");
1903
1903
  if (t) return `${K(e.name)} ${W(e)} ${t}`;
1904
1904
  let n = [K(e.name), W(e)];
1905
- if (e.type === "id" && n.push("PRIMARY KEY"), e.nullable || n.push("NOT NULL"), e.unique && e.type !== "id" && !hn(e) && n.push("UNIQUE"), e.hasDefault) {
1906
- let t = cn(e.defaultValue, e);
1905
+ if (e.type === "id" && n.push("PRIMARY KEY"), e.nullable || n.push("NOT NULL"), e.unique && e.type !== "id" && !mn(e) && n.push("UNIQUE"), e.hasDefault) {
1906
+ let t = sn(e.defaultValue, e);
1907
1907
  t && n.push(t);
1908
1908
  }
1909
1909
  return e.references && (n.push(`REFERENCES ${K(e.references.table)} (${K(e.references.column)})`), e.references.onDelete && n.push(`ON DELETE ${{
@@ -1912,25 +1912,25 @@ BEGIN
1912
1912
  setNull: "SET NULL",
1913
1913
  noAction: "NO ACTION"
1914
1914
  }[e.references.onDelete]}`)), n.join(" ");
1915
- }, _n = (e) => {
1915
+ }, gn = (e) => {
1916
1916
  let t = new Map(e.columns.map((e) => [e.name, e])), n = (e) => {
1917
1917
  let n = t.get(e);
1918
- return n && hn(n) ? `${K(e)}(${mn})` : K(e);
1919
- }, r = e.columns.map((e) => ` ${gn(e)}`).join(",\n"), i = [`CREATE TABLE IF NOT EXISTS ${K(e.table)} (\n${r}${fn(e, n)}\n)`];
1920
- for (let t of e.columns) t.unique && t.type !== "id" && hn(t) && i.push(`CREATE UNIQUE INDEX IF NOT EXISTS ${K(`${e.table}_${t.name}_key`)} ON ${K(e.table)} (${n(t.name)})`);
1918
+ return n && mn(n) ? `${K(e)}(${pn})` : K(e);
1919
+ }, r = e.columns.map((e) => ` ${hn(e)}`).join(",\n"), i = [`CREATE TABLE IF NOT EXISTS ${K(e.table)} (\n${r}${dn(e, n)}\n)`];
1920
+ for (let t of e.columns) t.unique && t.type !== "id" && mn(t) && i.push(`CREATE UNIQUE INDEX IF NOT EXISTS ${K(`${e.table}_${t.name}_key`)} ON ${K(e.table)} (${n(t.name)})`);
1921
1921
  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(", ")})`);
1922
1922
  return i;
1923
- }, vn = {
1923
+ }, _n = {
1924
1924
  cascade: "CASCADE",
1925
1925
  restrict: "RESTRICT",
1926
1926
  setNull: "SET NULL",
1927
1927
  noAction: "NO ACTION"
1928
- }, yn = {
1928
+ }, vn = {
1929
1929
  cascade: "CASCADE",
1930
1930
  restrict: "NO ACTION",
1931
1931
  setNull: "SET NULL",
1932
1932
  noAction: "NO ACTION"
1933
- }, bn = (e) => {
1933
+ }, yn = (e) => {
1934
1934
  let t = H(e, "sqlite");
1935
1935
  if (t !== void 0) return t;
1936
1936
  switch (e.type) {
@@ -1942,29 +1942,29 @@ BEGIN
1942
1942
  case "bytes": return "BLOB";
1943
1943
  default: return "TEXT";
1944
1944
  }
1945
- }, 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, xn = (e) => {
1945
+ }, 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, bn = (e) => {
1946
1946
  if (e.type === "id" && e.idScheme?.kind === "numeric") return O(e.name, "sqlite");
1947
1947
  let t = J(e, "sqlite");
1948
- if (t) return `${G(e.name)} ${bn(e)} ${t}`;
1949
- let n = [G(e.name), bn(e)];
1948
+ if (t) return `${G(e.name)} ${yn(e)} ${t}`;
1949
+ let n = [G(e.name), yn(e)];
1950
1950
  if (e.type === "id" && n.push("PRIMARY KEY"), e.nullable || n.push("NOT NULL"), e.unique && e.type !== "id" && n.push("UNIQUE"), e.hasDefault) {
1951
1951
  let t = Y(e.defaultValue, "CURRENT_TIMESTAMP");
1952
1952
  t && n.push(t);
1953
1953
  }
1954
- if (e.references && (n.push(`REFERENCES ${G(e.references.table)} (${G(e.references.column)})`), e.references.onDelete && n.push(`ON DELETE ${vn[e.references.onDelete]}`)), e.oneOf && e.oneOf.length > 0) {
1954
+ if (e.references && (n.push(`REFERENCES ${G(e.references.table)} (${G(e.references.column)})`), e.references.onDelete && n.push(`ON DELETE ${_n[e.references.onDelete]}`)), e.oneOf && e.oneOf.length > 0) {
1955
1955
  let t = e.oneOf.map((e) => `'${e.replace(/'/g, "''")}'`).join(", ");
1956
1956
  n.push(`CHECK (${G(e.name)} IN (${t}))`);
1957
1957
  }
1958
1958
  return n.join(" ");
1959
- }, Sn = (e) => {
1960
- let t = e.columns.map((e) => ` ${xn(e)}`).join(",\n"), n = [`CREATE TABLE IF NOT EXISTS ${G(e.table)} (\n${t}${fn(e, G)}\n)`];
1959
+ }, xn = (e) => {
1960
+ let t = e.columns.map((e) => ` ${bn(e)}`).join(",\n"), n = [`CREATE TABLE IF NOT EXISTS ${G(e.table)} (\n${t}${dn(e, G)}\n)`];
1961
1961
  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(", ")})`);
1962
1962
  return n;
1963
1963
  }, X = (e, t) => {
1964
1964
  let n = t.find((t) => t.tableName === e);
1965
1965
  if (!n) return [];
1966
1966
  let r = N([n]).tables[0], i = `${e}__voltro_rebuild`, a = r.columns.map((e) => G(e.name)).join(", "), o = [
1967
- ...Sn({
1967
+ ...xn({
1968
1968
  kind: "create-table",
1969
1969
  table: i,
1970
1970
  columns: r.columns,
@@ -1977,17 +1977,17 @@ BEGIN
1977
1977
  ];
1978
1978
  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(", ")})`);
1979
1979
  return o;
1980
- }, Cn = (e, t, n, r) => {
1980
+ }, Sn = (e, t, n, r) => {
1981
1981
  let i = r ?? e.nullable;
1982
1982
  return `ALTER TABLE ${Z(n)} ALTER COLUMN ${Z(t)} ${E(e, "mssql")} ${i ? "NULL" : "NOT NULL"};`;
1983
- }, wn = (e) => {
1983
+ }, Cn = (e) => {
1984
1984
  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 + ']');`;
1985
1985
  if (!e.hasDefault) return t;
1986
1986
  let n = Y(e.defaultValue, "SYSUTCDATETIME()");
1987
1987
  if (!n) return t;
1988
1988
  let r = n.replace(/^DEFAULT\s+/i, "");
1989
1989
  return `${t} ALTER TABLE ${Z(e.table)} ADD DEFAULT ${r} FOR ${Z(e.column)};`;
1990
- }, Z = (e) => `[${e.replace(/]/g, "]]")}]`, Tn = (e) => {
1990
+ }, Z = (e) => `[${e.replace(/]/g, "]]")}]`, wn = (e) => {
1991
1991
  let t = H(e, "mssql");
1992
1992
  if (t !== void 0) return t;
1993
1993
  switch (e.type) {
@@ -1995,7 +1995,7 @@ BEGIN
1995
1995
  case "reference": return "NVARCHAR(64)";
1996
1996
  case "integer": return "INT";
1997
1997
  case "real": return "FLOAT";
1998
- case "decimal": return Zt(e, "DECIMAL");
1998
+ case "decimal": return Xt(e, "DECIMAL");
1999
1999
  case "bigint": return "BIGINT";
2000
2000
  case "boolean": return "BIT";
2001
2001
  case "timestamp": return "DATETIME2(6)";
@@ -2003,34 +2003,34 @@ BEGIN
2003
2003
  case "bytes": return "VARBINARY(MAX)";
2004
2004
  default: return "NVARCHAR(MAX)";
2005
2005
  }
2006
- }, En = (e, t) => {
2006
+ }, Tn = (e, t) => {
2007
2007
  if (e.type === "id" && e.idScheme?.kind === "numeric") return O(e.name, "mssql");
2008
- let n = e.type === "text" && t?.has(e.name) ? "NVARCHAR(450)" : Tn(e), r = J(e, "mssql");
2008
+ let n = e.type === "text" && t?.has(e.name) ? "NVARCHAR(450)" : wn(e), r = J(e, "mssql");
2009
2009
  if (r) return `${Z(e.name)} ${r}`;
2010
2010
  let i = [Z(e.name), n];
2011
2011
  if (e.type === "id" && i.push("PRIMARY KEY"), e.nullable || i.push("NOT NULL"), e.unique && e.type !== "id" && i.push("UNIQUE"), e.hasDefault) {
2012
2012
  let t = Y(e.defaultValue, "SYSUTCDATETIME()");
2013
2013
  t && i.push(t);
2014
2014
  }
2015
- return e.references && (i.push(`REFERENCES ${Z(e.references.table)} (${Z(e.references.column)})`), e.references.onDelete && i.push(`ON DELETE ${yn[e.references.onDelete]}`)), i.join(" ");
2016
- }, Dn = (e) => {
2017
- let t = (e) => e.replace(/'/g, "''"), n = new Set(e.indexes.flatMap((e) => e.columns)), r = e.columns.map((e) => ` ${En(e, n)}`).join(",\n"), i = `CREATE TABLE ${Z(e.table)} (\n${r}${fn(e, Z)}\n)`, a = [`IF OBJECT_ID(N'${t(e.table)}', N'U') IS NULL EXEC(N'${t(i)}')`];
2015
+ return e.references && (i.push(`REFERENCES ${Z(e.references.table)} (${Z(e.references.column)})`), e.references.onDelete && i.push(`ON DELETE ${vn[e.references.onDelete]}`)), i.join(" ");
2016
+ }, En = (e) => {
2017
+ let t = (e) => e.replace(/'/g, "''"), n = new Set(e.indexes.flatMap((e) => e.columns)), r = e.columns.map((e) => ` ${Tn(e, n)}`).join(",\n"), i = `CREATE TABLE ${Z(e.table)} (\n${r}${dn(e, Z)}\n)`, a = [`IF OBJECT_ID(N'${t(e.table)}', N'U') IS NULL EXEC(N'${t(i)}')`];
2018
2018
  for (let n of e.indexes) {
2019
2019
  if (n.name === `${e.table}_pkey`) continue;
2020
2020
  let r = `CREATE ${n.unique ? "UNIQUE " : ""}INDEX ${Z(n.name)} ON ${Z(e.table)} (${n.columns.map(Z).join(", ")})`;
2021
2021
  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)}')`);
2022
2022
  }
2023
2023
  return a;
2024
- }, On = (e) => `__dropped_${e.replace(/[-:T.Z]/g, "").slice(0, 14)}`, kn = (e, t) => `DROP TABLE IF EXISTS ${t(e.table)};`, An = (e, t, n) => {
2025
- let r = `${e.table}${On(t)}`;
2024
+ }, Dn = (e) => `__dropped_${e.replace(/[-:T.Z]/g, "").slice(0, 14)}`, On = (e, t) => `DROP TABLE IF EXISTS ${t(e.table)};`, kn = (e, t, n) => {
2025
+ let r = `${e.table}${Dn(t)}`;
2026
2026
  return `ALTER TABLE ${n(e.table)} RENAME TO ${n(r)};`;
2027
- }, jn = (e, t, n) => {
2027
+ }, An = (e, t, n) => {
2028
2028
  let r = q(e, t, n);
2029
- return r ? hn({ type: r.type }) : !1;
2030
- }, Mn = (e, t, n) => jn(e, t, n) ? `${K(n)}(${mn})` : K(n), Nn = (e) => e.startsWith("(") ? e : G(e), Pn = (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(Nn).join(", ")});`, Fn = (e, t) => `CREATE ${e.index.unique ? "UNIQUE " : ""}INDEX IF NOT EXISTS ${K(e.index.name)} ON ${K(e.table)} (${e.index.columns.map((n) => Mn(t, e.table, n)).join(", ")});`, In = (e) => `DROP INDEX IF EXISTS ${G(e.index)};`, Ln = (e) => `DROP INDEX ${K(e.index)} ON ${K(e.table)};`, Rn = (e) => `DROP INDEX IF EXISTS ${Z(e.index)} ON ${Z(e.table)};`, zn = (e) => {
2029
+ return r ? mn({ type: r.type }) : !1;
2030
+ }, jn = (e, t, n) => An(e, t, n) ? `${K(n)}(${pn})` : K(n), Mn = (e) => e.startsWith("(") ? e : G(e), Nn = (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(Mn).join(", ")});`, Pn = (e, t) => `CREATE ${e.index.unique ? "UNIQUE " : ""}INDEX IF NOT EXISTS ${K(e.index.name)} ON ${K(e.table)} (${e.index.columns.map((n) => jn(t, e.table, n)).join(", ")});`, Fn = (e) => `DROP INDEX IF EXISTS ${G(e.index)};`, In = (e) => `DROP INDEX ${K(e.index)} ON ${K(e.table)};`, Ln = (e) => `DROP INDEX IF EXISTS ${Z(e.index)} ON ${Z(e.table)};`, Rn = (e) => {
2031
2031
  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(", ")})`;
2032
2032
  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)}');`;
2033
- }, Bn = (e, t, n) => {
2033
+ }, zn = (e, t, n) => {
2034
2034
  let r = n.find((t) => t.tableName === e);
2035
2035
  if (!r) return [];
2036
2036
  let i = [];
@@ -2039,13 +2039,13 @@ BEGIN
2039
2039
  t && t.type === "text" && !t.generatedAs && i.push(`ALTER TABLE ${Z(e)} ALTER COLUMN ${Z(n)} NVARCHAR(450) ${t.nullable ? "NULL" : "NOT NULL"};`);
2040
2040
  }
2041
2041
  return i;
2042
- }, Vn = (e) => `ALTER TABLE ${G(e.table)} ADD CONSTRAINT ${G(`${e.table}_${e.column}_key`)} UNIQUE (${G(e.column)});`, Hn = (e, t) => `ALTER TABLE ${K(e.table)} ADD CONSTRAINT ${K(`${e.table}_${e.column}_key`)} UNIQUE (${Mn(t, e.table, e.column)});`, Un = (e) => {
2042
+ }, Bn = (e) => `ALTER TABLE ${G(e.table)} ADD CONSTRAINT ${G(`${e.table}_${e.column}_key`)} UNIQUE (${G(e.column)});`, Vn = (e, t) => `ALTER TABLE ${K(e.table)} ADD CONSTRAINT ${K(`${e.table}_${e.column}_key`)} UNIQUE (${jn(t, e.table, e.column)});`, Hn = (e) => {
2043
2043
  let t = e.fields.map((e) => G(e)).join(", ");
2044
2044
  return `ALTER TABLE ${G(e.table)} ADD CONSTRAINT ${G(e.name)} UNIQUE (${t});`;
2045
- }, Wn = (e, t) => {
2046
- let n = e.fields.map((n) => Mn(t, e.table, n)).join(", ");
2045
+ }, Un = (e, t) => {
2046
+ let n = e.fields.map((n) => jn(t, e.table, n)).join(", ");
2047
2047
  return `ALTER TABLE ${K(e.table)} ADD CONSTRAINT ${K(e.name)} UNIQUE (${n});`;
2048
- }, Gn = (e) => `ALTER TABLE ${G(e.table)} DROP CONSTRAINT IF EXISTS ${G(e.name)};`, Kn = (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`)};`, Jn = (e) => `ALTER TABLE ${K(e.table)} DROP INDEX ${K(`${e.table}_${e.column}_key`)};`, Yn = (e, t) => {
2048
+ }, Wn = (e) => `ALTER TABLE ${G(e.table)} DROP CONSTRAINT IF EXISTS ${G(e.name)};`, Gn = (e) => `ALTER TABLE ${K(e.table)} DROP INDEX ${K(e.name)};`, Kn = (e) => `ALTER TABLE ${G(e.table)} DROP CONSTRAINT IF EXISTS ${G(`${e.table}_${e.column}_key`)};`, qn = (e) => `ALTER TABLE ${K(e.table)} DROP INDEX ${K(`${e.table}_${e.column}_key`)};`, Jn = (e, t) => {
2049
2049
  let n = [], r = t(e.table), i = t(e.column), a = t(e.targetTable), o = t(e.targetColumn);
2050
2050
  if (e.orphanPolicy) {
2051
2051
  let t = `${i} IS NOT NULL AND ${i} NOT IN (SELECT ${o} FROM ${a})`;
@@ -2063,11 +2063,11 @@ BEGIN
2063
2063
  setNull: "SET NULL",
2064
2064
  noAction: "NO ACTION"
2065
2065
  }[e.onDelete]}`), n.push(s.join(" ") + ";"), n;
2066
- }, Xn = (e) => `ALTER TABLE ${G(e.table)} DROP CONSTRAINT IF EXISTS ${G(`${e.table}_${e.column}_fkey`)};`, Zn = (e) => `ALTER TABLE ${K(e.table)} DROP FOREIGN KEY ${K(`${e.table}_${e.column}_fkey`)};`, Qn = (e, t) => {
2066
+ }, Yn = (e) => `ALTER TABLE ${G(e.table)} DROP CONSTRAINT IF EXISTS ${G(`${e.table}_${e.column}_fkey`)};`, Xn = (e) => `ALTER TABLE ${K(e.table)} DROP FOREIGN KEY ${K(`${e.table}_${e.column}_fkey`)};`, Zn = (e, t) => {
2067
2067
  let n = e.values.map((e) => `'${e.replace(/'/g, "''")}'`).join(", ");
2068
2068
  return `ALTER TABLE ${t(e.table)} ADD CONSTRAINT ${t(`${e.table}_${e.column}_check`)} CHECK (${t(e.column)} IN (${n}));`;
2069
- }, $n = (e) => `ALTER TABLE ${G(e.table)} DROP CONSTRAINT IF EXISTS ${G(`${e.table}_${e.column}_check`)};`, er = (e) => `ALTER TABLE ${K(e.table)} DROP CHECK ${K(`${e.table}_${e.column}_check`)};`, tr = (e, t, n, r) => {
2070
- let i = e.column, a = r === "mariadb", o = a ? K : r === "mssql" ? Z : G, s = a ? W(i) : r === "mssql" ? Tn(i) : r === "sqlite" ? bn(i) : U(i), c = r === "mssql" ? "ADD" : "ADD COLUMN", l = (e) => a ? cn(e, i) : r === "mssql" ? Y(e, "SYSUTCDATETIME()") : r === "sqlite" ? Y(e, "CURRENT_TIMESTAMP") : un(e, i), u = J(i, r);
2069
+ }, Qn = (e) => `ALTER TABLE ${G(e.table)} DROP CONSTRAINT IF EXISTS ${G(`${e.table}_${e.column}_check`)};`, $n = (e) => `ALTER TABLE ${K(e.table)} DROP CHECK ${K(`${e.table}_${e.column}_check`)};`, er = (e, t, n, r) => {
2070
+ let i = e.column, a = r === "mariadb", o = a ? K : r === "mssql" ? Z : G, s = a ? W(i) : r === "mssql" ? wn(i) : r === "sqlite" ? yn(i) : U(i), c = r === "mssql" ? "ADD" : "ADD COLUMN", l = (e) => a ? sn(e, i) : r === "mssql" ? Y(e, "SYSUTCDATETIME()") : r === "sqlite" ? Y(e, "CURRENT_TIMESTAMP") : ln(e, i), u = J(i, r);
2071
2071
  if (u) {
2072
2072
  let t = r === "mssql" ? `${o(i.name)} ${u}` : `${o(i.name)} ${s} ${u}`;
2073
2073
  return {
@@ -2095,7 +2095,7 @@ BEGIN
2095
2095
  post: f ? [f] : []
2096
2096
  };
2097
2097
  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;
2098
- }, nr = (e) => {
2098
+ }, tr = (e) => {
2099
2099
  let t = new Map(e.map((e) => [e.tableName, e]));
2100
2100
  return (e, n) => {
2101
2101
  let r = t.get(e);
@@ -2120,21 +2120,21 @@ BEGIN
2120
2120
  })), d.mapError((e) => {
2121
2121
  let r = _(`applier: statement failed (op=${n})`, t, e, 400).trim();
2122
2122
  return Object.assign(e, { message: r });
2123
- }), d.map(() => void 0)), $ = (e, t, n) => d.forEach(t, (t) => Q(e, t, n), { discard: !0 }), rr = (e, t, n) => d.gen(function* () {
2124
- let r = process.hrtime.bigint(), i = nr(n.declared), a = t.op;
2123
+ }), d.map(() => void 0)), $ = (e, t, n) => d.forEach(t, (t) => Q(e, t, n), { discard: !0 }), nr = (e, t, n) => d.gen(function* () {
2124
+ let r = process.hrtime.bigint(), i = tr(n.declared), a = t.op;
2125
2125
  switch (a.kind) {
2126
2126
  case "create-table": {
2127
2127
  let t = yield* e.onDialectOrElse({
2128
- mysql: () => d.succeed(_n(a)),
2129
- mssql: () => d.succeed(Dn(a)),
2130
- sqlite: () => d.succeed(Sn(a)),
2131
- orElse: () => d.succeed(pn(a))
2128
+ mysql: () => d.succeed(gn(a)),
2129
+ mssql: () => d.succeed(En(a)),
2130
+ sqlite: () => d.succeed(xn(a)),
2131
+ orElse: () => d.succeed(fn(a))
2132
2132
  });
2133
2133
  for (let n of t) yield* Q(e, n, a.kind);
2134
2134
  break;
2135
2135
  }
2136
2136
  case "drop-table": {
2137
- let t = process.env.VOLTRO_SOFT_DROP === "1", n = (/* @__PURE__ */ new Date()).toISOString(), r = (e) => t ? An(a, n, e) : kn(a, e);
2137
+ let t = process.env.VOLTRO_SOFT_DROP === "1", n = (/* @__PURE__ */ new Date()).toISOString(), r = (e) => t ? kn(a, n, e) : On(a, e);
2138
2138
  yield* e.onDialectOrElse({
2139
2139
  mysql: () => Q(e, r(K), a.kind),
2140
2140
  orElse: () => Q(e, r(G), a.kind)
@@ -2144,71 +2144,71 @@ BEGIN
2144
2144
  case "drop-column": {
2145
2145
  let t = process.env.VOLTRO_SOFT_DROP === "1", n = (/* @__PURE__ */ new Date()).toISOString();
2146
2146
  yield* e.onDialectOrElse({
2147
- mysql: () => Q(e, t ? nn(a, n, K) : en(a), a.kind),
2148
- orElse: () => Q(e, t ? nn(a, n, G) : $t(a, G), a.kind)
2147
+ mysql: () => Q(e, t ? tn(a, n, K) : $t(a), a.kind),
2148
+ orElse: () => Q(e, t ? tn(a, n, G) : Qt(a, G), a.kind)
2149
2149
  });
2150
2150
  break;
2151
2151
  }
2152
2152
  case "rename-column":
2153
2153
  yield* e.onDialectOrElse({
2154
- mysql: () => Q(e, tn(a, K), a.kind),
2154
+ mysql: () => Q(e, en(a, K), a.kind),
2155
2155
  mssql: () => Q(e, `EXEC sp_rename N'${a.table.replace(/'/g, "''")}.${a.from.replace(/'/g, "''")}', N'${a.to.replace(/'/g, "''")}', 'COLUMN';`, a.kind),
2156
- orElse: () => Q(e, tn(a, G), a.kind)
2156
+ orElse: () => Q(e, en(a, G), a.kind)
2157
2157
  });
2158
2158
  break;
2159
2159
  case "add-index":
2160
2160
  yield* e.onDialectOrElse({
2161
- mysql: () => Q(e, Fn(a, n.declared), a.kind),
2162
- mssql: () => $(e, [...Bn(a.table, a.index.columns, n.declared), zn(a)], a.kind),
2163
- orElse: () => Q(e, Pn(a, t.classification === "online-required"), a.kind)
2161
+ mysql: () => Q(e, Pn(a, n.declared), a.kind),
2162
+ mssql: () => $(e, [...zn(a.table, a.index.columns, n.declared), Rn(a)], a.kind),
2163
+ orElse: () => Q(e, Nn(a, t.classification === "online-required"), a.kind)
2164
2164
  });
2165
2165
  break;
2166
2166
  case "drop-index":
2167
2167
  yield* e.onDialectOrElse({
2168
- mysql: () => Q(e, Ln(a), a.kind),
2169
- mssql: () => Q(e, Rn(a), a.kind),
2170
- orElse: () => Q(e, In(a), a.kind)
2168
+ mysql: () => Q(e, In(a), a.kind),
2169
+ mssql: () => Q(e, Ln(a), a.kind),
2170
+ orElse: () => Q(e, Fn(a), a.kind)
2171
2171
  });
2172
2172
  break;
2173
2173
  case "add-unique":
2174
2174
  yield* e.onDialectOrElse({
2175
- mysql: () => Q(e, Hn(a, n.declared), a.kind),
2175
+ mysql: () => Q(e, Vn(a, n.declared), a.kind),
2176
2176
  sqlite: () => $(e, X(a.table, n.declared), a.kind),
2177
- mssql: () => $(e, [...Bn(a.table, [a.column], n.declared), Vn(a)], a.kind),
2178
- orElse: () => Q(e, Vn(a), a.kind)
2177
+ mssql: () => $(e, [...zn(a.table, [a.column], n.declared), Bn(a)], a.kind),
2178
+ orElse: () => Q(e, Bn(a), a.kind)
2179
2179
  });
2180
2180
  break;
2181
2181
  case "drop-unique":
2182
2182
  yield* e.onDialectOrElse({
2183
- mysql: () => Q(e, Jn(a), a.kind),
2183
+ mysql: () => Q(e, qn(a), a.kind),
2184
2184
  sqlite: () => $(e, X(a.table, n.declared), a.kind),
2185
- orElse: () => Q(e, qn(a), a.kind)
2185
+ orElse: () => Q(e, Kn(a), a.kind)
2186
2186
  });
2187
2187
  break;
2188
2188
  case "add-unique-composite":
2189
2189
  yield* e.onDialectOrElse({
2190
- mysql: () => Q(e, Wn(a, n.declared), a.kind),
2190
+ mysql: () => Q(e, Un(a, n.declared), a.kind),
2191
2191
  sqlite: () => $(e, X(a.table, n.declared), a.kind),
2192
- mssql: () => $(e, [...Bn(a.table, a.fields, n.declared), Un(a)], a.kind),
2193
- orElse: () => Q(e, Un(a), a.kind)
2192
+ mssql: () => $(e, [...zn(a.table, a.fields, n.declared), Hn(a)], a.kind),
2193
+ orElse: () => Q(e, Hn(a), a.kind)
2194
2194
  });
2195
2195
  break;
2196
2196
  case "drop-unique-composite":
2197
2197
  yield* e.onDialectOrElse({
2198
- mysql: () => Q(e, Kn(a), a.kind),
2198
+ mysql: () => Q(e, Gn(a), a.kind),
2199
2199
  sqlite: () => $(e, X(a.table, n.declared), a.kind),
2200
- orElse: () => Q(e, Gn(a), a.kind)
2200
+ orElse: () => Q(e, Wn(a), a.kind)
2201
2201
  });
2202
2202
  break;
2203
2203
  case "add-foreign-key":
2204
2204
  yield* e.onDialectOrElse({
2205
- mysql: () => $(e, Yn(a, K), a.kind),
2205
+ mysql: () => $(e, Jn(a, K), a.kind),
2206
2206
  sqlite: () => $(e, X(a.table, n.declared), a.kind),
2207
- orElse: () => $(e, Yn(a, G), a.kind)
2207
+ orElse: () => $(e, Jn(a, G), a.kind)
2208
2208
  });
2209
2209
  break;
2210
2210
  case "add-column": {
2211
- let n = tr(a, t, i, yield* e.onDialectOrElse({
2211
+ let n = er(a, t, i, yield* e.onDialectOrElse({
2212
2212
  mysql: () => d.succeed("mariadb"),
2213
2213
  mssql: () => d.succeed("mssql"),
2214
2214
  sqlite: () => d.succeed("sqlite"),
@@ -2254,37 +2254,37 @@ BEGIN
2254
2254
  yield* e.onDialectOrElse({
2255
2255
  mysql: () => {
2256
2256
  let t = q(n.declared, a.table, a.column);
2257
- return t ? Q(e, `ALTER TABLE ${K(a.table)} MODIFY COLUMN ${sn(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.`));
2257
+ return t ? Q(e, `ALTER TABLE ${K(a.table)} MODIFY COLUMN ${on(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.`));
2258
2258
  },
2259
2259
  mssql: () => {
2260
2260
  let t = q(n.declared, a.table, a.column);
2261
- return t ? Q(e, Cn(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}'.`));
2261
+ return t ? Q(e, Sn(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}'.`));
2262
2262
  },
2263
2263
  sqlite: () => $(e, X(a.table, n.declared), a.kind),
2264
2264
  orElse: () => Q(e, `ALTER TABLE ${G(a.table)} ALTER COLUMN ${G(a.column)} ${a.toNullable ? "DROP NOT NULL" : "SET NOT NULL"};`, a.kind)
2265
2265
  });
2266
2266
  break;
2267
2267
  case "alter-column-default": {
2268
- let t = on(n.declared, a.table, a.column);
2268
+ let t = an(n.declared, a.table, a.column);
2269
2269
  yield* e.onDialectOrElse({
2270
- mysql: () => Q(e, rn(a, K, (e) => cn(e, t)), a.kind),
2271
- mssql: () => Q(e, wn(a), a.kind),
2270
+ mysql: () => Q(e, nn(a, K, (e) => sn(e, t)), a.kind),
2271
+ mssql: () => Q(e, Cn(a), a.kind),
2272
2272
  sqlite: () => $(e, X(a.table, n.declared), a.kind),
2273
- orElse: () => Q(e, rn(a, G, (e) => un(e, t)), a.kind)
2273
+ orElse: () => Q(e, nn(a, G, (e) => ln(e, t)), a.kind)
2274
2274
  });
2275
2275
  break;
2276
2276
  }
2277
2277
  case "alter-column-type": {
2278
- let r = U(on(n.declared, a.table, a.column) ?? { type: a.to }), i = a.using ? ` USING ${a.using}` : "";
2278
+ let r = U(an(n.declared, a.table, a.column) ?? { type: a.to }), i = a.using ? ` USING ${a.using}` : "";
2279
2279
  if (t.classification !== "online-required") {
2280
2280
  yield* e.onDialectOrElse({
2281
2281
  mysql: () => {
2282
2282
  let t = q(n.declared, a.table, a.column);
2283
- return t ? Q(e, `ALTER TABLE ${K(a.table)} MODIFY COLUMN ${sn(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.`));
2283
+ return t ? Q(e, `ALTER TABLE ${K(a.table)} MODIFY COLUMN ${on(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.`));
2284
2284
  },
2285
2285
  mssql: () => {
2286
2286
  let t = q(n.declared, a.table, a.column);
2287
- return t ? Q(e, Cn(t, a.column, a.table), a.kind) : d.die(/* @__PURE__ */ Error(`alter-column-type on mssql needs the declared column '${a.table}.${a.column}'.`));
2287
+ return t ? Q(e, Sn(t, a.column, a.table), a.kind) : d.die(/* @__PURE__ */ Error(`alter-column-type on mssql needs the declared column '${a.table}.${a.column}'.`));
2288
2288
  },
2289
2289
  sqlite: () => $(e, X(a.table, n.declared), a.kind),
2290
2290
  orElse: () => Q(e, `ALTER TABLE ${G(a.table)} ALTER COLUMN ${G(a.column)} TYPE ${r}${i};`, a.kind)
@@ -2308,23 +2308,23 @@ BEGIN
2308
2308
  }
2309
2309
  case "drop-foreign-key":
2310
2310
  yield* e.onDialectOrElse({
2311
- mysql: () => Q(e, Zn(a), a.kind),
2311
+ mysql: () => Q(e, Xn(a), a.kind),
2312
2312
  sqlite: () => $(e, X(a.table, n.declared), a.kind),
2313
- orElse: () => Q(e, Xn(a), a.kind)
2313
+ orElse: () => Q(e, Yn(a), a.kind)
2314
2314
  });
2315
2315
  break;
2316
2316
  case "add-check":
2317
2317
  yield* e.onDialectOrElse({
2318
- mysql: () => Q(e, Qn(a, K), a.kind),
2318
+ mysql: () => Q(e, Zn(a, K), a.kind),
2319
2319
  sqlite: () => $(e, X(a.table, n.declared), a.kind),
2320
- orElse: () => Q(e, Qn(a, G), a.kind)
2320
+ orElse: () => Q(e, Zn(a, G), a.kind)
2321
2321
  });
2322
2322
  break;
2323
2323
  case "drop-check":
2324
2324
  yield* e.onDialectOrElse({
2325
- mysql: () => Q(e, er(a), a.kind),
2325
+ mysql: () => Q(e, $n(a), a.kind),
2326
2326
  sqlite: () => $(e, X(a.table, n.declared), a.kind),
2327
- orElse: () => Q(e, $n(a), a.kind)
2327
+ orElse: () => Q(e, Qn(a), a.kind)
2328
2328
  });
2329
2329
  break;
2330
2330
  }
@@ -2333,7 +2333,7 @@ BEGIN
2333
2333
  status: "applied",
2334
2334
  durationMs: Number((process.hrtime.bigint() - r) / 1000000n)
2335
2335
  };
2336
- }), ir = (e, t, n) => d.gen(function* () {
2336
+ }), rr = (e, t, n) => d.gen(function* () {
2337
2337
  let r = t.operations.filter((e) => e.blocked);
2338
2338
  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.`));
2339
2339
  yield* C(e);
@@ -2346,9 +2346,9 @@ BEGIN
2346
2346
  }), i = r ? t.operations.filter((e) => e.classification !== "online-required") : [], o = r ? t.operations.filter((e) => e.classification === "online-required") : t.operations;
2347
2347
  i.length > 0 && (yield* e.withTransaction(d.gen(function* () {
2348
2348
  let e = yield* p.SqlClient;
2349
- for (let t of i) a.push(yield* rr(e, t, n));
2349
+ for (let t of i) a.push(yield* nr(e, t, n));
2350
2350
  })));
2351
- for (let t of o) a.push(yield* rr(e, t, n));
2351
+ for (let t of o) a.push(yield* nr(e, t, n));
2352
2352
  } finally {
2353
2353
  yield* w(e).pipe(d.orDie);
2354
2354
  }
@@ -2382,19 +2382,19 @@ BEGIN
2382
2382
  source: n.source,
2383
2383
  ...n.notes ? { notes: n.notes } : {}
2384
2384
  };
2385
- }), ar = (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"), or = (e) => e`
2385
+ }), ir = (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"), ar = (e) => e`
2386
2386
  SELECT fingerprint
2387
2387
  FROM _voltro_migration_plans
2388
2388
  ORDER BY ${e("appliedAt")} DESC
2389
2389
  LIMIT 1
2390
- `.pipe(d.map((e) => e.length > 0 ? e[0].fingerprint : void 0), d.catchAll(() => d.succeed(void 0))), sr = (e) => e.onDialectOrElse({
2390
+ `.pipe(d.map((e) => e.length > 0 ? e[0].fingerprint : void 0), d.catchAll(() => d.succeed(void 0))), or = (e) => e.onDialectOrElse({
2391
2391
  pg: () => "postgres",
2392
2392
  mysql: () => "mysql",
2393
2393
  mssql: () => "mssql",
2394
2394
  sqlite: () => "sqlite",
2395
2395
  orElse: () => "sqlite"
2396
- }), cr = (e, t) => d.gen(function* () {
2397
- let n = j(N(t, sr(e))), r = yield* or(e);
2396
+ }), sr = (e, t) => d.gen(function* () {
2397
+ let n = j(N(t, or(e))), r = yield* ar(e);
2398
2398
  return r === n ? {
2399
2399
  kind: "up-to-date",
2400
2400
  fingerprint: n
@@ -2403,23 +2403,23 @@ BEGIN
2403
2403
  expected: n,
2404
2404
  ...r === void 0 ? {} : { actual: r }
2405
2405
  };
2406
- }), lr = [
2406
+ }), cr = [
2407
2407
  "pgeagertest_",
2408
2408
  "mig_e2e_",
2409
2409
  "mig_test_",
2410
2410
  "mysqleagertest_",
2411
2411
  "mssqleagertest_",
2412
2412
  "sqliteeagertest_"
2413
- ], ur = (e) => lr.some((t) => e.startsWith(t)), dr = (e, t) => d.gen(function* () {
2413
+ ], lr = (e) => cr.some((t) => e.startsWith(t)), ur = (e, t) => d.gen(function* () {
2414
2414
  if (process.env.VOLTRO_TEST_FIXTURE_GC === "off") return [];
2415
- let n = t.filter((e) => ur(e.name)).map((e) => e.name);
2415
+ let n = t.filter((e) => lr(e.name)).map((e) => e.name);
2416
2416
  if (n.length === 0) return [];
2417
2417
  for (let t of n) yield* e.unsafe(`DROP TABLE IF EXISTS "${t}" CASCADE`).pipe(d.catchAll(() => d.void));
2418
2418
  return n;
2419
- }), fr = () => {
2419
+ }), dr = () => {
2420
2420
  let e = (process.env.VOLTRO_DB_IGNORE_TABLES ?? "").split(",").map((e) => e.trim()).filter((e) => e.length > 0);
2421
2421
  return e.length > 0 ? { ignoreTables: e } : {};
2422
- }, pr = (e) => {
2422
+ }, fr = (e) => {
2423
2423
  if (e === void 0) return;
2424
2424
  let t = e.trim();
2425
2425
  if (t === "") return;
@@ -2429,43 +2429,43 @@ BEGIN
2429
2429
  kind: "tables",
2430
2430
  tables: new Set(n)
2431
2431
  } : void 0;
2432
- }, mr = (e) => typeof e.table == "string" ? e.table : void 0, hr = (e, t = { kind: "all" }) => ({
2432
+ }, pr = (e) => typeof e.table == "string" ? e.table : void 0, mr = (e, t = { kind: "all" }) => ({
2433
2433
  ...e,
2434
2434
  operations: e.operations.map((e) => {
2435
2435
  if (!e.blocked || e.classification !== "lossy") return e;
2436
2436
  if (t?.kind === "tables") {
2437
- let n = mr(e.op);
2437
+ let n = pr(e.op);
2438
2438
  if (n === void 0 || !t.tables.has(n)) return e;
2439
2439
  }
2440
2440
  let { blocked: n, ...r } = e;
2441
2441
  return r;
2442
2442
  })
2443
- }), gr = (e, t, n) => t === "postgres" ? st(e, n).pipe(d.flatMap((e) => {
2443
+ }), hr = (e, t, n) => t === "postgres" ? st(e, n).pipe(d.flatMap((e) => {
2444
2444
  let t = ct(e);
2445
2445
  return t === void 0 ? d.void : d.logWarning(`auto-migrate: ${t}`).pipe(d.annotateLogs({ scope: "voltro:migrate" }));
2446
- }), d.catchAll(() => d.void)) : d.void, _r = (e, t, n) => d.gen(function* () {
2447
- let r = sr(e), i = t.filter((e) => !P(e.tableName));
2446
+ }), d.catchAll(() => d.void)) : d.void, gr = (e, t, n) => d.gen(function* () {
2447
+ let r = or(e), i = t.filter((e) => !P(e.tableName));
2448
2448
  if (process.env.VOLTRO_MIGRATE_FORCE !== "1") {
2449
2449
  let t = j(N(i, r));
2450
- if ((yield* or(e)) === t) return yield* gr(e, r, i), {
2450
+ if ((yield* ar(e)) === t) return yield* hr(e, r, i), {
2451
2451
  kind: "up-to-date",
2452
2452
  fingerprint: t
2453
2453
  };
2454
2454
  }
2455
- let a = yield* V(e), o = yield* dr(e, a.tables);
2455
+ let a = yield* V(e), o = yield* ur(e, a.tables);
2456
2456
  o.length > 0 && (yield* d.logInfo(`auto-migrate: reaped ${o.length} test-fixture leftover(s)`).pipe(d.annotateLogs({
2457
2457
  scope: "voltro:migrate",
2458
2458
  count: o.length
2459
2459
  })), a = yield* V(e));
2460
- let s = Pt({
2460
+ let s = Nt({
2461
2461
  declared: i,
2462
2462
  live: { tables: a.tables.filter((e) => !P(e.name)) },
2463
2463
  dialect: r,
2464
- ...fr()
2464
+ ...dr()
2465
2465
  });
2466
2466
  if (s.summary.blocked > 0) {
2467
- let e = s.operations.filter((e) => e.blocked).every((e) => e.classification === "lossy"), t = pr(process.env.VOLTRO_DESTRUCTIVE_OK);
2468
- if (t === void 0 || !e || (s = hr(s, t), s.operations.some((e) => e.blocked))) return {
2467
+ let e = s.operations.filter((e) => e.blocked).every((e) => e.classification === "lossy"), t = fr(process.env.VOLTRO_DESTRUCTIVE_OK);
2468
+ if (t === void 0 || !e || (s = mr(s, t), s.operations.some((e) => e.blocked))) return {
2469
2469
  kind: "refused-blocked",
2470
2470
  plan: s
2471
2471
  };
@@ -2475,27 +2475,27 @@ BEGIN
2475
2475
  fingerprint: s.toFingerprint
2476
2476
  } : {
2477
2477
  kind: "applied",
2478
- applied: yield* ir(e, s, {
2478
+ applied: yield* rr(e, s, {
2479
2479
  declared: t,
2480
2480
  appliedBy: n.appliedBy,
2481
2481
  environment: n.environment === "prod" ? "dev" : n.environment,
2482
2482
  source: "auto-diff",
2483
2483
  replan: (e) => d.gen(function* () {
2484
2484
  let t = yield* V(e);
2485
- return Pt({
2485
+ return Nt({
2486
2486
  declared: i,
2487
2487
  live: { tables: t.tables.filter((e) => !P(e.name)) },
2488
2488
  dialect: r,
2489
- ...fr()
2489
+ ...dr()
2490
2490
  });
2491
2491
  })
2492
2492
  }),
2493
2493
  plan: s
2494
2494
  };
2495
- }), vr = (e, t, n) => process.env.VOLTRO_AUTO_MIGRATE === "0" ? d.succeed({
2495
+ }), _r = (e, t, n) => process.env.VOLTRO_AUTO_MIGRATE === "0" ? d.succeed({
2496
2496
  kind: "skipped",
2497
2497
  reason: "VOLTRO_AUTO_MIGRATE=0"
2498
- }) : n.environment === "prod" ? cr(e, t) : _r(e, t, n), yr = (e, t) => {
2498
+ }) : n.environment === "prod" ? sr(e, t) : gr(e, t, n), vr = (e, t) => {
2499
2499
  switch (e.kind) {
2500
2500
  case "skipped": return `auto-migrate: skipped (${e.reason})`;
2501
2501
  case "up-to-date": return `auto-migrate: schema up to date (${t}, fingerprint=${M(e.fingerprint)})`;
@@ -2505,7 +2505,7 @@ BEGIN
2505
2505
  }
2506
2506
  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.";
2507
2507
  case "refused-blocked": {
2508
- 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` + ar(e.plan), c = [""];
2508
+ 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` + ir(e.plan), c = [""];
2509
2509
  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) {
2510
2510
  let t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map();
2511
2511
  for (let r of e.plan.operations) {
@@ -2522,7 +2522,7 @@ BEGIN
2522
2522
  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");
2523
2523
  }
2524
2524
  }
2525
- }, br = /* @__PURE__ */ new Set([
2525
+ }, yr = /* @__PURE__ */ new Set([
2526
2526
  "node_modules",
2527
2527
  "dist",
2528
2528
  "build",
@@ -2531,11 +2531,11 @@ BEGIN
2531
2531
  ".next",
2532
2532
  ".git",
2533
2533
  ".framework"
2534
- ]), xr = async (e) => {
2534
+ ]), br = async (e) => {
2535
2535
  let t = [], n = async (e) => {
2536
2536
  let r = await h.readdir(e, { withFileTypes: !0 }).catch(() => []);
2537
2537
  for (let i of r) {
2538
- if (br.has(i.name)) continue;
2538
+ if (yr.has(i.name)) continue;
2539
2539
  let r = g(e, i.name);
2540
2540
  i.isDirectory() ? await n(r) : i.isFile() && l.test(i.name) && t.push(r);
2541
2541
  }
@@ -2544,7 +2544,7 @@ BEGIN
2544
2544
  let n = e.split("/").pop() ?? e, r = t.split("/").pop() ?? t;
2545
2545
  return n.localeCompare(r);
2546
2546
  });
2547
- }, Sr = async (e) => {
2547
+ }, xr = async (e) => {
2548
2548
  let t = [];
2549
2549
  for (let n of e) {
2550
2550
  let e = (await import(ee(n).href)).default;
@@ -2558,11 +2558,11 @@ BEGIN
2558
2558
  });
2559
2559
  }
2560
2560
  return t;
2561
- }, Cr = (e) => e`
2561
+ }, Sr = (e) => e`
2562
2562
  SELECT ${e("id")}
2563
2563
  FROM ${e("_voltro_migration_plans")}
2564
2564
  WHERE ${e("source")} = 'file'
2565
- `.pipe(d.map((e) => e.map((e) => e.id)), d.catchAll(() => d.succeed([]))), wr = (e, t, n, r) => d.gen(function* () {
2565
+ `.pipe(d.map((e) => e.map((e) => e.id)), d.catchAll(() => d.succeed([]))), Cr = (e, t, n, r) => d.gen(function* () {
2566
2566
  let i = Date.now(), a = (/* @__PURE__ */ new Date()).toISOString(), o = {
2567
2567
  sql: e,
2568
2568
  log: {
@@ -2595,9 +2595,9 @@ BEGIN
2595
2595
  ${r}, ${n}, ${"file"},
2596
2596
  ${c}, ${a}, ${t.migration.description})
2597
2597
  `, { durationMs: c };
2598
- }), Tr = (e, t) => d.gen(function* () {
2598
+ }), wr = (e, t) => d.gen(function* () {
2599
2599
  let n = yield* d.tryPromise({
2600
- try: () => xr(g(t, "migrations")),
2600
+ try: () => br(g(t, "migrations")),
2601
2601
  catch: (e) => e
2602
2602
  });
2603
2603
  if (n.length === 0) return {
@@ -2605,20 +2605,20 @@ BEGIN
2605
2605
  skipped: []
2606
2606
  };
2607
2607
  let r = yield* d.tryPromise({
2608
- try: () => Sr(n),
2608
+ try: () => xr(n),
2609
2609
  catch: (e) => e
2610
2610
  });
2611
2611
  if (r.length === 0) return {
2612
2612
  pending: [],
2613
2613
  skipped: []
2614
2614
  };
2615
- let i = new Set(yield* Cr(e));
2615
+ let i = new Set(yield* Sr(e));
2616
2616
  return {
2617
2617
  pending: r.filter((e) => !i.has(e.migration.id)),
2618
2618
  skipped: r.filter((e) => i.has(e.migration.id)).map((e) => e.migration.id)
2619
2619
  };
2620
- }), Er = (e, t) => Tr(e, t).pipe(d.map((e) => e.pending.map((e) => e.migration.id))), Dr = (e, t) => d.gen(function* () {
2621
- let { pending: n, skipped: r } = yield* Tr(e, t.projectRoot);
2620
+ }), Tr = (e, t) => wr(e, t).pipe(d.map((e) => e.pending.map((e) => e.migration.id))), Er = (e, t) => d.gen(function* () {
2621
+ let { pending: n, skipped: r } = yield* wr(e, t.projectRoot);
2622
2622
  if (n.length === 0) return {
2623
2623
  applied: [],
2624
2624
  skipped: r
@@ -2632,7 +2632,7 @@ BEGIN
2632
2632
  id: r.migration.id,
2633
2633
  file: r.file
2634
2634
  }));
2635
- let { durationMs: n } = yield* wr(e, r, t.env, t.appliedBy);
2635
+ let { durationMs: n } = yield* Cr(e, r, t.env, t.appliedBy);
2636
2636
  i.push({
2637
2637
  id: r.migration.id,
2638
2638
  durationMs: n
@@ -2649,18 +2649,18 @@ BEGIN
2649
2649
  applied: i,
2650
2650
  skipped: r
2651
2651
  };
2652
- }), Or = (e, t) => e`
2652
+ }), Dr = (e, t) => e`
2653
2653
  SELECT ${e("id")}
2654
2654
  FROM ${e("_voltro_migration_plans")}
2655
2655
  WHERE ${e("id")} = ${t} AND ${e("source")} = 'file'
2656
2656
  LIMIT 1
2657
- `, kr = (e, t) => d.gen(function* () {
2658
- if (!(yield* Or(e, t.id))[0]) return yield* d.fail(/* @__PURE__ */ Error(`rollback: ${t.id} not found in _voltro_migration_plans (file source)`));
2657
+ `, Or = (e, t) => d.gen(function* () {
2658
+ if (!(yield* Dr(e, t.id))[0]) return yield* d.fail(/* @__PURE__ */ Error(`rollback: ${t.id} not found in _voltro_migration_plans (file source)`));
2659
2659
  let n = yield* d.tryPromise({
2660
- try: () => xr(g(t.projectRoot, "migrations")),
2660
+ try: () => br(g(t.projectRoot, "migrations")),
2661
2661
  catch: (e) => e
2662
2662
  }), r = (yield* d.tryPromise({
2663
- try: () => Sr(n),
2663
+ try: () => xr(n),
2664
2664
  catch: (e) => e
2665
2665
  })).find((e) => e.migration.id === t.id);
2666
2666
  if (!r) return yield* d.fail(/* @__PURE__ */ Error(`rollback: file for migration ${t.id} not found on disk under ${t.projectRoot}/migrations/`));
@@ -2693,7 +2693,7 @@ BEGIN
2693
2693
  } finally {
2694
2694
  yield* w(e).pipe(d.orDie);
2695
2695
  }
2696
- }), Ar = (e) => d.gen(function* () {
2696
+ }), kr = (e) => d.gen(function* () {
2697
2697
  let t = yield* p.SqlClient, n = yield* t`
2698
2698
  SELECT id, fingerprint, appliedAt FROM _voltro_migration_plans
2699
2699
  WHERE source = 'auto-diff'
@@ -2738,10 +2738,10 @@ BEGIN
2738
2738
  snapshotFingerprint: e.fingerprint,
2739
2739
  snapshotId: i
2740
2740
  };
2741
- }), jr = (e, ...t) => ({
2741
+ }), Ar = (e, ...t) => ({
2742
2742
  _tag: "RawSqlFragment",
2743
2743
  strings: [...e],
2744
2744
  values: [...t]
2745
- }), Mr = (e) => typeof e == "object" && !!e && e._tag === "RawSqlFragment";
2745
+ }), jr = (e) => typeof e == "object" && !!e && e._tag === "RawSqlFragment";
2746
2746
  //#endregion
2747
- export { l as FILE_MIGRATION_PATTERN, ot as REACTIVE_TRIGGER_PREFIX, re as VOLTRO_MIGRATION_LOCK_KEY, mt as _internalCmp, C as acquireMigrationLock, Je as applyNamespacedSchema, ir as applyPlan, He as applySchema, Vt as chunkTables, N as declaredSnapshot, be as defaultArrayClause, ye as defaultClause, D as defaultJsonClause, yr as describeOutcome, pr as destructiveScope, st as detectReactiveTriggerDrift, $t as emitDropColumnDdl, en as emitDropColumnDdlMysql, Ve as emitFrameworkBootstrapSql, ze as emitNamespaceProvisionDdl, Be as emitNamespacedSchemaSql, A as emitSchemaSql, j as fingerprintSchema, ct as formatReactiveTriggerDrift, fr as ignoreTablesFromEnv, V as introspectSchema, o as isFileMigration, Mr as isRawSqlFragment, It as mapPgType, s as migration, O as numericIdSql, Ft as parseEnumCheck, Er as pendingFileMigrationIds, Pt as planMigrations, Ye as provisionTenantNamespace, w as releaseMigrationLock, gn as renderColumnMysql, dn as renderColumnPg, kr as rollbackFileBasedMigration, Dr as runFileBasedMigrations, Xe as runFrameworkBootstrap, qe as runMigrate, vr as runPlannedMigrations, M as shortFingerprint, nt as snapshotColumn, jr as sql, E as sqlType, Ar as squashMigrationPlans, hr as unblockLossy, _e as withMigrationLock };
2747
+ export { l as FILE_MIGRATION_PATTERN, ot as REACTIVE_TRIGGER_PREFIX, re as VOLTRO_MIGRATION_LOCK_KEY, C as acquireMigrationLock, Je as applyNamespacedSchema, rr as applyPlan, He as applySchema, Bt as chunkTables, N as declaredSnapshot, be as defaultArrayClause, ye as defaultClause, D as defaultJsonClause, vr as describeOutcome, fr as destructiveScope, st as detectReactiveTriggerDrift, Qt as emitDropColumnDdl, $t as emitDropColumnDdlMysql, Ve as emitFrameworkBootstrapSql, ze as emitNamespaceProvisionDdl, Be as emitNamespacedSchemaSql, A as emitSchemaSql, j as fingerprintSchema, ct as formatReactiveTriggerDrift, dr as ignoreTablesFromEnv, V as introspectSchema, o as isFileMigration, jr as isRawSqlFragment, Ft as mapPgType, s as migration, O as numericIdSql, Pt as parseEnumCheck, Tr as pendingFileMigrationIds, Nt as planMigrations, Ye as provisionTenantNamespace, w as releaseMigrationLock, hn as renderColumnMysql, un as renderColumnPg, Or as rollbackFileBasedMigration, Er as runFileBasedMigrations, Xe as runFrameworkBootstrap, qe as runMigrate, _r as runPlannedMigrations, M as shortFingerprint, nt as snapshotColumn, Ar as sql, E as sqlType, kr as squashMigrationPlans, mr as unblockLossy, _e as withMigrationLock };