@voltro/database 0.30.2 → 0.31.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 { H as e, U as t, a as n, c as r, d as i, ft as a, i as o, n as s, o as c, ot as l, q as u, r as d, s as f } from "./frameworkLiveTables-CMyumigs.js";
1
+ import { J as e, U as t, W as n, a as r, c as i, d as a, i as o, n as s, o as c, pt as l, r as u, s as d, st as f } from "./frameworkLiveTables-DbAgeVOU.js";
2
2
  import { Effect as p } from "effect";
3
3
  import { createLogger as m } from "@voltro/logger";
4
4
  import { SqlClient as h } from "@effect/sql";
@@ -39,7 +39,7 @@ var b = (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
- }, x = (e) => e.unique === !0 && typeof e.where == "string" && e.where.length > 0, S = (e) => e.replace(/"/g, "`"), ee = (e) => typeof e == "string" ? e : e.name ?? String(e), C = (e, t) => `_ua_${t}_${e}`.slice(0, 64), te = (e, t) => {
42
+ }, x = (e) => e.unique === !0 && typeof e.where == "string" && e.where.length > 0, S = (e) => e.replace(/"/g, "`"), ee = (e) => typeof e == "string" ? e : e.name ?? String(e), C = (e, t) => `_ua_${t}_${e}`.slice(0, 64), w = (e, t) => {
43
43
  if (t !== "mysql" && t !== "mariadb" || !e.appliedIndexes.some(x)) return e;
44
44
  let n = { ...e.fields }, r = [], i = [];
45
45
  for (let t of e.appliedIndexes) {
@@ -74,101 +74,101 @@ var b = (e, t, n, r = 400) => {
74
74
  appliedIndexes: r,
75
75
  appliedUniques: [...e.appliedUniques ?? [], ...i]
76
76
  };
77
- }, w = (e, t) => `${e}::${t}`, ne = (e, t) => {
77
+ }, T = (e, t) => `${e}::${t}`, te = (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(w(e, t.column)) : r.has(t.target) || a(t.target);
81
+ for (let t of o) n.has(t.target) ? i.add(T(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
- }, re = 6322741009312437n, ie = 250, ae = () => {
86
+ }, ne = 6322741009312437n, re = 250, ie = () => {
87
87
  let e = Number(process.env.VOLTRO_MIGRATION_LOCK_TIMEOUT_MS);
88
88
  return Number.isFinite(e) && e > 0 ? e : 3e4;
89
- }, oe = (e) => p.gen(function* () {
90
- let t = ae(), n = Date.now();
89
+ }, ae = (e) => p.gen(function* () {
90
+ let t = ie(), n = Date.now();
91
91
  for (;;) {
92
92
  if ((yield* e`
93
93
  SELECT pg_try_advisory_lock(${"6322741009312437"}::bigint) AS got`)[0]?.got) return;
94
- Date.now() - n >= t && (yield* p.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* p.sleep(`${ie} millis`);
94
+ Date.now() - n >= t && (yield* p.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* p.sleep(`${re} millis`);
95
95
  }
96
- }), se = (e) => p.gen(function* () {
97
- yield* e`SELECT pg_advisory_unlock(${re.toString()}::bigint)`;
98
- }), ce = `voltro_migration_${re.toString(36)}`, le = 30, ue = (e) => p.gen(function* () {
96
+ }), oe = (e) => p.gen(function* () {
97
+ yield* e`SELECT pg_advisory_unlock(${ne.toString()}::bigint)`;
98
+ }), se = `voltro_migration_${ne.toString(36)}`, ce = 30, le = (e) => p.gen(function* () {
99
99
  (yield* e`
100
- SELECT GET_LOCK(${ce}, ${le}) AS got`)[0]?.got !== 1 && (yield* p.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
- }), de = (e) => p.gen(function* () {
102
- yield* e`SELECT RELEASE_LOCK(${ce})`;
103
- }), fe = `voltro_migration_${re.toString(36)}`, pe = 3e4, me = (e) => p.gen(function* () {
100
+ SELECT GET_LOCK(${se}, ${ce}) AS got`)[0]?.got !== 1 && (yield* p.die(/* @__PURE__ */ Error(`could not acquire the migration lock '${se}' within ${ce}s (another migration is in progress, or a prior one left it held).`)));
101
+ }), ue = (e) => p.gen(function* () {
102
+ yield* e`SELECT RELEASE_LOCK(${se})`;
103
+ }), de = `voltro_migration_${ne.toString(36)}`, fe = 3e4, pe = (e) => p.gen(function* () {
104
104
  let t = yield* e`
105
105
  DECLARE @res int;
106
- EXEC @res = sp_getapplock @Resource = ${fe}, @LockMode = 'Exclusive',
107
- @LockOwner = 'Session', @LockTimeout = ${pe};
106
+ EXEC @res = sp_getapplock @Resource = ${de}, @LockMode = 'Exclusive',
107
+ @LockOwner = 'Session', @LockTimeout = ${fe};
108
108
  SELECT @res AS res`;
109
- (t[0]?.res ?? -999) < 0 && (yield* p.die(/* @__PURE__ */ Error(`could not acquire the migration lock '${fe}' (sp_getapplock returned ${t[0]?.res ?? "no row"}; another migration is in progress).`)));
110
- }), he = (e) => p.gen(function* () {
111
- yield* e`EXEC sp_releaseapplock @Resource = ${fe}, @LockOwner = 'Session'`;
112
- }), ge = p.void, T = (e) => e.onDialectOrElse({
109
+ (t[0]?.res ?? -999) < 0 && (yield* p.die(/* @__PURE__ */ Error(`could not acquire the migration lock '${de}' (sp_getapplock returned ${t[0]?.res ?? "no row"}; another migration is in progress).`)));
110
+ }), me = (e) => p.gen(function* () {
111
+ yield* e`EXEC sp_releaseapplock @Resource = ${de}, @LockOwner = 'Session'`;
112
+ }), he = p.void, E = (e) => e.onDialectOrElse({
113
+ mysql: () => le(e),
114
+ mssql: () => pe(e),
115
+ sqlite: () => he,
116
+ orElse: () => ae(e)
117
+ }), D = (e) => e.onDialectOrElse({
113
118
  mysql: () => ue(e),
114
119
  mssql: () => me(e),
115
- sqlite: () => ge,
120
+ sqlite: () => he,
116
121
  orElse: () => oe(e)
117
- }), E = (e) => e.onDialectOrElse({
118
- mysql: () => de(e),
119
- mssql: () => he(e),
120
- sqlite: () => ge,
121
- orElse: () => se(e)
122
- }), D = (e, t) => p.acquireUseRelease(T(e), () => t, () => E(e).pipe(p.orDie)), O = "framework_changes", k = "framework_changes_", _e = (e, t) => t === "framework_changes" ? `${k}${e}` : `${k}${t}_${e}`, ve = (e) => e === "framework_changes" ? "framework_notify_change" : `framework_notify_change_${e}`, ye = m({ scope: "voltro:migrate" }), A = (e) => {
122
+ }), ge = (e, t) => p.acquireUseRelease(E(e), () => t, () => D(e).pipe(p.orDie)), O = "framework_changes", k = "framework_changes_", _e = (e, t) => t === "framework_changes" ? `${k}${e}` : `${k}${t}_${e}`, ve = (e) => e === "framework_changes" ? "framework_notify_change" : `framework_notify_change_${e}`, ye = m({ scope: "voltro:migrate" }), A = (e) => {
123
123
  ye.warn(e.replace(/^\[voltro:migrate\]\s*/, ""));
124
- }, j = (t, n) => {
125
- let r = t.type;
126
- if (t.spatial) {
127
- if (n === "postgres") return `${t.spatial.kind}(${t.spatial.geomKind},${t.spatial.srid})`;
128
- throw Error(`@voltro/plugin-postgis: ${t.spatial.kind}('${t.spatial.geomKind}', ${t.spatial.srid}) is postgres-only — the active dialect is '${n}'. PostGIS has no portable equivalent; use store: 'postgres' (or DB_DIALECT=postgres) for spatial columns, or model the value as plain text/json.`);
124
+ }, j = (e, n) => {
125
+ let r = e.type;
126
+ if (e.spatial) {
127
+ if (n === "postgres") return `${e.spatial.kind}(${e.spatial.geomKind},${e.spatial.srid})`;
128
+ throw Error(`@voltro/plugin-postgis: ${e.spatial.kind}('${e.spatial.geomKind}', ${e.spatial.srid}) is postgres-only — the active dialect is '${n}'. PostGIS has no portable equivalent; use store: 'postgres' (or DB_DIALECT=postgres) for spatial columns, or model the value as plain text/json.`);
129
129
  }
130
130
  if (r === "raw") {
131
- if (t.rawDdl === void 0) throw Error("raw() column is missing its DDL fragment — this is a framework bug.");
132
- return t.rawDdl;
131
+ if (e.rawDdl === void 0) throw Error("raw() column is missing its DDL fragment — this is a framework bug.");
132
+ return e.rawDdl;
133
133
  }
134
- if (r === "array" && t.arrayElement) {
134
+ if (r === "array" && e.arrayElement) {
135
135
  if (n === "postgres") return `${j({
136
- ...t,
137
- type: t.arrayElement,
136
+ ...e,
137
+ type: e.arrayElement,
138
138
  arrayElement: void 0
139
139
  }, n)}[]`;
140
140
  if (n === "mysql" || n === "mariadb") return "JSON";
141
141
  if (n === "mssql") return "NVARCHAR(MAX)";
142
- if (e(n)) return "TEXT";
142
+ if (t(n)) return "TEXT";
143
143
  }
144
144
  if (r === "vector") {
145
- let r = t.vectorDim;
145
+ let r = e.vectorDim;
146
146
  if (r === void 0) throw Error("vector column is missing its dimension — this is a framework bug.");
147
- let i = t.vectorPrecision === "half";
147
+ let i = e.vectorPrecision === "half";
148
148
  if (n === "postgres") return i ? `HALFVEC(${r})` : `VECTOR(${r})`;
149
149
  if (n === "mysql" || n === "mariadb") return `VECTOR(${r})`;
150
150
  if (n === "mssql") return "VARBINARY(MAX)";
151
- if (e(n)) return "BLOB";
151
+ if (t(n)) return "BLOB";
152
152
  }
153
153
  if (r === "interval") {
154
154
  if (n === "postgres") return "INTERVAL";
155
155
  if (n === "mysql" || n === "mariadb" || n === "mssql") return "BIGINT";
156
- if (e(n)) return "INTEGER";
156
+ if (t(n)) return "INTEGER";
157
157
  }
158
158
  if (r === "decimal") {
159
- let r = t.precision, i = t.scale ?? 0;
159
+ let r = e.precision, i = e.scale ?? 0;
160
160
  if (r === void 0) throw Error("decimal column is missing its precision — this is a framework bug.");
161
- return e(n) ? "NUMERIC" : n === "postgres" ? `NUMERIC(${r}, ${i})` : `DECIMAL(${r}, ${i})`;
161
+ return t(n) ? "NUMERIC" : n === "postgres" ? `NUMERIC(${r}, ${i})` : `DECIMAL(${r}, ${i})`;
162
162
  }
163
- if (r === "bigint") return e(n) ? "INTEGER" : "BIGINT";
163
+ if (r === "bigint") return t(n) ? "INTEGER" : "BIGINT";
164
164
  if (r === "enum") {
165
- if (n === "postgres") return t.enumName ?? "TEXT";
166
- if (n === "mysql" || n === "mariadb") return `ENUM(${(t.enumValues ?? []).map((e) => `'${e.replace(/'/g, "''")}'`).join(", ")})`;
165
+ if (n === "postgres") return e.enumName ?? "TEXT";
166
+ if (n === "mysql" || n === "mariadb") return `ENUM(${(e.enumValues ?? []).map((e) => `'${e.replace(/'/g, "''")}'`).join(", ")})`;
167
167
  if (n === "mssql") return "NVARCHAR(255)";
168
- if (e(n)) return "TEXT";
168
+ if (t(n)) return "TEXT";
169
169
  }
170
- if (r === "text" && t.maxLength !== void 0 && t.generatedAs === void 0) return n === "mssql" ? `NVARCHAR(${t.maxLength})` : e(n) ? "TEXT" : `VARCHAR(${t.maxLength})`;
171
- if (e(n)) switch (r) {
170
+ if (r === "text" && e.maxLength !== void 0 && e.generatedAs === void 0) return n === "mssql" ? `NVARCHAR(${e.maxLength})` : t(n) ? "TEXT" : `VARCHAR(${e.maxLength})`;
171
+ if (t(n)) switch (r) {
172
172
  case "id": return "TEXT";
173
173
  case "text": return "TEXT";
174
174
  case "integer": return "INTEGER";
@@ -186,7 +186,7 @@ var b = (e, t, n, r = 400) => {
186
186
  }
187
187
  if (n === "mysql" || n === "mariadb") switch (r) {
188
188
  case "id": return "VARCHAR(64)";
189
- case "text": return t.hasDefault && t.defaultFactory === void 0 || t.oneOf && t.oneOf.length > 0 ? "VARCHAR(255)" : t.generatedAs ? "TEXT" : "LONGTEXT";
189
+ case "text": return e.hasDefault && e.defaultFactory === void 0 || e.oneOf && e.oneOf.length > 0 ? "VARCHAR(255)" : e.generatedAs ? "TEXT" : "LONGTEXT";
190
190
  case "integer": return "INT";
191
191
  case "real": return "DOUBLE";
192
192
  case "boolean": return "TINYINT(1)";
@@ -202,7 +202,7 @@ var b = (e, t, n, r = 400) => {
202
202
  }
203
203
  if (n === "mssql") switch (r) {
204
204
  case "id": return "NVARCHAR(64)";
205
- case "text": return t.hasDefault && t.defaultFactory === void 0 || t.oneOf && t.oneOf.length > 0 ? "NVARCHAR(450)" : "NVARCHAR(MAX)";
205
+ case "text": return e.hasDefault && e.defaultFactory === void 0 || e.oneOf && e.oneOf.length > 0 ? "NVARCHAR(450)" : "NVARCHAR(MAX)";
206
206
  case "integer": return "INT";
207
207
  case "real": return "FLOAT";
208
208
  case "boolean": return "BIT";
@@ -228,14 +228,14 @@ var b = (e, t, n, r = 400) => {
228
228
  case "bytes": return "BYTEA";
229
229
  case "reference": return "TEXT";
230
230
  case "vector": return "VECTOR";
231
- case "enum": return t.enumName ?? "TEXT";
231
+ case "enum": return e.enumName ?? "TEXT";
232
232
  case "array": return "TEXT[]";
233
233
  case "interval": return "INTERVAL";
234
234
  }
235
- }, be = (t, n) => {
236
- if (!t.hasDefault || t.defaultFactory !== void 0) return null;
237
- let r = t.defaultValue;
238
- return r === "now" ? e(n) ? "DEFAULT CURRENT_TIMESTAMP" : n === "mssql" ? "DEFAULT SYSUTCDATETIME()" : n === "mysql" || n === "mariadb" ? "DEFAULT CURRENT_TIMESTAMP(6)" : "DEFAULT now()" : typeof r == "boolean" ? n === "postgres" ? `DEFAULT ${r}` : `DEFAULT ${+!!r}` : typeof r == "number" ? `DEFAULT ${r}` : typeof r == "string" ? `DEFAULT '${r.replace(/'/g, "''")}'` : Array.isArray(r) ? xe(r, t, n) : typeof r == "object" && r ? M(r, n) : null;
235
+ }, be = (e, n) => {
236
+ if (!e.hasDefault || e.defaultFactory !== void 0) return null;
237
+ let r = e.defaultValue;
238
+ return r === "now" ? t(n) ? "DEFAULT CURRENT_TIMESTAMP" : n === "mssql" ? "DEFAULT SYSUTCDATETIME()" : n === "mysql" || n === "mariadb" ? "DEFAULT CURRENT_TIMESTAMP(6)" : "DEFAULT now()" : typeof r == "boolean" ? n === "postgres" ? `DEFAULT ${r}` : `DEFAULT ${+!!r}` : typeof r == "number" ? `DEFAULT ${r}` : typeof r == "string" ? `DEFAULT '${r.replace(/'/g, "''")}'` : Array.isArray(r) ? xe(r, e, n) : typeof r == "object" && r ? M(r, n) : null;
239
239
  }, xe = (e, t, n) => {
240
240
  if (n !== "postgres" || t.type !== "array" || t.arrayElement === void 0) return M(e, n);
241
241
  let r = j({
@@ -246,7 +246,7 @@ var b = (e, t, n, r = 400) => {
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
247
  }, M = (e, t) => {
248
248
  let n = JSON.stringify(e).replace(/'/g, "''");
249
- return t === "postgres" ? `DEFAULT '${n}'::jsonb` : t === "mysql" || t === "mariadb" ? `DEFAULT (CAST('${n}' AS JSON))` : `DEFAULT '${n}'`;
249
+ return t === "postgres" ? `DEFAULT '${n}'::jsonb` : t === "mysql" || t === "mariadb" ? `DEFAULT (CONVERT('${n}' USING utf8mb4))` : `DEFAULT '${n}'`;
250
250
  }, N = (e, t) => {
251
251
  switch (t) {
252
252
  case "postgres": return `"${e}" BIGSERIAL PRIMARY KEY`;
@@ -264,10 +264,10 @@ var b = (e, t, n, r = 400) => {
264
264
  case "setNull": return "SET NULL";
265
265
  case "noAction": return "NO ACTION";
266
266
  }
267
- }, Ce = (e, n, r) => r === null ? t(e, n) : `${t(r, n)}.${t(e, n)}`, we = 191, Te = (e, n, r) => {
268
- let i = t(e, r);
267
+ }, Ce = (e, t, r) => r === null ? n(e, t) : `${n(r, t)}.${n(e, t)}`, we = 191, Te = (e, t, r) => {
268
+ let i = n(e, r);
269
269
  if (r !== "mysql" && r !== "mariadb") return i;
270
- let a = n[e];
270
+ let a = t[e];
271
271
  if (!a) return i;
272
272
  let o = j(a, r).toUpperCase();
273
273
  return o.endsWith("TEXT") || o.endsWith("BLOB") ? `${i}(${we})` : i;
@@ -279,9 +279,9 @@ var b = (e, t, n, r = 400) => {
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
- }, De = (n, r, i, a, o = !1, s = !1) => {
283
- if (r.type === "id" && r.idScheme?.kind === "numeric") return N(n, i);
284
- let c = i === "mssql" && r.type === "text" && !r.generatedAs && r.maxLength === void 0 && a?.has(n) ? "NVARCHAR(450)" : j(r, i), l = [t(n, i), c];
282
+ }, De = (e, r, i, a, o = !1, s = !1) => {
283
+ if (r.type === "id" && r.idScheme?.kind === "numeric") return N(e, i);
284
+ let c = i === "mssql" && r.type === "text" && !r.generatedAs && r.maxLength === void 0 && a?.has(e) ? "NVARCHAR(450)" : j(r, i), l = [n(e, i), c];
285
285
  r.type === "id" && !s && l.push("PRIMARY KEY");
286
286
  let u = Ee(r, i);
287
287
  if (u) l.push(u);
@@ -292,39 +292,39 @@ var b = (e, t, n, r = 400) => {
292
292
  }
293
293
  if (r.type === "reference" && r.references && !o) {
294
294
  let e = r.references();
295
- l.push(`REFERENCES ${t(e.tableName, i)} (${t("id", i)})`);
296
- let n = Se(r.onDelete ?? "restrict", i);
297
- l.push(`ON DELETE ${n}`);
295
+ l.push(`REFERENCES ${n(e.tableName, i)} (${n("id", i)})`);
296
+ let t = Se(r.onDelete ?? "restrict", i);
297
+ l.push(`ON DELETE ${t}`);
298
298
  let a = Se(r.refOnUpdate ?? "noAction", i);
299
299
  a !== "NO ACTION" && l.push(`ON UPDATE ${a}`);
300
300
  }
301
301
  if (r.oneOf && r.oneOf.length > 0) {
302
- let e = r.oneOf.map((e) => `'${e.replace(/'/g, "''")}'`).join(", ");
303
- l.push(`CHECK (${t(n, i)} IN (${e}))`);
302
+ let t = r.oneOf.map((e) => `'${e.replace(/'/g, "''")}'`).join(", ");
303
+ l.push(`CHECK (${n(e, i)} IN (${t}))`);
304
304
  }
305
305
  if (r.checks && r.checks.length > 0) for (let e of r.checks) l.push(`CHECK (${e})`);
306
- if (r.type === "enum" && r.enumValues && r.enumValues.length > 0 && (i === "mssql" || e(i))) {
307
- let e = r.enumValues.map((e) => `'${e.replace(/'/g, "''")}'`).join(", ");
308
- l.push(`CHECK (${t(n, i)} IN (${e}))`);
306
+ if (r.type === "enum" && r.enumValues && r.enumValues.length > 0 && (i === "mssql" || t(i))) {
307
+ let t = r.enumValues.map((e) => `'${e.replace(/'/g, "''")}'`).join(", ");
308
+ l.push(`CHECK (${n(e, i)} IN (${t}))`);
309
309
  }
310
310
  if (r.type === "json" || r.type === "array") {
311
- let r = t(n, i);
312
- e(i) ? l.push(`CHECK (${r} IS NULL OR json_valid(${r}))`) : i === "mssql" && l.push(`CHECK (${r} IS NULL OR ISJSON(${r}) = 1)`);
311
+ let r = n(e, i);
312
+ t(i) ? l.push(`CHECK (${r} IS NULL OR json_valid(${r}))`) : i === "mssql" && l.push(`CHECK (${r} IS NULL OR ISJSON(${r}) = 1)`);
313
313
  }
314
314
  return l.join(" ");
315
- }, Oe = (e, n, r = null, i) => {
315
+ }, Oe = (e, t, r = null, i) => {
316
316
  let a = /* @__PURE__ */ new Set();
317
317
  for (let t of e.appliedIndexes ?? []) for (let e of t.fields) typeof e == "string" && a.add(e);
318
318
  for (let t of e.appliedUniques ?? []) for (let e of t.fields) typeof e == "string" && a.add(e);
319
- let o = e.appliedPrimaryKey ?? [], s = o.length > 0, c = Object.entries(e.fields).map(([e, t]) => ` ${De(e, t, n, a, i?.has(e) ?? !1, s)}`).join(",\n"), l = (e.appliedUniques ?? []).map((r) => {
320
- let i = r.fields.map((t) => Te(t, e.fields, n)).join(", ");
321
- return ` CONSTRAINT ${t(r.name, n)} UNIQUE (${i})`;
322
- }), u = (e.appliedChecks ?? []).map((e) => ` CONSTRAINT ${t(e.name, n)} CHECK (${e.expr})`), d = [
323
- ...s ? [` PRIMARY KEY (${o.map((t) => Te(t, e.fields, n)).join(", ")})`] : [],
319
+ let o = e.appliedPrimaryKey ?? [], s = o.length > 0, c = Object.entries(e.fields).map(([e, n]) => ` ${De(e, n, t, a, i?.has(e) ?? !1, s)}`).join(",\n"), l = (e.appliedUniques ?? []).map((r) => {
320
+ let i = r.fields.map((n) => Te(n, e.fields, t)).join(", ");
321
+ return ` CONSTRAINT ${n(r.name, t)} UNIQUE (${i})`;
322
+ }), u = (e.appliedChecks ?? []).map((e) => ` CONSTRAINT ${n(e.name, t)} CHECK (${e.expr})`), d = [
323
+ ...s ? [` PRIMARY KEY (${o.map((n) => Te(n, e.fields, t)).join(", ")})`] : [],
324
324
  ...l,
325
325
  ...u
326
- ], f = d.length > 0 ? `${c},\n${d.join(",\n")}` : c, p = Ce(e.tableName, n, r);
327
- if (n === "mssql") {
326
+ ], f = d.length > 0 ? `${c},\n${d.join(",\n")}` : c, p = Ce(e.tableName, t, r);
327
+ if (t === "mssql") {
328
328
  let t = r === null ? e.tableName : `${r}.${e.tableName}`, n = `CREATE TABLE ${p} (\n${f}\n)`;
329
329
  return `IF OBJECT_ID('${t.replace(/'/g, "''")}', 'U') IS NULL EXEC(N'${n.replace(/'/g, "''")}');`;
330
330
  }
@@ -333,97 +333,97 @@ var b = (e, t, n, r = 400) => {
333
333
  f,
334
334
  ");"
335
335
  ].join("\n");
336
- }, ke = (e, n, r) => {
337
- let i = `${e}_${n.name}_fts`, a = (e) => t(e, r), o = n.columns.map(a).join(", "), s = n.columns.map((e) => `new.${a(e)}`).join(", "), c = [];
336
+ }, ke = (e, t, r) => {
337
+ let i = `${e}_${t.name}_fts`, a = (e) => n(e, r), o = t.columns.map(a).join(", "), s = t.columns.map((e) => `new.${a(e)}`).join(", "), c = [];
338
338
  return c.push(`CREATE VIRTUAL TABLE IF NOT EXISTS ${a(i)} USING fts5(${o}, row_id UNINDEXED, tokenize='porter');`), c.push(`CREATE TRIGGER IF NOT EXISTS ${a(`${i}_ai`)} AFTER INSERT ON ${a(e)} BEGIN\n INSERT INTO ${a(i)} (${o}, row_id) VALUES (${s}, new.${a("id")});\nEND;`), c.push(`CREATE TRIGGER IF NOT EXISTS ${a(`${i}_ad`)} AFTER DELETE ON ${a(e)} BEGIN\n DELETE FROM ${a(i)} WHERE row_id = old.${a("id")};\nEND;`), c.push(`CREATE TRIGGER IF NOT EXISTS ${a(`${i}_au`)} AFTER UPDATE ON ${a(e)} BEGIN\n DELETE FROM ${a(i)} WHERE row_id = old.${a("id")};\n INSERT INTO ${a(i)} (${o}, row_id) VALUES (${s}, new.${a("id")});\nEND;`), c;
339
- }, Ae = (e, n, r = null) => {
340
- let i = [], a = /* @__PURE__ */ new Set(), o = (e) => e.join("\0"), s = (e, t, r, i) => {
341
- let a = {
339
+ }, Ae = (t, r, i = null) => {
340
+ let a = [], o = /* @__PURE__ */ new Set(), s = (e) => e.join("\0"), c = (t, n, i, a) => {
341
+ let o = {
342
342
  using: "",
343
343
  withSuffix: "",
344
344
  skip: !1
345
345
  };
346
- if (r === void 0 || r === "btree") return a;
347
- if (r === "gist") return n === "postgres" ? {
346
+ if (i === void 0 || i === "btree") return o;
347
+ if (i === "gist") return r === "postgres" ? {
348
348
  using: " USING GIST",
349
349
  withSuffix: "",
350
350
  skip: !1
351
- } : (A(`[voltro:migrate] index '${e}' on '${t}': ${n} doesn't support GiST — falling back to btree. Spatial queries on this column will fall back to sequential scan.`), a);
352
- if (r === "gin") return n === "postgres" ? {
351
+ } : (A(`[voltro:migrate] index '${t}' on '${n}': ${r} doesn't support GiST — falling back to btree. Spatial queries on this column will fall back to sequential scan.`), o);
352
+ if (i === "gin") return r === "postgres" ? {
353
353
  using: " USING GIN",
354
354
  withSuffix: "",
355
355
  skip: !1
356
- } : n === "mysql" || n === "mariadb" ? (A(`[voltro:migrate] gin index '${e}' on '${t}': ${n} 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" ? (A(`[voltro:migrate] gin index '${t}' 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
- }) : (A(`[voltro:migrate] gin index '${e}' on '${t}': ${n} has no GIN access method — falling back to btree. Containment/membership queries won't use this index efficiently.`), a);
361
- if (r === "brin") return n === "postgres" ? {
360
+ }) : (A(`[voltro:migrate] gin index '${t}' on '${n}': ${r} has no GIN access method — falling back to btree. Containment/membership queries won't use this index efficiently.`), o);
361
+ if (i === "brin") return r === "postgres" ? {
362
362
  using: " USING BRIN",
363
363
  withSuffix: "",
364
364
  skip: !1
365
- } : (A(`[voltro:migrate] brin index '${e}' on '${t}': ${n} has no BRIN access method — falling back to btree (larger on disk, but the range scan still works).`), a);
366
- if (r === "hnsw") {
367
- if (n === "postgres") {
368
- let e = i?.hnsw?.m ?? 16, t = i?.hnsw?.efConstruction ?? 64, n = i?.hnsw?.opclass ?? u(i?.hnsw?.distance);
365
+ } : (A(`[voltro:migrate] brin index '${t}' on '${n}': ${r} has no BRIN access method — falling back to btree (larger on disk, but the range scan still works).`), o);
366
+ if (i === "hnsw") {
367
+ if (r === "postgres") {
368
+ let t = a?.hnsw?.m ?? 16, n = a?.hnsw?.efConstruction ?? 64, r = a?.hnsw?.opclass ?? e(a?.hnsw?.distance);
369
369
  return {
370
370
  using: " USING hnsw",
371
- withSuffix: ` WITH (m = ${e}, ef_construction = ${t})`,
372
- opclass: n,
371
+ withSuffix: ` WITH (m = ${t}, ef_construction = ${n})`,
372
+ opclass: r,
373
373
  skip: !1
374
374
  };
375
375
  }
376
- return A(`[voltro:migrate] hnsw index '${e}' on '${t}': ${n} has no pgvector / HNSW access method — skipping. Nearest-neighbour queries on this column fall back to a sequential scan.`), {
376
+ return A(`[voltro:migrate] hnsw index '${t}' 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
380
380
  };
381
381
  }
382
- return a;
383
- }, c = (t, r) => {
384
- let i = t.map((t) => {
385
- if (typeof t == "string") return Te(t, e.fields, n);
386
- if ("jsonPath" in t) {
387
- let { column: e, path: r, numeric: i } = t.jsonPath;
388
- return `(${f(e, r, n, { numeric: i })})`;
382
+ return o;
383
+ }, l = (e, n) => {
384
+ let i = e.map((e) => {
385
+ if (typeof e == "string") return Te(e, t.fields, r);
386
+ if ("jsonPath" in e) {
387
+ let { column: t, path: n, numeric: i } = e.jsonPath;
388
+ return `(${d(t, n, r, { numeric: i })})`;
389
389
  }
390
- return `(${t.expr})`;
390
+ return `(${e.expr})`;
391
391
  });
392
- return r !== void 0 && i.length === 1 ? `${i[0]} ${r}` : i.join(", ");
393
- }, l = (e, i, a, o, l, u = "", d = !1) => {
394
- let f = s(e, i, o, l);
392
+ return n !== void 0 && i.length === 1 ? `${i[0]} ${n}` : i.join(", ");
393
+ }, u = (e, t, a, o, s, u = "", d = !1) => {
394
+ let f = c(e, t, o, s);
395
395
  if (f.skip) return "";
396
- let p = c(a, f.opclass), m = `${f.withSuffix}${u}`, h = Ce(i, n, r), g = d ? "UNIQUE " : "";
397
- return n === "mssql" ? `IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = '${e}') CREATE ${g}INDEX ${t(e, n)} ON ${h}${f.using} (${p})${m};` : n === "mysql" ? `CREATE ${g}INDEX ${t(e, n)} ON ${h}${f.using} (${p})${m};` : `CREATE ${g}INDEX IF NOT EXISTS ${t(e, n)} ON ${h}${f.using} (${p})${m};`;
396
+ let p = l(a, f.opclass), m = `${f.withSuffix}${u}`, h = Ce(t, r, i), g = d ? "UNIQUE " : "";
397
+ return r === "mssql" ? `IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = '${e}') CREATE ${g}INDEX ${n(e, r)} ON ${h}${f.using} (${p})${m};` : r === "mysql" ? `CREATE ${g}INDEX ${n(e, r)} ON ${h}${f.using} (${p})${m};` : `CREATE ${g}INDEX IF NOT EXISTS ${n(e, r)} ON ${h}${f.using} (${p})${m};`;
398
398
  };
399
- for (let r of e.appliedFullText ?? []) if (n === "postgres") {
400
- let a = r.config ?? "english", o = `${r.name}_tsv`, s = r.columns.map((e) => {
401
- let i = r.weights?.[e] ?? "A";
402
- return `setweight(to_tsvector('${a}', coalesce(${t(e, n)}, '')), '${i}')`;
399
+ for (let e of t.appliedFullText ?? []) if (r === "postgres") {
400
+ let i = e.config ?? "english", o = `${e.name}_tsv`, s = e.columns.map((t) => {
401
+ let a = e.weights?.[t] ?? "A";
402
+ return `setweight(to_tsvector('${i}', coalesce(${n(t, r)}, '')), '${a}')`;
403
403
  }).join(" || ");
404
- i.push(`ALTER TABLE ${t(e.tableName, n)} ADD COLUMN IF NOT EXISTS ${t(o, n)} tsvector GENERATED ALWAYS AS (${s}) STORED;`), i.push(`CREATE INDEX IF NOT EXISTS ${t(r.name, n)} ON ${t(e.tableName, n)} USING GIN (${t(o, n)});`);
405
- } else if (n === "mysql" || n === "mariadb") {
406
- let a = r.columns.map((e) => t(e, n)).join(", ");
407
- i.push(`CREATE FULLTEXT INDEX ${t(r.name, n)} ON ${t(e.tableName, n)} (${a});`);
408
- } else if (n === "turso") throw Error(`@voltro/sql-turso: full-text index '${r.name}' on '${e.tableName}' is not supported — Turso's MVCC mode has no FTS5 virtual tables. Drop .fullTextIndex(), or use the 'sqlite' / 'postgres' dialect for this table.`);
409
- else n === "sqlite" ? i.push(...ke(e.tableName, r, n)) : A(`[voltro:migrate] full-text index '${r.name}' on '${e.tableName}': ${n} uses a ranked LIKE search at query time (no native FTS catalog required).`);
410
- for (let t of e.appliedIndexes) {
411
- if ((n === "mariadb" || n === "mssql") && t.fields.some((e) => typeof e != "string" && "jsonPath" in e)) {
412
- A(`[voltro:migrate] json-path index '${t.name}' on '${e.tableName}': ${n} cannot index a JSON expression directly — skipping. For an indexed JSON path on ${n}, add a generated column for the path (text().generatedAs(...) / .stored()) and .index([...]) it, then filter on that column instead of jsonField(...).`);
404
+ a.push(`ALTER TABLE ${n(t.tableName, r)} ADD COLUMN IF NOT EXISTS ${n(o, r)} tsvector GENERATED ALWAYS AS (${s}) STORED;`), a.push(`CREATE INDEX IF NOT EXISTS ${n(e.name, r)} ON ${n(t.tableName, r)} USING GIN (${n(o, r)});`);
405
+ } else if (r === "mysql" || r === "mariadb") {
406
+ let i = e.columns.map((e) => n(e, r)).join(", ");
407
+ a.push(`CREATE FULLTEXT INDEX ${n(e.name, r)} ON ${n(t.tableName, r)} (${i});`);
408
+ } else if (r === "turso") throw Error(`@voltro/sql-turso: full-text index '${e.name}' on '${t.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" ? a.push(...ke(t.tableName, e, r)) : A(`[voltro:migrate] full-text index '${e.name}' on '${t.tableName}': ${r} uses a ranked LIKE search at query time (no native FTS catalog required).`);
410
+ for (let e of t.appliedIndexes) {
411
+ if ((r === "mariadb" || r === "mssql") && e.fields.some((e) => typeof e != "string" && "jsonPath" in e)) {
412
+ A(`[voltro:migrate] json-path index '${e.name}' on '${t.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
- if (t.unique && t.where !== void 0 && t.where.length > 0 && (n === "mysql" || n === "mariadb")) throw Error(`@voltro/migrate: uniqueActive index '${t.name}' on '${e.tableName}' cannot be expressed on ${n} — 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 ${n}, or move this table to postgres/sqlite/mssql.`);
416
- let r = "";
417
- t.where !== void 0 && t.where.length > 0 && (n === "mysql" || n === "mariadb" ? A(`[voltro:migrate] partial index '${t.name}' on '${e.tableName}': ${n} does not support WHERE clauses on indexes — emitting a full index`) : r = ` WHERE ${t.where}`);
418
- let s = l(t.name, e.tableName, t.fields, t.kind, t.kindOptions, r, t.unique === !0);
419
- s !== "" && i.push(s), t.fields.every((e) => typeof e == "string") && a.add(o(t.fields));
420
- }
421
- for (let [t, n] of Object.entries(e.fields)) {
422
- if (n.type !== "reference" || n.fkAutoIndex === !1 || a.has(o([t]))) continue;
423
- let r = `${e.tableName}_${t}_idx`;
424
- i.push(l(r, e.tableName, [t])), a.add(o([t]));
425
- }
426
- return i.join("\n");
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 '${t.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
+ let n = "";
417
+ e.where !== void 0 && e.where.length > 0 && (r === "mysql" || r === "mariadb" ? A(`[voltro:migrate] partial index '${e.name}' on '${t.tableName}': ${r} does not support WHERE clauses on indexes — emitting a full index`) : n = ` WHERE ${e.where}`);
418
+ let i = u(e.name, t.tableName, e.fields, e.kind, e.kindOptions, n, e.unique === !0);
419
+ i !== "" && a.push(i), e.fields.every((e) => typeof e == "string") && o.add(s(e.fields));
420
+ }
421
+ for (let [e, n] of Object.entries(t.fields)) {
422
+ if (n.type !== "reference" || n.fkAutoIndex === !1 || o.has(s([e]))) continue;
423
+ let r = `${t.tableName}_${e}_idx`;
424
+ a.push(u(r, t.tableName, [e])), o.add(s([e]));
425
+ }
426
+ return a.join("\n");
427
427
  }, je = (e, t, n = O) => {
428
428
  if (t !== "postgres") return [];
429
429
  let r = e.filter((e) => e.isReactive !== !1);
@@ -480,7 +480,7 @@ $$ LANGUAGE plpgsql;
480
480
  for (let n of e.stale) r.push(`DROP TRIGGER IF EXISTS ${_e(n, t)} ON "${n}"`), r.push(`ALTER TABLE "${n}" REPLICA IDENTITY DEFAULT`);
481
481
  return r;
482
482
  }, Ie = (e) => e.some((e) => Object.values(e.fields).some((e) => e.type === "vector")), Le = (e) => e.some((e) => Object.values(e.fields).some((e) => e.spatial !== void 0)), Re = (e) => {
483
- let t = new Map(e.map((e) => [e.tableName, e])), n = ne(e.map((e) => e.tableName), (e) => {
483
+ let t = new Map(e.map((e) => [e.tableName, e])), n = te(e.map((e) => e.tableName), (e) => {
484
484
  let n = t.get(e);
485
485
  return n ? Object.entries(n.fields).flatMap(([e, n]) => {
486
486
  if (n.type !== "reference" || !n.references) return [];
@@ -491,7 +491,7 @@ $$ LANGUAGE plpgsql;
491
491
  }] : [];
492
492
  }) : [];
493
493
  }), r = [];
494
- for (let t of e) for (let [e, i] of Object.entries(t.fields)) i.type !== "reference" || !i.references || n.has(w(t.tableName, e)) && r.push({
494
+ for (let t of e) for (let [e, i] of Object.entries(t.fields)) i.type !== "reference" || !i.references || n.has(T(t.tableName, e)) && r.push({
495
495
  table: t.tableName,
496
496
  column: e,
497
497
  targetTable: i.references().tableName,
@@ -502,7 +502,7 @@ $$ LANGUAGE plpgsql;
502
502
  if (!(i.has(e.tableName) || a.has(e.tableName))) {
503
503
  a.add(e.tableName);
504
504
  for (let [r, i] of Object.entries(e.fields)) {
505
- if (i.type !== "reference" || !i.references || n.has(w(e.tableName, r))) continue;
505
+ if (i.type !== "reference" || !i.references || n.has(T(e.tableName, r))) continue;
506
506
  let a = i.references();
507
507
  if (a.tableName === e.tableName) continue;
508
508
  let o = t.get(a.tableName);
@@ -516,9 +516,9 @@ $$ LANGUAGE plpgsql;
516
516
  sorted: o,
517
517
  cyclic: r
518
518
  };
519
- }, ze = (e, n, r = null) => {
520
- let i = (e) => r ? `${t(r, n)}.${t(e, n)}` : t(e, n), a = `${e.table}_${e.column}_fkey`, o = Se(e.onDelete, n), s = Se(e.onUpdate, n), c = ` ON DELETE ${o}${s === "NO ACTION" ? "" : ` ON UPDATE ${s}`}`, l = (r) => `ADD CONSTRAINT ${t(a, n)} FOREIGN KEY ${r ? "IF NOT EXISTS " : ""}(${t(e.column, n)}) REFERENCES ${i(e.targetTable)} (${t("id", n)})${c}`;
521
- switch (n) {
519
+ }, ze = (e, t, r = null) => {
520
+ let i = (e) => r ? `${n(r, t)}.${n(e, t)}` : n(e, t), a = `${e.table}_${e.column}_fkey`, o = Se(e.onDelete, t), s = Se(e.onUpdate, t), c = ` ON DELETE ${o}${s === "NO ACTION" ? "" : ` ON UPDATE ${s}`}`, l = (r) => `ADD CONSTRAINT ${n(a, t)} FOREIGN KEY ${r ? "IF NOT EXISTS " : ""}(${n(e.column, t)}) REFERENCES ${i(e.targetTable)} (${n("id", t)})${c}`;
521
+ switch (t) {
522
522
  case "postgres": return [
523
523
  "DO $$ BEGIN",
524
524
  " IF NOT EXISTS (SELECT 1 FROM pg_constraint",
@@ -531,12 +531,12 @@ $$ LANGUAGE plpgsql;
531
531
  case "mariadb": return `ALTER TABLE ${i(e.table)} ${l(!0)};`;
532
532
  default: return `ALTER TABLE ${i(e.table)} ${l(!1)};`;
533
533
  }
534
- }, Be = (t, n) => {
534
+ }, Be = (e, n) => {
535
535
  let r = /* @__PURE__ */ new Map();
536
- if (e(n)) return r;
537
- for (let e of t) {
538
- let t = r.get(e.table) ?? /* @__PURE__ */ new Set();
539
- t.add(e.column), r.set(e.table, t);
536
+ if (t(n)) return r;
537
+ for (let t of e) {
538
+ let e = r.get(t.table) ?? /* @__PURE__ */ new Set();
539
+ e.add(t.column), r.set(t.table, e);
540
540
  }
541
541
  return r;
542
542
  }, Ve = (e, t) => {
@@ -560,7 +560,7 @@ $$ LANGUAGE plpgsql;
560
560
  let n = /* @__PURE__ */ new Set();
561
561
  for (let t of e) for (let e of Object.values(t.fields)) e.type === "enum" && e.enumName && n.add(e.enumName);
562
562
  let r = [];
563
- for (let e of n) for (let { from: t, to: n } of a(e)) {
563
+ for (let e of n) for (let { from: t, to: n } of l(e)) {
564
564
  let i = e.replace(/'/g, "''"), a = t.replace(/'/g, "''"), o = n.replace(/'/g, "''");
565
565
  r.push(`DO \$\$
566
566
  DECLARE
@@ -571,30 +571,30 @@ BEGIN
571
571
  return r.join("\n\n");
572
572
  }, Ue = (e) => {
573
573
  let t = [], n = [];
574
- for (let i of e) r(i) ? n.push(i) : t.push(i);
574
+ for (let r of e) i(r) ? n.push(r) : t.push(r);
575
575
  return {
576
576
  tables: t,
577
577
  views: n
578
578
  };
579
- }, We = (t, n, r = O) => {
580
- let { tables: a, views: o } = Ue(t), { sorted: s, cyclic: c } = Re(a.map((e) => te(e, n))), l = Be(c, n), u = [];
579
+ }, We = (e, n, r = O) => {
580
+ let { tables: i, views: o } = Ue(e), { sorted: s, cyclic: c } = Re(i.map((e) => w(e, n))), l = Be(c, n), u = [];
581
581
  n === "postgres" && Ie(s) && u.push("CREATE EXTENSION IF NOT EXISTS vector;"), n === "postgres" && Le(s) && u.push("CREATE EXTENSION IF NOT EXISTS postgis;");
582
582
  let d = He(s, n);
583
583
  d && u.push(d);
584
584
  let f = Ve(s, n);
585
585
  f && u.push(f);
586
586
  for (let e of s) u.push(Oe(e, n, null, l.get(e.tableName)));
587
- if (!e(n)) for (let e of c) u.push(ze(e, n));
587
+ if (!t(n)) for (let e of c) u.push(ze(e, n));
588
588
  for (let e of s) {
589
589
  let t = Ae(e, n);
590
590
  t && u.push(t);
591
591
  }
592
592
  u.push(...je(s, n, r));
593
- for (let e of o) u.push(i(e, n));
593
+ for (let e of o) u.push(a(e, n));
594
594
  return u.join("\n\n") + "\n";
595
- }, Ge = (e, n, r) => {
596
- let i = t(e, n);
597
- switch (n) {
595
+ }, Ge = (e, t, r) => {
596
+ let i = n(e, t);
597
+ switch (t) {
598
598
  case "postgres": return `CREATE SCHEMA IF NOT EXISTS ${i};`;
599
599
  case "mysql":
600
600
  case "mariadb": return `CREATE DATABASE IF NOT EXISTS ${i};`;
@@ -602,13 +602,13 @@ BEGIN
602
602
  case "turso":
603
603
  case "sqlite": return `ATTACH DATABASE '${(r ?? `${e}.db`).replace(/'/g, "''")}' AS ${i};`;
604
604
  }
605
- }, Ke = (n, r, i, a) => {
606
- let o = Ge(i, r, a), s = t(i, r);
607
- if (r === "postgres") return `${o}\n\nSET search_path TO ${s};\n\n${We(n, r)}`;
608
- if (r === "mysql" || r === "mariadb") return `${o}\n\nUSE ${s};\n\n${We(n, r)}`;
609
- let { sorted: c, cyclic: l } = Re(n), u = Be(l, r), d = [o];
605
+ }, Ke = (e, r, i, a) => {
606
+ let o = Ge(i, r, a), s = n(i, r);
607
+ if (r === "postgres") return `${o}\n\nSET search_path TO ${s};\n\n${We(e, r)}`;
608
+ if (r === "mysql" || r === "mariadb") return `${o}\n\nUSE ${s};\n\n${We(e, r)}`;
609
+ let { sorted: c, cyclic: l } = Re(e), u = Be(l, r), d = [o];
610
610
  for (let e of c) d.push(Oe(e, r, i, u.get(e.tableName)));
611
- if (!e(r)) for (let e of l) d.push(ze(e, r, i));
611
+ if (!t(r)) for (let e of l) d.push(ze(e, r, i));
612
612
  for (let e of c) {
613
613
  let t = Ae(e, r, i);
614
614
  t && d.push(t);
@@ -624,7 +624,7 @@ BEGIN
624
624
  return o.push(...je(r, t, n)), o.join("\n\n") + "\n";
625
625
  }, Je = (e, t = "postgres", n = O) => p.gen(function* () {
626
626
  let r = yield* h.SqlClient;
627
- yield* D(r, Ze(r, We(e, t, n), t)).pipe(p.orDie);
627
+ yield* ge(r, Ze(r, We(e, t, n), t)).pipe(p.orDie);
628
628
  }), Ye = (e, t) => {
629
629
  let n = t.cause ?? {};
630
630
  return (n.errno === 1061 || n.code === "ER_DUP_KEYNAME") && /^\s*CREATE\s+(UNIQUE\s+|FULLTEXT\s+)?INDEX\b/i.test(e);
@@ -652,13 +652,13 @@ BEGIN
652
652
  await p.runPromise(Je(e, n).pipe(p.provide(t)));
653
653
  }, et = (e, t, n = "postgres") => p.gen(function* () {
654
654
  let r = Ke(e, n, t), i = yield* h.SqlClient;
655
- yield* D(i, Ze(i, r, n)).pipe(p.orDie);
655
+ yield* ge(i, Ze(i, r, n)).pipe(p.orDie);
656
656
  }), tt = async (e, t, n, r = "postgres") => {
657
657
  await p.runPromise(et(e, t, r).pipe(p.provide(n)));
658
658
  }, nt = async (e, t, n = "postgres") => {
659
659
  await p.runPromise(p.gen(function* () {
660
660
  let t = qe(e, n), r = yield* h.SqlClient;
661
- yield* D(r, Ze(r, t, n)).pipe(p.orDie);
661
+ yield* ge(r, Ze(r, t, n)).pipe(p.orDie);
662
662
  }).pipe(p.provide(t)));
663
663
  }, rt = (e) => {
664
664
  if (e == null) return e;
@@ -760,7 +760,7 @@ BEGIN
760
760
  let i = n;
761
761
  if (i.dropped || !i.references || i.fkAutoIndex === !1 || s.has(t)) continue;
762
762
  let a = `${e.tableName}_${t}_idx`;
763
- l(e.tableName, a, !0, [t]), r({
763
+ f(e.tableName, a, !0, [t]), r({
764
764
  name: a,
765
765
  table: e.tableName,
766
766
  columns: [t],
@@ -794,7 +794,7 @@ BEGIN
794
794
  t.set(e.name, n.name);
795
795
  }
796
796
  }, I = (e, t) => {
797
- let n = e.map((e) => ut(te(e, t)));
797
+ let n = e.map((e) => ut(w(e, t)));
798
798
  return dt(n), { tables: n };
799
799
  }, ft = (e, t, n = O) => p.gen(function* () {
800
800
  let r = t.filter((e) => !e.tableName.startsWith("_voltro_"));
@@ -879,6 +879,10 @@ BEGIN
879
879
  if (o) try {
880
880
  return L(JSON.parse(o[1]));
881
881
  } catch {}
882
+ let s = /^convert\(\s*(?:_\w+\s*)?\\?'(.*?)\\?'\s+using\s+[\w]+\s*\)$/i.exec(a);
883
+ if (s) try {
884
+ return L(JSON.parse(s[1]));
885
+ } catch {}
882
886
  if (a.startsWith("{") || a.startsWith("[")) try {
883
887
  return L(JSON.parse(a));
884
888
  } catch {}
@@ -910,7 +914,7 @@ BEGIN
910
914
  } catch {
911
915
  return;
912
916
  }
913
- }, Ct = (t, n, r) => r === void 0 || e(r) ? !0 : t.type !== "text" || n.type !== "text" || St(t, r) === n.maxLength, wt = (e, t, n) => e.type === t.type && e.nullable === t.nullable && e.unique === t.unique && yt(e, t) && Ct(e, t, n) && JSON.stringify(bt(e.references)) === JSON.stringify(bt(t.references)) && xt(e.oneOf, t.oneOf), Tt = (e, t) => t.oneOf && t.oneOf.length > 0 ? R({
917
+ }, Ct = (e, n, r) => r === void 0 || t(r) ? !0 : e.type !== "text" || n.type !== "text" || St(e, r) === n.maxLength, wt = (e, t, n) => e.type === t.type && e.nullable === t.nullable && e.unique === t.unique && yt(e, t) && Ct(e, t, n) && JSON.stringify(bt(e.references)) === JSON.stringify(bt(t.references)) && xt(e.oneOf, t.oneOf), Tt = (e, t) => t.oneOf && t.oneOf.length > 0 ? R({
914
918
  kind: "add-check",
915
919
  table: e,
916
920
  column: t.name,
@@ -1006,99 +1010,99 @@ BEGIN
1006
1010
  case "mssql": return e === "json" ? "text" : e;
1007
1011
  default: return e;
1008
1012
  }
1009
- }, Lt = (t, n, r, i, a, o) => {
1013
+ }, Lt = (e, n, r, i, a, o) => {
1010
1014
  let s = [];
1011
1015
  if (n.nullable !== r.nullable) {
1012
- let e = {
1016
+ let t = {
1013
1017
  kind: "alter-column-nullability",
1014
- table: t,
1018
+ table: e,
1015
1019
  column: n.name,
1016
1020
  toNullable: n.nullable
1017
1021
  };
1018
- s.push(n.nullable ? R(e, "safe", `loosen ${t}.${n.name} to nullable`) : R(e, "needs-backfill", `tighten ${t}.${n.name} to NOT NULL — existing rows must already be non-null`));
1022
+ s.push(n.nullable ? R(t, "safe", `loosen ${e}.${n.name} to nullable`) : R(t, "needs-backfill", `tighten ${e}.${n.name} to NOT NULL — existing rows must already be non-null`));
1019
1023
  }
1020
1024
  if (n.unique !== r.unique) if (n.unique) {
1021
- let e = {
1025
+ let t = {
1022
1026
  kind: "add-unique",
1023
- table: t,
1027
+ table: e,
1024
1028
  column: n.name
1025
1029
  }, r = (a ?? 0) >= o;
1026
- s.push(r ? R(e, "online-required", `online unique build on ${a} rows — CONCURRENTLY / INPLACE / WITH(ONLINE=ON) depending on dialect`) : R(e, "safe", `add unique constraint on ${t}.${n.name} — existing rows must already be distinct (else the DB rejects at migrate)`));
1030
+ s.push(r ? R(t, "online-required", `online unique build on ${a} rows — CONCURRENTLY / INPLACE / WITH(ONLINE=ON) depending on dialect`) : R(t, "safe", `add unique constraint on ${e}.${n.name} — existing rows must already be distinct (else the DB rejects at migrate)`));
1027
1031
  } else s.push(R({
1028
1032
  kind: "drop-unique",
1029
- table: t,
1033
+ table: e,
1030
1034
  column: n.name
1031
- }, "safe", `drop unique constraint on ${t}.${n.name} — constraint is derived metadata, no data loss`));
1035
+ }, "safe", `drop unique constraint on ${e}.${n.name} — constraint is derived metadata, no data loss`));
1032
1036
  if (It(n.type, i) !== It(r.type, i)) {
1033
- let e = n.narrowedFrom;
1034
- if (e && e.from === r.type) {
1037
+ let t = n.narrowedFrom;
1038
+ if (t && t.from === r.type) {
1035
1039
  let i = {
1036
1040
  kind: "alter-column-type",
1037
- table: t,
1041
+ table: e,
1038
1042
  column: n.name,
1039
1043
  from: r.type,
1040
1044
  to: n.type,
1041
- ...e.using === void 0 ? {} : { using: e.using }
1045
+ ...t.using === void 0 ? {} : { using: t.using }
1042
1046
  };
1043
- s.push(R(i, "needs-backfill", `type change ${r.type} → ${n.type} on ${t}.${n.name} — narrowedFrom('${e.from}') declared` + (e.using ? ` with USING ${e.using}` : " (implicit cast)")));
1047
+ s.push(R(i, "needs-backfill", `type change ${r.type} → ${n.type} on ${e}.${n.name} — narrowedFrom('${t.from}') declared` + (t.using ? ` with USING ${t.using}` : " (implicit cast)")));
1044
1048
  } else {
1045
- let e = {
1049
+ let t = {
1046
1050
  kind: "alter-column-type",
1047
- table: t,
1051
+ table: e,
1048
1052
  column: n.name,
1049
1053
  from: r.type,
1050
1054
  to: n.type
1051
1055
  };
1052
- s.push(R(e, "lossy", `type change ${r.type} → ${n.type} on ${t}.${n.name} may not be value-preserving`, { fix: `acknowledge it on the column: \`.narrowedFrom('${r.type}', { using: '${n.name}::${n.type}' })\` (drop \`using\` if the cast is implicit), or use a file-based migration` }));
1056
+ s.push(R(t, "lossy", `type change ${r.type} → ${n.type} on ${e}.${n.name} may not be value-preserving`, { fix: `acknowledge it on the column: \`.narrowedFrom('${r.type}', { using: '${n.name}::${n.type}' })\` (drop \`using\` if the cast is implicit), or use a file-based migration` }));
1053
1057
  }
1054
1058
  }
1055
- if (n.type === "text" && r.type === "text" && !e(i ?? "postgres") && n.maxLength !== r.maxLength) {
1056
- let e = n.maxLength === void 0 || r.maxLength !== void 0 && n.maxLength > r.maxLength, i = r.maxLength === void 0 ? "unbounded" : `varchar(${r.maxLength})`, a = n.maxLength === void 0 ? "unbounded" : `varchar(${n.maxLength})`;
1059
+ if (n.type === "text" && r.type === "text" && !t(i ?? "postgres") && n.maxLength !== r.maxLength) {
1060
+ let t = n.maxLength === void 0 || r.maxLength !== void 0 && n.maxLength > r.maxLength, i = r.maxLength === void 0 ? "unbounded" : `varchar(${r.maxLength})`, a = n.maxLength === void 0 ? "unbounded" : `varchar(${n.maxLength})`;
1057
1061
  s.push(R({
1058
1062
  kind: "alter-column-type",
1059
- table: t,
1063
+ table: e,
1060
1064
  column: n.name,
1061
1065
  from: "text",
1062
1066
  to: "text"
1063
- }, e ? "safe" : "needs-backfill", e ? `text length ${i} → ${a} on ${t}.${n.name} — widening, no data can be lost` : `text length ${i} → ${a} on ${t}.${n.name} — NARROWING; the ALTER fails if any existing value is longer than ${String(n.maxLength)}. Check first: SELECT COUNT(*) FROM ${t} WHERE LENGTH(${n.name}) > ${String(n.maxLength)}`));
1067
+ }, t ? "safe" : "needs-backfill", t ? `text length ${i} → ${a} on ${e}.${n.name} — widening, no data can be lost` : `text length ${i} → ${a} on ${e}.${n.name} — NARROWING; the ALTER fails if any existing value is longer than ${String(n.maxLength)}. Check first: SELECT COUNT(*) FROM ${e} WHERE LENGTH(${n.name}) > ${String(n.maxLength)}`));
1064
1068
  }
1065
1069
  if (!yt(n, r)) {
1066
- let e = {
1070
+ let t = {
1067
1071
  kind: "alter-column-default",
1068
- table: t,
1072
+ table: e,
1069
1073
  column: n.name,
1070
1074
  hasDefault: n.hasDefault,
1071
1075
  ...n.defaultValue === void 0 ? {} : { defaultValue: n.defaultValue }
1072
1076
  };
1073
- s.push(R(e, "safe", `default change on ${t}.${n.name} affects only future inserts`));
1077
+ s.push(R(t, "safe", `default change on ${e}.${n.name} affects only future inserts`));
1074
1078
  }
1075
1079
  if (!xt(n.oneOf, r.oneOf)) {
1076
1080
  r.oneOf && r.oneOf.length > 0 && s.push(R({
1077
1081
  kind: "drop-check",
1078
- table: t,
1082
+ table: e,
1079
1083
  column: n.name
1080
- }, "safe", `drop stale enum CHECK on ${t}.${n.name}`));
1081
- let e = Tt(t, n);
1082
- e && s.push(e);
1084
+ }, "safe", `drop stale enum CHECK on ${e}.${n.name}`));
1085
+ let t = Tt(e, n);
1086
+ t && s.push(t);
1083
1087
  }
1084
1088
  if (JSON.stringify(bt(n.references)) !== JSON.stringify(bt(r.references)) && (r.references && s.push(R({
1085
1089
  kind: "drop-foreign-key",
1086
- table: t,
1090
+ table: e,
1087
1091
  column: n.name
1088
- }, "safe", `drop FK on ${t}.${n.name} (→ ${r.references.table})`)), n.references)) {
1089
- let e = n.references.table, r = n.references.orphanPolicy ?? "fail", i = {
1092
+ }, "safe", `drop FK on ${e}.${n.name} (→ ${r.references.table})`)), n.references)) {
1093
+ let t = n.references.table, r = n.references.orphanPolicy ?? "fail", i = {
1090
1094
  kind: "add-foreign-key",
1091
- table: t,
1095
+ table: e,
1092
1096
  column: n.name,
1093
- targetTable: e,
1097
+ targetTable: t,
1094
1098
  targetColumn: n.references.column,
1095
1099
  ...n.references.onDelete ? { onDelete: n.references.onDelete } : {},
1096
1100
  ...n.references.onUpdate ? { onUpdate: n.references.onUpdate } : {}
1097
1101
  };
1098
- r === "null" && !n.nullable ? s.push(R(i, "lossy", `add FK ${t}.${n.name} → ${e}: orphanPolicy 'null' needs a nullable column (the NULL-out would violate NOT NULL)`, { fix: `make ${n.name} \`.nullable()\`, OR use \`orphanPolicy: 'delete'\`, OR clean the orphans and drop the policy` })) : r === "null" || r === "delete" ? s.push(R({
1102
+ r === "null" && !n.nullable ? s.push(R(i, "lossy", `add FK ${e}.${n.name} → ${t}: orphanPolicy 'null' needs a nullable column (the NULL-out would violate NOT NULL)`, { fix: `make ${n.name} \`.nullable()\`, OR use \`orphanPolicy: 'delete'\`, OR clean the orphans and drop the policy` })) : r === "null" || r === "delete" ? s.push(R({
1099
1103
  ...i,
1100
1104
  orphanPolicy: r
1101
- }, "lossy", r === "delete" ? `add FK ${t}.${n.name} → ${e}: orphanPolicy 'delete' first DELETES rows whose ${n.name} points at a missing ${e}` : `add FK ${t}.${n.name} → ${e}: orphanPolicy 'null' first NULLs ${n.name} where it points at a missing ${e}`)) : s.push(R(i, "needs-backfill", `add FK ${t}.${n.name} → ${e} — existing rows must already reference a valid ${e} (else set orphanPolicy:'null'/'delete')`));
1105
+ }, "lossy", r === "delete" ? `add FK ${e}.${n.name} → ${t}: orphanPolicy 'delete' first DELETES rows whose ${n.name} points at a missing ${t}` : `add FK ${e}.${n.name} → ${t}: orphanPolicy 'null' first NULLs ${n.name} where it points at a missing ${t}`)) : s.push(R(i, "needs-backfill", `add FK ${e}.${n.name} → ${t} — existing rows must already reference a valid ${t} (else set orphanPolicy:'null'/'delete')`));
1102
1106
  }
1103
1107
  return s;
1104
1108
  }, Rt = (e, t, n) => {
@@ -1265,16 +1269,16 @@ BEGIN
1265
1269
  }
1266
1270
  }
1267
1271
  let c = new Set(e.ignoreTables ?? []);
1268
- for (let t of e.live.tables) n.has(t.name) || o.claimedOldNames.has(t.name) || s(t.name) || d(t.name) || c.has(t.name) || a.push(Mt(t.name));
1272
+ for (let t of e.live.tables) n.has(t.name) || o.claimedOldNames.has(t.name) || s(t.name) || u(t.name) || c.has(t.name) || a.push(Mt(t.name));
1269
1273
  for (let s of t.tables) {
1270
1274
  let t = o.renamedInto.get(s.name), c = r.get(s.name) ?? (t === void 0 ? void 0 : r.get(t));
1271
1275
  if (!c) continue;
1272
1276
  let l = Wt(c, t, s.name, e.dialect);
1273
1277
  a.push(...l.ops);
1274
- let u = l.live, f = n.get(s.name), p = Dt(s, u, e.dialect), m = Ot(s, u), h = Rt(f.table, f.columnDefs, p);
1278
+ let d = l.live, f = n.get(s.name), p = Dt(s, d, e.dialect), m = Ot(s, d), h = Rt(f.table, f.columnDefs, p);
1275
1279
  a.push(...h.ops);
1276
1280
  for (let e of p.removed) {
1277
- if (h.consumedRemovedNames.has(e.name) || d(e.name)) continue;
1281
+ if (h.consumedRemovedNames.has(e.name) || u(e.name)) continue;
1278
1282
  let t = f.columnDefs[e.name];
1279
1283
  a.push(At(s.name, e, t));
1280
1284
  }
@@ -1285,20 +1289,20 @@ BEGIN
1285
1289
  let n = Tt(s.name, e);
1286
1290
  n && a.push(n);
1287
1291
  }
1288
- let g = new Map(h.ops.flatMap((e) => e.op.kind === "rename-column" ? [[e.op.from, e.op.to]] : [])), _ = Ht(s.name, m, g, new Set(u.indexes.map((e) => e.name)), e.dialect);
1292
+ let g = new Map(h.ops.flatMap((e) => e.op.kind === "rename-column" ? [[e.op.from, e.op.to]] : [])), _ = Ht(s.name, m, g, new Set(d.indexes.map((e) => e.name)), e.dialect);
1289
1293
  a.push(..._.ops);
1290
- for (let e of m.added) _.consumedAddedNames.has(e.name) || a.push(Pt(s.name, e, u.rowCount, i));
1294
+ for (let e of m.added) _.consumedAddedNames.has(e.name) || a.push(Pt(s.name, e, d.rowCount, i));
1291
1295
  for (let e of m.removed) _.consumedRemovedNames.has(e.name) || a.push(Ft(s.name, e));
1292
- for (let { declared: t, live: n } of p.changed) a.push(...Lt(s.name, t, n, e.dialect, u.rowCount, i));
1296
+ for (let { declared: t, live: n } of p.changed) a.push(...Lt(s.name, t, n, e.dialect, d.rowCount, i));
1293
1297
  }
1294
- let l = new Set(a.flatMap((e) => e.op.kind === "create-table" ? [e.op.table] : [])), u = new Map(t.tables.map((e) => [e.name, e])), f = (e) => {
1295
- let t = u.get(e);
1298
+ let l = new Set(a.flatMap((e) => e.op.kind === "create-table" ? [e.op.table] : [])), d = new Map(t.tables.map((e) => [e.name, e])), f = (e) => {
1299
+ let t = d.get(e);
1296
1300
  return t ? t.columns.flatMap((e) => e.references && l.has(e.references.table) ? [{
1297
1301
  column: e.name,
1298
1302
  target: e.references.table
1299
1303
  }] : []) : [];
1300
- }, p = ne([...l], f), m = [];
1301
- for (let e of t.tables) if (l.has(e.name)) for (let t of e.columns) !t.references || !p.has(w(e.name, t.name)) || m.push(R({
1304
+ }, p = te([...l], f), m = [];
1305
+ for (let e of t.tables) if (l.has(e.name)) for (let t of e.columns) !t.references || !p.has(T(e.name, t.name)) || m.push(R({
1302
1306
  kind: "add-foreign-key",
1303
1307
  table: e.name,
1304
1308
  column: t.name,
@@ -1313,8 +1317,8 @@ BEGIN
1313
1317
  let n = a[t];
1314
1318
  if (n.op.kind !== "create-table") continue;
1315
1319
  let r = n.op;
1316
- if (!r.columns.some((e) => p.has(w(r.table, e.name)))) continue;
1317
- let i = r.columns.map((t) => p.has(w(r.table, t.name)) ? e(t) : t);
1320
+ if (!r.columns.some((e) => p.has(T(r.table, e.name)))) continue;
1321
+ let i = r.columns.map((t) => p.has(T(r.table, t.name)) ? e(t) : t);
1318
1322
  a[t] = {
1319
1323
  ...n,
1320
1324
  op: {
@@ -1334,7 +1338,7 @@ BEGIN
1334
1338
  let i = new Set(t).add(e), a = 0;
1335
1339
  for (let t of r.columns) {
1336
1340
  let n = t.references?.table;
1337
- n && n !== e && !p.has(w(e, t.name)) && (a = Math.max(a, _(n, i) + 1));
1341
+ n && n !== e && !p.has(T(e, t.name)) && (a = Math.max(a, _(n, i) + 1));
1338
1342
  }
1339
1343
  return g.set(e, a), a;
1340
1344
  }, v = (e) => e === "rename-table" ? -1 : e === "create-table" ? 0 : e === "drop-table" ? 2 : 1, y = (e) => {
@@ -1576,7 +1580,7 @@ BEGIN
1576
1580
  let n = t.get(e.index_name);
1577
1581
  n || (n = [], t.set(e.index_name, n)), n.push(e);
1578
1582
  }
1579
- let te = [];
1583
+ let w = [];
1580
1584
  for (let e of c) {
1581
1585
  let t = /* @__PURE__ */ new Set(), n = (v.get(e.table_name) ?? []).filter((e) => t.has(e.column_name) ? !1 : (t.add(e.column_name), !0)), r = y.get(e.table_name) ?? /* @__PURE__ */ new Set(), i = b.get(e.table_name) ?? /* @__PURE__ */ new Set(), a = S.get(e.table_name) ?? [], o = new Map(a.map((e) => [e.source_column, e])), s = new Set(n.filter((e) => e.udt_name === "tsvector").map((e) => e.column_name)), c = n.filter((e) => !s.has(e.column_name)).map((t) => {
1582
1586
  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" : Jt(t.data_type, t.udt_name), c = a ? {
@@ -1620,14 +1624,14 @@ BEGIN
1620
1624
  unique: !0
1621
1625
  });
1622
1626
  let d = Number(e.row_count ?? 0);
1623
- te.push({
1627
+ w.push({
1624
1628
  name: e.table_name,
1625
1629
  columns: c,
1626
1630
  indexes: l,
1627
1631
  ...d > 0 ? { rowCount: d } : {}
1628
1632
  });
1629
1633
  }
1630
- return { tables: te };
1634
+ return { tables: w };
1631
1635
  });
1632
1636
  return (t > 0 ? e.withTransaction(n) : n).pipe(p.catchAll((e) => {
1633
1637
  let n = `${String(e)} ${String(e.cause ?? "")}`.toLowerCase();
@@ -2044,7 +2048,7 @@ BEGIN
2044
2048
  r ? null : "NOT NULL",
2045
2049
  i
2046
2050
  ].filter(Boolean).join(" ");
2047
- }, wn = (e, t) => e == null ? null : Array.isArray(e) ? Tn(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" ? M(e, "mysql") : null, Tn = (e, t, n) => xe(e, t ?? { type: "json" }, n), En = (e, t) => e == null ? null : Array.isArray(e) ? Tn(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" ? M(e, "postgres") : null, J = (e, t) => {
2051
+ }, wn = (e, t) => e == null ? null : Array.isArray(e) ? Tn(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" ? M(e, "mariadb") : null, Tn = (e, t, n) => xe(e, t ?? { type: "json" }, n), En = (e, t) => e == null ? null : Array.isArray(e) ? Tn(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" ? M(e, "postgres") : null, J = (e, t) => {
2048
2052
  if (!e.generatedAs) return null;
2049
2053
  let { expr: n, stored: r } = e.generatedAs;
2050
2054
  return t === "postgres" ? `GENERATED ALWAYS AS (${n}) STORED` : t === "mssql" ? `AS (${n})${r ? " PERSISTED" : ""}` : `GENERATED ALWAYS AS (${n}) ${r ? "STORED" : "VIRTUAL"}`;
@@ -2529,7 +2533,7 @@ BEGIN
2529
2533
  }), Tr = (e, t, n) => p.gen(function* () {
2530
2534
  let r = t.operations.filter((e) => e.blocked);
2531
2535
  if (r.length > 0) return yield* p.die(/* @__PURE__ */ Error(`applyPlan: refusing to execute — ${r.length} blocked operations. Run \`voltro db plan\` to see the fixes.`));
2532
- yield* T(e);
2536
+ yield* E(e);
2533
2537
  let i = Date.now(), a = [];
2534
2538
  try {
2535
2539
  let r = yield* e.onDialectOrElse({
@@ -2543,7 +2547,7 @@ BEGIN
2543
2547
  })));
2544
2548
  for (let t of o) a.push(yield* wr(e, t, n));
2545
2549
  } finally {
2546
- yield* E(e).pipe(p.orDie);
2550
+ yield* D(e).pipe(p.orDie);
2547
2551
  }
2548
2552
  let o = yield* n.replan(e);
2549
2553
  if (o.operations.length > 0) {
@@ -2736,14 +2740,14 @@ BEGIN
2736
2740
  });
2737
2741
  }, Ur = async (e) => {
2738
2742
  let t = [];
2739
- for (let r of e) {
2740
- let e = (await import(y(r).href)).default;
2741
- if (!n(e)) {
2742
- process.stderr.write(`[voltro:migrate] ${r} has no default-exported \`migration(...)\` — skipped\n`);
2743
+ for (let n of e) {
2744
+ let e = (await import(y(n).href)).default;
2745
+ if (!r(e)) {
2746
+ process.stderr.write(`[voltro:migrate] ${n} has no default-exported \`migration(...)\` — skipped\n`);
2743
2747
  continue;
2744
2748
  }
2745
2749
  t.push({
2746
- file: r,
2750
+ file: n,
2747
2751
  migration: e
2748
2752
  });
2749
2753
  }
@@ -2823,7 +2827,7 @@ BEGIN
2823
2827
  applied: [],
2824
2828
  skipped: r
2825
2829
  };
2826
- yield* T(e);
2830
+ yield* E(e);
2827
2831
  let i = [];
2828
2832
  try {
2829
2833
  for (let r of n) {
@@ -2843,7 +2847,7 @@ BEGIN
2843
2847
  }));
2844
2848
  }
2845
2849
  } finally {
2846
- yield* E(e).pipe(p.orDie);
2850
+ yield* D(e).pipe(p.orDie);
2847
2851
  }
2848
2852
  return {
2849
2853
  applied: i,
@@ -2864,7 +2868,7 @@ BEGIN
2864
2868
  catch: (e) => e
2865
2869
  })).find((e) => e.migration.id === t.id);
2866
2870
  if (!r) return yield* p.fail(/* @__PURE__ */ Error(`rollback: file for migration ${t.id} not found on disk under ${t.projectRoot}/migrations/`));
2867
- yield* T(e);
2871
+ yield* E(e);
2868
2872
  let i = Date.now();
2869
2873
  try {
2870
2874
  let n = {
@@ -2891,7 +2895,7 @@ BEGIN
2891
2895
  durationMs: o
2892
2896
  };
2893
2897
  } finally {
2894
- yield* E(e).pipe(p.orDie);
2898
+ yield* D(e).pipe(p.orDie);
2895
2899
  }
2896
2900
  }), Qr = (e) => p.gen(function* () {
2897
2901
  let t = yield* h.SqlClient, n = yield* t`
@@ -3030,4 +3034,4 @@ BEGIN
3030
3034
  values: [...t]
3031
3035
  }), ii = (e) => typeof e == "object" && !!e && e._tag === "RawSqlFragment";
3032
3036
  //#endregion
3033
- export { O as DEFAULT_CDC_CHANNEL, o as FILE_MIGRATION_PATTERN, Gr as FileMigrationLedgerError, k as REACTIVE_TRIGGER_PREFIX, re as VOLTRO_MIGRATION_LOCK_KEY, T as acquireMigrationLock, et as applyNamespacedSchema, Tr as applyPlan, Je as applySchema, ni as assessRollingDeployGate, $t as chunkTables, ei as classifyRollingDeploySafety, I as declaredSnapshot, xe as defaultArrayClause, be as defaultClause, M as defaultJsonClause, Br as describeOutcome, Pr as destructiveScope, ft as detectReactiveTriggerDrift, gn as emitDropColumnDdl, _n as emitDropColumnDdlMysql, qe as emitFrameworkBootstrapSql, Ge as emitNamespaceProvisionDdl, Ke as emitNamespacedSchemaSql, We as emitSchemaSql, P as fingerprintSchema, pt as formatReactiveTriggerDrift, Nr as ignoreTablesFromEnv, U as introspectSchema, n as isFileMigration, ii as isRawSqlFragment, Jt as mapPgType, c as migration, N as numericIdSql, qt as parseEnumCheck, Jr as pendingFileMigrationIds, Kt as planMigrations, tt as provisionTenantNamespace, Fe as reactiveTriggerRepairSql, E as releaseMigrationLock, Mn as renderColumnMysql, Dn as renderColumnPg, Zr as rollbackFileBasedMigration, ti as rollingDeployUnsafeOps, Yr as runFileBasedMigrations, nt as runFrameworkBootstrap, $e as runMigrate, zr as runPlannedMigrations, F as shortFingerprint, ct as snapshotColumn, ri as sql, j as sqlType, Qr as squashMigrationPlans, Ir as unblockLossy, D as withMigrationLock };
3037
+ export { O as DEFAULT_CDC_CHANNEL, o as FILE_MIGRATION_PATTERN, Gr as FileMigrationLedgerError, k as REACTIVE_TRIGGER_PREFIX, ne as VOLTRO_MIGRATION_LOCK_KEY, E as acquireMigrationLock, et as applyNamespacedSchema, Tr as applyPlan, Je as applySchema, ni as assessRollingDeployGate, $t as chunkTables, ei as classifyRollingDeploySafety, I as declaredSnapshot, xe as defaultArrayClause, be as defaultClause, M as defaultJsonClause, Br as describeOutcome, Pr as destructiveScope, ft as detectReactiveTriggerDrift, gn as emitDropColumnDdl, _n as emitDropColumnDdlMysql, qe as emitFrameworkBootstrapSql, Ge as emitNamespaceProvisionDdl, Ke as emitNamespacedSchemaSql, We as emitSchemaSql, P as fingerprintSchema, pt as formatReactiveTriggerDrift, Nr as ignoreTablesFromEnv, U as introspectSchema, r as isFileMigration, ii as isRawSqlFragment, Jt as mapPgType, c as migration, N as numericIdSql, qt as parseEnumCheck, Jr as pendingFileMigrationIds, Kt as planMigrations, tt as provisionTenantNamespace, Fe as reactiveTriggerRepairSql, D as releaseMigrationLock, Mn as renderColumnMysql, Dn as renderColumnPg, Zr as rollbackFileBasedMigration, ti as rollingDeployUnsafeOps, Yr as runFileBasedMigrations, nt as runFrameworkBootstrap, $e as runMigrate, zr as runPlannedMigrations, F as shortFingerprint, ct as snapshotColumn, ri as sql, j as sqlType, Qr as squashMigrationPlans, Ir as unblockLossy, ge as withMigrationLock };