@voltro/database 0.4.0 → 0.5.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 { L as e, R as t, V as n, a as r, c as i, et as a, i as o, n as s, ot as c, r as l, t as u } from "./fileBased-CRXgPJkv.js";
1
+ import { H as e, R as t, a as n, c as r, i, n as a, r as o, st as s, t as c, tt as l, z as u } from "./fileBased-Cc-F1oFv.js";
2
2
  import { Effect as d } from "effect";
3
3
  import { createLogger as f } from "@voltro/logger";
4
4
  import { SqlClient as p } from "@effect/sql";
@@ -121,54 +121,54 @@ var _ = (e, t, n, r = 400) => {
121
121
  orElse: () => oe(e)
122
122
  }), ge = (e, t) => d.acquireUseRelease(w(e), () => t, () => T(e).pipe(d.orDie)), _e = f({ scope: "voltro:migrate" }), E = (e) => {
123
123
  _e.warn(e.replace(/^\[voltro:migrate\]\s*/, ""));
124
- }, D = (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
+ }, D = (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 `${D({
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 _ = (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 _ = (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 _ = (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
- }, ve = (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, "''")}'` : typeof r == "object" && r && !Array.isArray(r) ? O(r, n) : null;
235
+ }, ve = (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, "''")}'` : typeof r == "object" && r && !Array.isArray(r) ? O(r, n) : null;
239
239
  }, O = (e, t) => {
240
240
  let n = JSON.stringify(e).replace(/'/g, "''");
241
241
  return t === "postgres" ? `DEFAULT '${n}'::jsonb` : t === "mysql" || t === "mariadb" ? `DEFAULT (CAST('${n}' AS JSON))` : `DEFAULT '${n}'`;
@@ -256,13 +256,13 @@ var _ = (e, t, n, r = 400) => {
256
256
  case "setNull": return "SET NULL";
257
257
  case "noAction": return "NO ACTION";
258
258
  }
259
- }, ye = (e, n, r) => r === null ? t(e, n) : `${t(r, n)}.${t(e, n)}`, be = 191, xe = (e, n, r) => {
260
- let i = t(e, r);
261
- if (r !== "mysql" && r !== "mariadb") return i;
262
- let a = n[e];
263
- if (!a) return i;
264
- let o = D(a, r).toUpperCase();
265
- return o.endsWith("TEXT") || o.endsWith("BLOB") ? `${i}(${be})` : i;
259
+ }, ye = (e, t, n) => n === null ? u(e, t) : `${u(n, t)}.${u(e, t)}`, be = 191, xe = (e, t, n) => {
260
+ let r = u(e, n);
261
+ if (n !== "mysql" && n !== "mariadb") return r;
262
+ let i = t[e];
263
+ if (!i) return r;
264
+ let a = D(i, n).toUpperCase();
265
+ return a.endsWith("TEXT") || a.endsWith("BLOB") ? `${r}(${be})` : r;
266
266
  }, Se = (e, t) => {
267
267
  if (!e.generatedAs) return null;
268
268
  let { expr: n, stored: r } = e.generatedAs;
@@ -271,149 +271,149 @@ var _ = (e, t, n, r = 400) => {
271
271
  if (t === "mssql") return `AS (${n})${r ? " PERSISTED" : ""}`;
272
272
  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.");
273
273
  return `GENERATED ALWAYS AS (${n}) ${r ? "STORED" : "VIRTUAL"}`;
274
- }, Ce = (n, r, i, a, o = !1, s = !1) => {
275
- if (r.type === "id" && r.idScheme?.kind === "numeric") return k(n, i);
276
- let c = i === "mssql" && r.type === "text" && !r.generatedAs && r.maxLength === void 0 && a?.has(n) ? "NVARCHAR(450)" : D(r, i), l = [t(n, i), c];
277
- r.type === "id" && !s && l.push("PRIMARY KEY");
278
- let u = Se(r, i);
279
- if (u) l.push(u);
274
+ }, Ce = (e, n, r, i, a = !1, o = !1) => {
275
+ if (n.type === "id" && n.idScheme?.kind === "numeric") return k(e, r);
276
+ let s = r === "mssql" && n.type === "text" && !n.generatedAs && n.maxLength === void 0 && i?.has(e) ? "NVARCHAR(450)" : D(n, r), c = [u(e, r), s];
277
+ n.type === "id" && !o && c.push("PRIMARY KEY");
278
+ let l = Se(n, r);
279
+ if (l) c.push(l);
280
280
  else {
281
- r.nullable || l.push("NOT NULL"), r.unique && r.type !== "id" && l.push("UNIQUE");
282
- let e = ve(r, i);
283
- e && l.push(e);
284
- }
285
- if (r.type === "reference" && r.references && !o) {
286
- let e = r.references();
287
- l.push(`REFERENCES ${t(e.tableName, i)} (${t("id", i)})`);
288
- let n = A(r.onDelete ?? "restrict", i);
289
- l.push(`ON DELETE ${n}`);
290
- let a = A(r.refOnUpdate ?? "noAction", i);
291
- a !== "NO ACTION" && l.push(`ON UPDATE ${a}`);
292
- }
293
- if (r.oneOf && r.oneOf.length > 0) {
294
- let e = r.oneOf.map((e) => `'${e.replace(/'/g, "''")}'`).join(", ");
295
- l.push(`CHECK (${t(n, i)} IN (${e}))`);
296
- }
297
- if (r.checks && r.checks.length > 0) for (let e of r.checks) l.push(`CHECK (${e})`);
298
- if (r.type === "enum" && r.enumValues && r.enumValues.length > 0 && (i === "mssql" || e(i))) {
299
- let e = r.enumValues.map((e) => `'${e.replace(/'/g, "''")}'`).join(", ");
300
- l.push(`CHECK (${t(n, i)} IN (${e}))`);
301
- }
302
- if (r.type === "json" || r.type === "array") {
303
- let r = t(n, i);
304
- e(i) ? l.push(`CHECK (${r} IS NULL OR json_valid(${r}))`) : i === "mssql" && l.push(`CHECK (${r} IS NULL OR ISJSON(${r}) = 1)`);
305
- }
306
- return l.join(" ");
307
- }, we = (e, n, r = null, i) => {
308
- let a = /* @__PURE__ */ new Set();
309
- for (let t of e.appliedIndexes ?? []) for (let e of t.fields) typeof e == "string" && a.add(e);
310
- for (let t of e.appliedUniques ?? []) for (let e of t.fields) typeof e == "string" && a.add(e);
311
- let o = e.appliedPrimaryKey ?? [], s = o.length > 0, c = Object.entries(e.fields).map(([e, t]) => ` ${Ce(e, t, n, a, i?.has(e) ?? !1, s)}`).join(",\n"), l = (e.appliedUniques ?? []).map((r) => {
312
- let i = r.fields.map((t) => xe(t, e.fields, n)).join(", ");
313
- return ` CONSTRAINT ${t(r.name, n)} UNIQUE (${i})`;
314
- }), u = (e.appliedChecks ?? []).map((e) => ` CONSTRAINT ${t(e.name, n)} CHECK (${e.expr})`), d = [
315
- ...s ? [` PRIMARY KEY (${o.map((t) => xe(t, e.fields, n)).join(", ")})`] : [],
316
- ...l,
317
- ...u
318
- ], f = d.length > 0 ? `${c},\n${d.join(",\n")}` : c, p = ye(e.tableName, n, r);
319
- if (n === "mssql") {
320
- let t = r === null ? e.tableName : `${r}.${e.tableName}`, n = `CREATE TABLE ${p} (\n${f}\n)`;
321
- return `IF OBJECT_ID('${t.replace(/'/g, "''")}', 'U') IS NULL EXEC(N'${n.replace(/'/g, "''")}');`;
281
+ n.nullable || c.push("NOT NULL"), n.unique && n.type !== "id" && c.push("UNIQUE");
282
+ let e = ve(n, r);
283
+ e && c.push(e);
284
+ }
285
+ if (n.type === "reference" && n.references && !a) {
286
+ let e = n.references();
287
+ c.push(`REFERENCES ${u(e.tableName, r)} (${u("id", r)})`);
288
+ let t = A(n.onDelete ?? "restrict", r);
289
+ c.push(`ON DELETE ${t}`);
290
+ let i = A(n.refOnUpdate ?? "noAction", r);
291
+ i !== "NO ACTION" && c.push(`ON UPDATE ${i}`);
292
+ }
293
+ if (n.oneOf && n.oneOf.length > 0) {
294
+ let t = n.oneOf.map((e) => `'${e.replace(/'/g, "''")}'`).join(", ");
295
+ c.push(`CHECK (${u(e, r)} IN (${t}))`);
296
+ }
297
+ if (n.checks && n.checks.length > 0) for (let e of n.checks) c.push(`CHECK (${e})`);
298
+ if (n.type === "enum" && n.enumValues && n.enumValues.length > 0 && (r === "mssql" || t(r))) {
299
+ let t = n.enumValues.map((e) => `'${e.replace(/'/g, "''")}'`).join(", ");
300
+ c.push(`CHECK (${u(e, r)} IN (${t}))`);
301
+ }
302
+ if (n.type === "json" || n.type === "array") {
303
+ let n = u(e, r);
304
+ t(r) ? c.push(`CHECK (${n} IS NULL OR json_valid(${n}))`) : r === "mssql" && c.push(`CHECK (${n} IS NULL OR ISJSON(${n}) = 1)`);
305
+ }
306
+ return c.join(" ");
307
+ }, we = (e, t, n = null, r) => {
308
+ let i = /* @__PURE__ */ new Set();
309
+ for (let t of e.appliedIndexes ?? []) for (let e of t.fields) typeof e == "string" && i.add(e);
310
+ for (let t of e.appliedUniques ?? []) for (let e of t.fields) typeof e == "string" && i.add(e);
311
+ let a = e.appliedPrimaryKey ?? [], o = a.length > 0, s = Object.entries(e.fields).map(([e, n]) => ` ${Ce(e, n, t, i, r?.has(e) ?? !1, o)}`).join(",\n"), c = (e.appliedUniques ?? []).map((n) => {
312
+ let r = n.fields.map((n) => xe(n, e.fields, t)).join(", ");
313
+ return ` CONSTRAINT ${u(n.name, t)} UNIQUE (${r})`;
314
+ }), l = (e.appliedChecks ?? []).map((e) => ` CONSTRAINT ${u(e.name, t)} CHECK (${e.expr})`), d = [
315
+ ...o ? [` PRIMARY KEY (${a.map((n) => xe(n, e.fields, t)).join(", ")})`] : [],
316
+ ...c,
317
+ ...l
318
+ ], f = d.length > 0 ? `${s},\n${d.join(",\n")}` : s, p = ye(e.tableName, t, n);
319
+ if (t === "mssql") {
320
+ let t = n === null ? e.tableName : `${n}.${e.tableName}`, r = `CREATE TABLE ${p} (\n${f}\n)`;
321
+ return `IF OBJECT_ID('${t.replace(/'/g, "''")}', 'U') IS NULL EXEC(N'${r.replace(/'/g, "''")}');`;
322
322
  }
323
323
  return [
324
324
  `CREATE TABLE IF NOT EXISTS ${p} (`,
325
325
  f,
326
326
  ");"
327
327
  ].join("\n");
328
- }, Te = (e, n, r) => {
329
- 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 = [];
330
- 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;
331
- }, Ee = (e, r, i = null) => {
332
- let a = [], s = /* @__PURE__ */ new Set(), c = (e) => e.join("\0"), l = (e, t, i, a) => {
328
+ }, Te = (e, t, n) => {
329
+ let r = `${e}_${t.name}_fts`, i = (e) => u(e, n), a = t.columns.map(i).join(", "), o = t.columns.map((e) => `new.${i(e)}`).join(", "), s = [];
330
+ return s.push(`CREATE VIRTUAL TABLE IF NOT EXISTS ${i(r)} USING fts5(${a}, row_id UNINDEXED, tokenize='porter');`), s.push(`CREATE TRIGGER IF NOT EXISTS ${i(`${r}_ai`)} AFTER INSERT ON ${i(e)} BEGIN\n INSERT INTO ${i(r)} (${a}, row_id) VALUES (${o}, new.${i("id")});\nEND;`), s.push(`CREATE TRIGGER IF NOT EXISTS ${i(`${r}_ad`)} AFTER DELETE ON ${i(e)} BEGIN\n DELETE FROM ${i(r)} WHERE row_id = old.${i("id")};\nEND;`), s.push(`CREATE TRIGGER IF NOT EXISTS ${i(`${r}_au`)} AFTER UPDATE ON ${i(e)} BEGIN\n DELETE FROM ${i(r)} WHERE row_id = old.${i("id")};\n INSERT INTO ${i(r)} (${a}, row_id) VALUES (${o}, new.${i("id")});\nEND;`), s;
331
+ }, Ee = (t, n, r = null) => {
332
+ let a = [], o = /* @__PURE__ */ new Set(), s = (e) => e.join("\0"), c = (t, r, i, a) => {
333
333
  let o = {
334
334
  using: "",
335
335
  withSuffix: "",
336
336
  skip: !1
337
337
  };
338
338
  if (i === void 0 || i === "btree") return o;
339
- if (i === "gist") return r === "postgres" ? {
339
+ if (i === "gist") return n === "postgres" ? {
340
340
  using: " USING GIST",
341
341
  withSuffix: "",
342
342
  skip: !1
343
- } : (E(`[voltro:migrate] index '${e}' on '${t}': ${r} doesn't support GiST — falling back to btree. Spatial queries on this column will fall back to sequential scan.`), o);
344
- if (i === "gin") return r === "postgres" ? {
343
+ } : (E(`[voltro:migrate] index '${t}' on '${r}': ${n} doesn't support GiST — falling back to btree. Spatial queries on this column will fall back to sequential scan.`), o);
344
+ if (i === "gin") return n === "postgres" ? {
345
345
  using: " USING GIN",
346
346
  withSuffix: "",
347
347
  skip: !1
348
- } : r === "mysql" || r === "mariadb" ? (E(`[voltro:migrate] gin index '${e}' on '${t}': ${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(...).`), {
348
+ } : n === "mysql" || n === "mariadb" ? (E(`[voltro:migrate] gin index '${t}' on '${r}': ${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(...).`), {
349
349
  using: "",
350
350
  withSuffix: "",
351
351
  skip: !0
352
- }) : (E(`[voltro:migrate] gin index '${e}' on '${t}': ${r} has no GIN access method — falling back to btree. Containment/membership queries won't use this index efficiently.`), o);
353
- if (i === "brin") return r === "postgres" ? {
352
+ }) : (E(`[voltro:migrate] gin index '${t}' on '${r}': ${n} has no GIN access method — falling back to btree. Containment/membership queries won't use this index efficiently.`), o);
353
+ if (i === "brin") return n === "postgres" ? {
354
354
  using: " USING BRIN",
355
355
  withSuffix: "",
356
356
  skip: !1
357
- } : (E(`[voltro:migrate] brin index '${e}' on '${t}': ${r} has no BRIN access method — falling back to btree (larger on disk, but the range scan still works).`), o);
357
+ } : (E(`[voltro:migrate] brin index '${t}' on '${r}': ${n} has no BRIN access method — falling back to btree (larger on disk, but the range scan still works).`), o);
358
358
  if (i === "hnsw") {
359
- if (r === "postgres") {
360
- let e = a?.hnsw?.m ?? 16, t = a?.hnsw?.efConstruction ?? 64, r = a?.hnsw?.opclass ?? n(a?.hnsw?.distance);
359
+ if (n === "postgres") {
360
+ let t = a?.hnsw?.m ?? 16, n = a?.hnsw?.efConstruction ?? 64, r = a?.hnsw?.opclass ?? e(a?.hnsw?.distance);
361
361
  return {
362
362
  using: " USING hnsw",
363
- withSuffix: ` WITH (m = ${e}, ef_construction = ${t})`,
363
+ withSuffix: ` WITH (m = ${t}, ef_construction = ${n})`,
364
364
  opclass: r,
365
365
  skip: !1
366
366
  };
367
367
  }
368
- return E(`[voltro:migrate] hnsw index '${e}' on '${t}': ${r} has no pgvector / HNSW access method — skipping. Nearest-neighbour queries on this column fall back to a sequential scan.`), {
368
+ return E(`[voltro:migrate] hnsw index '${t}' on '${r}': ${n} has no pgvector / HNSW access method — skipping. Nearest-neighbour queries on this column fall back to a sequential scan.`), {
369
369
  using: "",
370
370
  withSuffix: "",
371
371
  skip: !0
372
372
  };
373
373
  }
374
374
  return o;
375
- }, u = (t, n) => {
376
- let i = t.map((t) => {
377
- if (typeof t == "string") return xe(t, e.fields, r);
378
- if ("jsonPath" in t) {
379
- let { column: e, path: n, numeric: i } = t.jsonPath;
380
- return `(${o(e, n, r, { numeric: i })})`;
375
+ }, l = (e, r) => {
376
+ let a = e.map((e) => {
377
+ if (typeof e == "string") return xe(e, t.fields, n);
378
+ if ("jsonPath" in e) {
379
+ let { column: t, path: r, numeric: a } = e.jsonPath;
380
+ return `(${i(t, r, n, { numeric: a })})`;
381
381
  }
382
- return `(${t.expr})`;
382
+ return `(${e.expr})`;
383
383
  });
384
- return n !== void 0 && i.length === 1 ? `${i[0]} ${n}` : i.join(", ");
385
- }, d = (e, n, a, o, s, c = "", d = !1) => {
386
- let f = l(e, n, o, s);
384
+ return r !== void 0 && a.length === 1 ? `${a[0]} ${r}` : a.join(", ");
385
+ }, d = (e, t, i, a, o, s = "", d = !1) => {
386
+ let f = c(e, t, a, o);
387
387
  if (f.skip) return "";
388
- let p = u(a, f.opclass), m = `${f.withSuffix}${c}`, h = ye(n, r, i), g = d ? "UNIQUE " : "";
389
- return r === "mssql" ? `IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = '${e}') CREATE ${g}INDEX ${t(e, r)} ON ${h}${f.using} (${p})${m};` : r === "mysql" ? `CREATE ${g}INDEX ${t(e, r)} ON ${h}${f.using} (${p})${m};` : `CREATE ${g}INDEX IF NOT EXISTS ${t(e, r)} ON ${h}${f.using} (${p})${m};`;
388
+ let p = l(i, f.opclass), m = `${f.withSuffix}${s}`, h = ye(t, n, r), g = d ? "UNIQUE " : "";
389
+ return n === "mssql" ? `IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE name = '${e}') CREATE ${g}INDEX ${u(e, n)} ON ${h}${f.using} (${p})${m};` : n === "mysql" ? `CREATE ${g}INDEX ${u(e, n)} ON ${h}${f.using} (${p})${m};` : `CREATE ${g}INDEX IF NOT EXISTS ${u(e, n)} ON ${h}${f.using} (${p})${m};`;
390
390
  };
391
- for (let n of e.appliedFullText ?? []) if (r === "postgres") {
392
- let i = n.config ?? "english", o = `${n.name}_tsv`, s = n.columns.map((e) => {
393
- let a = n.weights?.[e] ?? "A";
394
- return `setweight(to_tsvector('${i}', coalesce(${t(e, r)}, '')), '${a}')`;
391
+ for (let e of t.appliedFullText ?? []) if (n === "postgres") {
392
+ let r = e.config ?? "english", i = `${e.name}_tsv`, o = e.columns.map((t) => {
393
+ let i = e.weights?.[t] ?? "A";
394
+ return `setweight(to_tsvector('${r}', coalesce(${u(t, n)}, '')), '${i}')`;
395
395
  }).join(" || ");
396
- a.push(`ALTER TABLE ${t(e.tableName, r)} ADD COLUMN IF NOT EXISTS ${t(o, r)} tsvector GENERATED ALWAYS AS (${s}) STORED;`), a.push(`CREATE INDEX IF NOT EXISTS ${t(n.name, r)} ON ${t(e.tableName, r)} USING GIN (${t(o, r)});`);
397
- } else if (r === "mysql" || r === "mariadb") {
398
- let i = n.columns.map((e) => t(e, r)).join(", ");
399
- a.push(`CREATE FULLTEXT INDEX ${t(n.name, r)} ON ${t(e.tableName, r)} (${i});`);
400
- } else if (r === "turso") throw Error(`@voltro/sql-turso: full-text index '${n.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.`);
401
- else r === "sqlite" ? a.push(...Te(e.tableName, n, r)) : E(`[voltro:migrate] full-text index '${n.name}' on '${e.tableName}': ${r} uses a ranked LIKE search at query time (no native FTS catalog required).`);
402
- for (let t of e.appliedIndexes) {
403
- if ((r === "mariadb" || r === "mssql") && t.fields.some((e) => typeof e != "string" && "jsonPath" in e)) {
404
- E(`[voltro:migrate] json-path index '${t.name}' on '${e.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(...).`);
396
+ a.push(`ALTER TABLE ${u(t.tableName, n)} ADD COLUMN IF NOT EXISTS ${u(i, n)} tsvector GENERATED ALWAYS AS (${o}) STORED;`), a.push(`CREATE INDEX IF NOT EXISTS ${u(e.name, n)} ON ${u(t.tableName, n)} USING GIN (${u(i, n)});`);
397
+ } else if (n === "mysql" || n === "mariadb") {
398
+ let r = e.columns.map((e) => u(e, n)).join(", ");
399
+ a.push(`CREATE FULLTEXT INDEX ${u(e.name, n)} ON ${u(t.tableName, n)} (${r});`);
400
+ } else if (n === "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.`);
401
+ else n === "sqlite" ? a.push(...Te(t.tableName, e, n)) : E(`[voltro:migrate] full-text index '${e.name}' on '${t.tableName}': ${n} uses a ranked LIKE search at query time (no native FTS catalog required).`);
402
+ for (let e of t.appliedIndexes) {
403
+ if ((n === "mariadb" || n === "mssql") && e.fields.some((e) => typeof e != "string" && "jsonPath" in e)) {
404
+ E(`[voltro:migrate] json-path index '${e.name}' on '${t.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(...).`);
405
405
  continue;
406
406
  }
407
- if (t.unique && t.where !== void 0 && t.where.length > 0 && (r === "mysql" || r === "mariadb")) throw Error(`@voltro/migrate: uniqueActive index '${t.name}' on '${e.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.`);
408
- let n = "";
409
- t.where !== void 0 && t.where.length > 0 && (r === "mysql" || r === "mariadb" ? E(`[voltro:migrate] partial index '${t.name}' on '${e.tableName}': ${r} does not support WHERE clauses on indexes — emitting a full index`) : n = ` WHERE ${t.where}`);
410
- let i = d(t.name, e.tableName, t.fields, t.kind, t.kindOptions, n, t.unique === !0);
411
- i !== "" && a.push(i), t.fields.every((e) => typeof e == "string") && s.add(c(t.fields));
407
+ if (e.unique && e.where !== void 0 && e.where.length > 0 && (n === "mysql" || n === "mariadb")) throw Error(`@voltro/migrate: uniqueActive index '${e.name}' on '${t.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.`);
408
+ let r = "";
409
+ e.where !== void 0 && e.where.length > 0 && (n === "mysql" || n === "mariadb" ? E(`[voltro:migrate] partial index '${e.name}' on '${t.tableName}': ${n} does not support WHERE clauses on indexes — emitting a full index`) : r = ` WHERE ${e.where}`);
410
+ let i = d(e.name, t.tableName, e.fields, e.kind, e.kindOptions, r, e.unique === !0);
411
+ i !== "" && a.push(i), e.fields.every((e) => typeof e == "string") && o.add(s(e.fields));
412
412
  }
413
- for (let [t, n] of Object.entries(e.fields)) {
414
- if (n.type !== "reference" || n.fkAutoIndex === !1 || s.has(c([t]))) continue;
415
- let r = `${e.tableName}_${t}_idx`;
416
- a.push(d(r, e.tableName, [t])), s.add(c([t]));
413
+ for (let [e, n] of Object.entries(t.fields)) {
414
+ if (n.type !== "reference" || n.fkAutoIndex === !1 || o.has(s([e]))) continue;
415
+ let r = `${t.tableName}_${e}_idx`;
416
+ a.push(d(r, t.tableName, [e])), o.add(s([e]));
417
417
  }
418
418
  return a.join("\n");
419
419
  }, De = "CREATE OR REPLACE FUNCTION framework_notify_change() RETURNS trigger AS $$\nDECLARE\n payload TEXT;\nBEGIN\n payload := json_build_object(\n 'table', TG_TABLE_NAME,\n -- The schema the write landed in. Under namespace isolation this is\n -- the tenant schema (tenant_<id>); the CDC consumer uses it so a\n -- write in tenant A namespace does not spuriously wake tenant B\n -- subscriptions on the same-named table. public/absent = shared.\n 'schema', TG_TABLE_SCHEMA,\n 'op', lower(TG_OP),\n 'old', CASE WHEN TG_OP = 'INSERT' THEN NULL ELSE row_to_json(OLD) END,\n 'new', CASE WHEN TG_OP = 'DELETE' THEN NULL ELSE row_to_json(NEW) END\n )::text;\n -- pg_notify hard-caps the payload at 8000 bytes; a wide reactive row\n -- (big text / json column) would otherwise abort the write itself.\n -- Fall back to a body-less notice — the CDC consumer treats absent\n -- old/new as \"all columns changed\" and re-queries, so correctness is\n -- preserved; only the delta-diff fast path is skipped for that write.\n IF octet_length(payload) >= 7999 THEN\n payload := json_build_object(\n 'table', TG_TABLE_NAME,\n 'schema', TG_TABLE_SCHEMA,\n 'op', lower(TG_OP),\n 'old', NULL,\n 'new', NULL,\n 'oversized', true\n )::text;\n END IF;\n PERFORM pg_notify('framework_changes', payload);\n RETURN COALESCE(NEW, OLD);\nEND;\n$$ LANGUAGE plpgsql;", Oe = (e) => `
@@ -459,27 +459,27 @@ FOR EACH ROW EXECUTE FUNCTION framework_notify_change();
459
459
  sorted: o,
460
460
  cyclic: r
461
461
  };
462
- }, Me = (e, n, r = null) => {
463
- let i = (e) => r ? `${t(r, n)}.${t(e, n)}` : t(e, n), a = `${e.table}_${e.column}_fkey`, o = A(e.onDelete, n), s = A(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}`;
464
- switch (n) {
462
+ }, Me = (e, t, n = null) => {
463
+ let r = (e) => n ? `${u(n, t)}.${u(e, t)}` : u(e, t), i = `${e.table}_${e.column}_fkey`, a = A(e.onDelete, t), o = A(e.onUpdate, t), s = ` ON DELETE ${a}${o === "NO ACTION" ? "" : ` ON UPDATE ${o}`}`, c = (n) => `ADD CONSTRAINT ${u(i, t)} FOREIGN KEY ${n ? "IF NOT EXISTS " : ""}(${u(e.column, t)}) REFERENCES ${r(e.targetTable)} (${u("id", t)})${s}`;
464
+ switch (t) {
465
465
  case "postgres": return [
466
466
  "DO $$ BEGIN",
467
467
  " IF NOT EXISTS (SELECT 1 FROM pg_constraint",
468
- ` WHERE conname = '${a}' AND conrelid = '${r ? `${r}.` : ""}${e.table}'::regclass) THEN`,
469
- ` ALTER TABLE ${i(e.table)} ${l(!1)};`,
468
+ ` WHERE conname = '${i}' AND conrelid = '${n ? `${n}.` : ""}${e.table}'::regclass) THEN`,
469
+ ` ALTER TABLE ${r(e.table)} ${c(!1)};`,
470
470
  " END IF;",
471
471
  "END $$;"
472
472
  ].join("\n");
473
- case "mssql": return `IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE name = '${a}') ALTER TABLE ${i(e.table)} ${l(!1)};`;
474
- case "mariadb": return `ALTER TABLE ${i(e.table)} ${l(!0)};`;
475
- default: return `ALTER TABLE ${i(e.table)} ${l(!1)};`;
473
+ case "mssql": return `IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE name = '${i}') ALTER TABLE ${r(e.table)} ${c(!1)};`;
474
+ case "mariadb": return `ALTER TABLE ${r(e.table)} ${c(!0)};`;
475
+ default: return `ALTER TABLE ${r(e.table)} ${c(!1)};`;
476
476
  }
477
- }, Ne = (t, n) => {
477
+ }, Ne = (e, n) => {
478
478
  let r = /* @__PURE__ */ new Map();
479
- if (e(n)) return r;
480
- for (let e of t) {
481
- let t = r.get(e.table) ?? /* @__PURE__ */ new Set();
482
- t.add(e.column), r.set(e.table, t);
479
+ if (t(n)) return r;
480
+ for (let t of e) {
481
+ let e = r.get(t.table) ?? /* @__PURE__ */ new Set();
482
+ e.add(t.column), r.set(t.table, e);
483
483
  }
484
484
  return r;
485
485
  }, Pe = (e, t) => {
@@ -503,7 +503,7 @@ FOR EACH ROW EXECUTE FUNCTION framework_notify_change();
503
503
  let n = /* @__PURE__ */ new Set();
504
504
  for (let t of e) for (let e of Object.values(t.fields)) e.type === "enum" && e.enumName && n.add(e.enumName);
505
505
  let r = [];
506
- for (let e of n) for (let { from: t, to: n } of c(e)) {
506
+ for (let e of n) for (let { from: t, to: n } of s(e)) {
507
507
  let i = e.replace(/'/g, "''"), a = t.replace(/'/g, "''"), o = n.replace(/'/g, "''");
508
508
  r.push(`DO \$\$
509
509
  DECLARE
@@ -513,21 +513,21 @@ BEGIN
513
513
  }
514
514
  return r.join("\n\n");
515
515
  }, Ie = (e) => {
516
- let t = [], n = [];
517
- for (let i of e) r(i) ? n.push(i) : t.push(i);
516
+ let t = [], r = [];
517
+ for (let i of e) n(i) ? r.push(i) : t.push(i);
518
518
  return {
519
519
  tables: t,
520
- views: n
520
+ views: r
521
521
  };
522
- }, j = (t, n) => {
523
- let { tables: r, views: a } = Ie(t), { sorted: o, cyclic: s } = je(r.map((e) => b(e, n))), c = Ne(s, n), l = [];
522
+ }, j = (e, n) => {
523
+ let { tables: i, views: a } = Ie(e), { sorted: o, cyclic: s } = je(i.map((e) => b(e, n))), c = Ne(s, n), l = [];
524
524
  n === "postgres" && ke(o) && l.push("CREATE EXTENSION IF NOT EXISTS vector;"), n === "postgres" && Ae(o) && l.push("CREATE EXTENSION IF NOT EXISTS postgis;");
525
525
  let u = Fe(o, n);
526
526
  u && l.push(u);
527
527
  let d = Pe(o, n);
528
528
  d && l.push(d);
529
529
  for (let e of o) l.push(we(e, n, null, c.get(e.tableName)));
530
- if (!e(n)) for (let e of s) l.push(Me(e, n));
530
+ if (!t(n)) for (let e of s) l.push(Me(e, n));
531
531
  for (let e of o) {
532
532
  let t = Ee(e, n);
533
533
  t && l.push(t);
@@ -537,57 +537,57 @@ BEGIN
537
537
  l.push(De);
538
538
  for (let e of f) l.push(Oe(e));
539
539
  }
540
- for (let e of a) l.push(i(e, n));
540
+ for (let e of a) l.push(r(e, n));
541
541
  return l.join("\n\n") + "\n";
542
- }, Le = (e, n, r) => {
543
- let i = t(e, n);
544
- switch (n) {
545
- case "postgres": return `CREATE SCHEMA IF NOT EXISTS ${i};`;
542
+ }, Le = (e, t, n) => {
543
+ let r = u(e, t);
544
+ switch (t) {
545
+ case "postgres": return `CREATE SCHEMA IF NOT EXISTS ${r};`;
546
546
  case "mysql":
547
- case "mariadb": return `CREATE DATABASE IF NOT EXISTS ${i};`;
548
- case "mssql": return `IF SCHEMA_ID('${e.replace(/'/g, "''")}') IS NULL EXEC(N'CREATE SCHEMA ${i.replace(/'/g, "''")}');`;
547
+ case "mariadb": return `CREATE DATABASE IF NOT EXISTS ${r};`;
548
+ case "mssql": return `IF SCHEMA_ID('${e.replace(/'/g, "''")}') IS NULL EXEC(N'CREATE SCHEMA ${r.replace(/'/g, "''")}');`;
549
549
  case "turso":
550
- case "sqlite": return `ATTACH DATABASE '${(r ?? `${e}.db`).replace(/'/g, "''")}' AS ${i};`;
551
- }
552
- }, Re = (n, r, i, a) => {
553
- let o = Le(i, r, a), s = t(i, r);
554
- if (r === "postgres") return `${o}\n\nSET search_path TO ${s};\n\n${j(n, r)}`;
555
- if (r === "mysql" || r === "mariadb") return `${o}\n\nUSE ${s};\n\n${j(n, r)}`;
556
- let { sorted: c, cyclic: l } = je(n), u = Ne(l, r), d = [o];
557
- for (let e of c) d.push(we(e, r, i, u.get(e.tableName)));
558
- if (!e(r)) for (let e of l) d.push(Me(e, r, i));
559
- for (let e of c) {
560
- let t = Ee(e, r, i);
550
+ case "sqlite": return `ATTACH DATABASE '${(n ?? `${e}.db`).replace(/'/g, "''")}' AS ${r};`;
551
+ }
552
+ }, Re = (e, n, r, i) => {
553
+ let a = Le(r, n, i), o = u(r, n);
554
+ if (n === "postgres") return `${a}\n\nSET search_path TO ${o};\n\n${j(e, n)}`;
555
+ if (n === "mysql" || n === "mariadb") return `${a}\n\nUSE ${o};\n\n${j(e, n)}`;
556
+ let { sorted: s, cyclic: c } = je(e), l = Ne(c, n), d = [a];
557
+ for (let e of s) d.push(we(e, n, r, l.get(e.tableName)));
558
+ if (!t(n)) for (let e of c) d.push(Me(e, n, r));
559
+ for (let e of s) {
560
+ let t = Ee(e, n, r);
561
561
  t && d.push(t);
562
562
  }
563
563
  return d.join("\n\n") + "\n";
564
- }, ze = (e, n) => {
565
- if (n !== "postgres") return j(e, n);
566
- let { sorted: r, cyclic: i } = je(e), a = Ne(i, n), o = [], s = Fe(r, n);
567
- s && o.push(s);
568
- let c = Pe(r, n);
569
- c && o.push(c);
570
- for (let e of r) o.push(we(e, n, null, a.get(e.tableName)));
571
- for (let e of i) o.push(Me(e, n));
572
- for (let e of r) {
573
- let r = Object.entries(e.fields);
574
- if (r.length === 0) continue;
575
- let i = r.map(([r, i]) => {
576
- let o = Ce(r, i, n, void 0, a.get(e.tableName)?.has(r) ?? !1);
577
- return `ALTER TABLE ${t(e.tableName, n)} ADD COLUMN IF NOT EXISTS ${o};`;
564
+ }, ze = (e, t) => {
565
+ if (t !== "postgres") return j(e, t);
566
+ let { sorted: n, cyclic: r } = je(e), i = Ne(r, t), a = [], o = Fe(n, t);
567
+ o && a.push(o);
568
+ let s = Pe(n, t);
569
+ s && a.push(s);
570
+ for (let e of n) a.push(we(e, t, null, i.get(e.tableName)));
571
+ for (let e of r) a.push(Me(e, t));
572
+ for (let e of n) {
573
+ let n = Object.entries(e.fields);
574
+ if (n.length === 0) continue;
575
+ let r = n.map(([n, r]) => {
576
+ let a = Ce(n, r, t, void 0, i.get(e.tableName)?.has(n) ?? !1);
577
+ return `ALTER TABLE ${u(e.tableName, t)} ADD COLUMN IF NOT EXISTS ${a};`;
578
578
  });
579
- o.push(i.join("\n"));
579
+ a.push(r.join("\n"));
580
580
  }
581
- for (let e of r) {
582
- let t = Ee(e, n);
583
- t && o.push(t);
581
+ for (let e of n) {
582
+ let n = Ee(e, t);
583
+ n && a.push(n);
584
584
  }
585
- let l = r.filter((e) => e.isReactive);
586
- if (l.length > 0) {
587
- o.push(De);
588
- for (let e of l) o.push(Oe(e));
585
+ let c = n.filter((e) => e.isReactive);
586
+ if (c.length > 0) {
587
+ a.push(De);
588
+ for (let e of c) a.push(Oe(e));
589
589
  }
590
- return o.join("\n\n") + "\n";
590
+ return a.join("\n\n") + "\n";
591
591
  }, Be = (e, t = "postgres") => d.gen(function* () {
592
592
  let n = yield* p.SqlClient;
593
593
  yield* ge(n, Ue(n, j(e, t), t)).pipe(d.orDie);
@@ -694,8 +694,8 @@ BEGIN
694
694
  columns: ["id"],
695
695
  unique: !0
696
696
  });
697
- let o = e.appliedIndexes ?? [];
698
- for (let t of o) {
697
+ let a = e.appliedIndexes ?? [];
698
+ for (let t of a) {
699
699
  if (t.unique && t.where) continue;
700
700
  let n = t.fields.map((e) => typeof e == "string" ? e : "jsonPath" in e ? `(json:${e.jsonPath.column}->${e.jsonPath.path.join(".")}${e.jsonPath.numeric ? "::num" : ""})` : `(${e.expr})`), i = t.fields.some((e) => typeof e != "string");
701
701
  r({
@@ -706,21 +706,21 @@ BEGIN
706
706
  ...i ? { expression: !0 } : {}
707
707
  });
708
708
  }
709
- let s = e.appliedUniques ?? [];
710
- for (let t of s) t.fields.length < 2 || r({
709
+ let o = e.appliedUniques ?? [];
710
+ for (let t of o) t.fields.length < 2 || r({
711
711
  name: t.name,
712
712
  table: e.tableName,
713
713
  columns: t.fields,
714
714
  unique: !0
715
715
  });
716
- let c = /* @__PURE__ */ new Set();
717
- for (let e of o) e.fields.every((e) => typeof e == "string") && c.add(e.fields.join("\0"));
716
+ let s = /* @__PURE__ */ new Set();
717
+ for (let e of a) e.fields.every((e) => typeof e == "string") && s.add(e.fields.join("\0"));
718
718
  for (let [t, n] of Object.entries(e.fields)) {
719
719
  let i = n;
720
- if (i.dropped || !i.references || i.fkAutoIndex === !1 || c.has(t)) continue;
721
- let o = `${e.tableName}_${t}_idx`;
722
- a(e.tableName, o, !0, [t]), r({
723
- name: o,
720
+ if (i.dropped || !i.references || i.fkAutoIndex === !1 || s.has(t)) continue;
721
+ let a = `${e.tableName}_${t}_idx`;
722
+ l(e.tableName, a, !0, [t]), r({
723
+ name: a,
724
724
  table: e.tableName,
725
725
  columns: [t],
726
726
  unique: !1
@@ -2409,7 +2409,7 @@ BEGIN
2409
2409
  for (let i of r) {
2410
2410
  if (sr.has(i.name)) continue;
2411
2411
  let r = g(e, i.name);
2412
- i.isDirectory() ? await n(r) : i.isFile() && u.test(i.name) && t.push(r);
2412
+ i.isDirectory() ? await n(r) : i.isFile() && c.test(i.name) && t.push(r);
2413
2413
  }
2414
2414
  };
2415
2415
  return await n(e), t.sort((e, t) => {
@@ -2420,7 +2420,7 @@ BEGIN
2420
2420
  let t = [];
2421
2421
  for (let n of e) {
2422
2422
  let e = (await import(ee(n).href)).default;
2423
- if (!s(e)) {
2423
+ if (!a(e)) {
2424
2424
  process.stderr.write(`[voltro:migrate] ${n} has no default-exported \`migration(...)\` — skipped\n`);
2425
2425
  continue;
2426
2426
  }
@@ -2610,4 +2610,4 @@ BEGIN
2610
2610
  values: [...t]
2611
2611
  }), _r = (e) => typeof e == "object" && !!e && e._tag === "RawSqlFragment";
2612
2612
  //#endregion
2613
- export { u as FILE_MIGRATION_PATTERN, C as VOLTRO_MIGRATION_LOCK_KEY, ut as _internalCmp, w as acquireMigrationLock, Ke as applyNamespacedSchema, Yn as applyPlan, Be as applySchema, Lt as chunkTables, P as declaredSnapshot, ve as defaultClause, O as defaultJsonClause, or as describeOutcome, Yt as emitDropColumnDdl, Xt as emitDropColumnDdlMysql, ze as emitFrameworkBootstrapSql, Le as emitNamespaceProvisionDdl, Re as emitNamespacedSchemaSql, j as emitSchemaSql, M as fingerprintSchema, rr as ignoreTablesFromEnv, qt as introspectSchema, s as isFileMigration, _r as isRawSqlFragment, Mt as mapPgType, l as migration, k as numericIdSql, jt as parseEnumCheck, At as planMigrations, qe as provisionTenantNamespace, T as releaseMigrationLock, sn as renderColumnMysql, rn as renderColumnPg, mr as rollbackFileBasedMigration, fr as runFileBasedMigrations, Je as runFrameworkBootstrap, Ge as runMigrate, ar as runPlannedMigrations, N as shortFingerprint, gr as sql, D as sqlType, hr as squashMigrationPlans, ge as withMigrationLock };
2613
+ export { c as FILE_MIGRATION_PATTERN, C as VOLTRO_MIGRATION_LOCK_KEY, ut as _internalCmp, w as acquireMigrationLock, Ke as applyNamespacedSchema, Yn as applyPlan, Be as applySchema, Lt as chunkTables, P as declaredSnapshot, ve as defaultClause, O as defaultJsonClause, or as describeOutcome, Yt as emitDropColumnDdl, Xt as emitDropColumnDdlMysql, ze as emitFrameworkBootstrapSql, Le as emitNamespaceProvisionDdl, Re as emitNamespacedSchemaSql, j as emitSchemaSql, M as fingerprintSchema, rr as ignoreTablesFromEnv, qt as introspectSchema, a as isFileMigration, _r as isRawSqlFragment, Mt as mapPgType, o as migration, k as numericIdSql, jt as parseEnumCheck, At as planMigrations, qe as provisionTenantNamespace, T as releaseMigrationLock, sn as renderColumnMysql, rn as renderColumnPg, mr as rollbackFileBasedMigration, fr as runFileBasedMigrations, Je as runFrameworkBootstrap, Ge as runMigrate, ar as runPlannedMigrations, N as shortFingerprint, gr as sql, D as sqlType, hr as squashMigrationPlans, ge as withMigrationLock };