@voltro/cli 0.41.0 → 0.42.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.
Files changed (68) hide show
  1. package/CHANGELOG.md +97 -0
  2. package/dist/bin.js +1 -1
  3. package/dist/{commands-D0VR1yBB.js → commands-DoTClnSk.js} +4 -4
  4. package/dist/{dataCommand-OKC5FscP.js → dataCommand-Rj57y1vg.js} +286 -168
  5. package/dist/dataProfile-Cm0YVKSy.js +18 -0
  6. package/dist/{dbCommand-BHRamDsy.js → dbCommand-B237qI-j.js} +361 -361
  7. package/dist/dbCommand-BvQeKQOb.js +2 -0
  8. package/dist/index.js +1 -1
  9. package/dist/{migrate-DLtPv2_D.js → migrate-DN47p2PG.js} +1 -1
  10. package/dist/{serveCommand-Cba_M2Su.js → serveCommand-C512kzZA.js} +415 -409
  11. package/dist/serveCommand-gj7MsqXY.js +2 -0
  12. package/dist/serveEntry.js +1 -1
  13. package/package.json +17 -17
  14. package/templates/AGENTS.md +1 -1
  15. package/templates/agent-docs/_index.md +1 -1
  16. package/templates/agent-docs/cli.md +73 -6
  17. package/templates/agent-docs/data.md +33 -0
  18. package/templates/agent-docs/whats-new.md +59 -36
  19. package/templates/apps/api-ai/package.json +7 -7
  20. package/templates/apps/api-auth/package.json +8 -8
  21. package/templates/apps/api-backend/package.json +7 -7
  22. package/templates/apps/api-backend-deactivation/package.json +7 -7
  23. package/templates/apps/api-backend-mail/package.json +8 -8
  24. package/templates/apps/api-backend-mariadb/package.json +9 -9
  25. package/templates/apps/api-backend-sqlite/package.json +8 -8
  26. package/templates/apps/api-backend-storage/package.json +8 -8
  27. package/templates/apps/api-cms/package.json +10 -10
  28. package/templates/apps/api-collab/package.json +8 -8
  29. package/templates/apps/api-data-advanced/package.json +8 -8
  30. package/templates/apps/api-durable/package.json +8 -8
  31. package/templates/apps/api-feature-flags/package.json +9 -9
  32. package/templates/apps/api-governance/package.json +8 -8
  33. package/templates/apps/api-kv/package.json +8 -8
  34. package/templates/apps/api-moderation/package.json +8 -8
  35. package/templates/apps/api-observability/package.json +8 -8
  36. package/templates/apps/api-ratelimit/package.json +8 -8
  37. package/templates/apps/api-rbac/package.json +8 -8
  38. package/templates/apps/api-rest/package.json +7 -7
  39. package/templates/apps/api-saas/package.json +11 -11
  40. package/templates/apps/api-saas-starter/package.json +10 -10
  41. package/templates/apps/api-search/package.json +8 -8
  42. package/templates/apps/api-status/package.json +8 -8
  43. package/templates/apps/api-versioning/package.json +8 -8
  44. package/templates/apps/api-webhooks/package.json +9 -9
  45. package/templates/apps/changelog/package.json +6 -6
  46. package/templates/apps/edge-functions/package.json +2 -2
  47. package/templates/apps/frontend-admin/package.json +8 -8
  48. package/templates/apps/frontend-app/package.json +9 -9
  49. package/templates/apps/frontend-auth/package.json +8 -8
  50. package/templates/apps/frontend-blank/package.json +7 -7
  51. package/templates/apps/frontend-cms/package.json +9 -9
  52. package/templates/apps/frontend-collab/package.json +10 -10
  53. package/templates/apps/frontend-contact/package.json +7 -7
  54. package/templates/apps/frontend-dashboard/package.json +7 -7
  55. package/templates/apps/frontend-docs/package.json +7 -7
  56. package/templates/apps/frontend-i18n/package.json +6 -6
  57. package/templates/apps/frontend-landing/package.json +7 -7
  58. package/templates/apps/frontend-portal/package.json +8 -8
  59. package/templates/apps/frontend-saas/package.json +8 -8
  60. package/templates/apps/frontend-spa/package.json +7 -7
  61. package/templates/apps/frontend-ssr/package.json +7 -7
  62. package/templates/apps/frontend-ssr-api/package.json +8 -8
  63. package/templates/apps/frontend-static-blog/package.json +6 -6
  64. package/templates/apps/frontend-status/package.json +8 -8
  65. package/templates/apps/mobile-app/package.json +4 -4
  66. package/dist/dataProfile-dW-PsfLB.js +0 -15
  67. package/dist/dbCommand-C9iE1pd9.js +0 -2
  68. package/dist/serveCommand-DRbYK646.js +0 -2
@@ -15,12 +15,12 @@ import { pathToFileURL as D } from "node:url";
15
15
  import { createLogger as O } from "@voltro/logger";
16
16
  import { Effect as k } from "effect";
17
17
  import { SqlClient as A } from "@effect/sql";
18
- import { DEFAULT_CDC_CHANNEL as j, applyPlan as ne, applySchema as re, assessRollingDeployGate as ie, branchRehearsalExitCode as ae, declaredSnapshot as oe, destructiveScope as se, fingerprintSchema as ce, formatBranchRehearsal as le, ignoreTablesFromEnv as M, introspectSchema as ue, pendingFileMigrationIds as de, planMigrations as N, recordUpToDate as fe, rehearseMigrationOnBranch as pe, rollbackFileBasedMigration as me, rollingDeployUnsafeOps as he, runFileBasedMigrations as ge, shortFingerprint as P, squashMigrationPlans as _e, unblockLossy as ve } from "@voltro/database/sql";
19
- import { actorsTable as ye, branchNamespaceName as be, decodeFieldValue as xe, encodeFieldValue as Se, frameworkTables as Ce, isEncrypted as F, isMigrationDefinition as we, isRawEncoding as Te, makeNamespaceBranchExecutor as Ee, provisionBranch as De, quoteIdent as Oe, registerCoreTables as ke, resolveBranchMechanism as Ae, teardownBranch as je } from "@voltro/database";
20
- import { InMemoryDataStore as Me, makeFieldCipher as Ne } from "@voltro/runtime";
21
- import { createHash as Pe } from "node:crypto";
18
+ import { DEFAULT_CDC_CHANNEL as j, applyPlan as ne, applySchema as re, assessRollingDeployGate as ie, branchRehearsalExitCode as ae, declaredSnapshot as oe, destructiveScope as se, fingerprintSchema as ce, formatBranchRehearsal as le, ignoreTablesFromEnv as M, introspectSchema as N, pendingFileMigrationIds as ue, planMigrations as P, recordUpToDate as de, rehearseMigrationOnBranch as fe, rollbackFileBasedMigration as pe, rollingDeployUnsafeOps as me, runFileBasedMigrations as he, shortFingerprint as F, squashMigrationPlans as ge, unblockLossy as _e } from "@voltro/database/sql";
19
+ import { actorsTable as ve, branchNamespaceName as ye, decodeFieldValue as be, encodeFieldValue as xe, frameworkTables as Se, isEncrypted as I, isMigrationDefinition as Ce, isRawEncoding as we, makeNamespaceBranchExecutor as Te, provisionBranch as Ee, quoteIdent as De, registerCoreTables as Oe, resolveBranchMechanism as ke, teardownBranch as Ae } from "@voltro/database";
20
+ import { InMemoryDataStore as je, makeFieldCipher as Me } from "@voltro/runtime";
21
+ import { createHash as Ne } from "node:crypto";
22
22
  //#region src/adoptPlan.ts
23
- var Fe = (e) => typeof e != "string", Ie = (e, t, n, r) => {
23
+ var Pe = (e) => typeof e != "string", Fe = (e, t, n, r) => {
24
24
  let i = [], a = new Map(t.map((e) => [e.name, e])), o = new Map(n.map((e) => [e.name, e])), s = new Set(e.leaveUnset ?? []);
25
25
  r > 0 && i.push({
26
26
  kind: "target-not-empty",
@@ -37,7 +37,7 @@ var Fe = (e) => typeof e != "string", Ie = (e, t, n, r) => {
37
37
  });
38
38
  continue;
39
39
  }
40
- if (Fe(n)) {
40
+ if (Pe(n)) {
41
41
  c.push({
42
42
  target: t,
43
43
  source: n.expr,
@@ -80,23 +80,23 @@ var Fe = (e) => typeof e != "string", Ie = (e, t, n, r) => {
80
80
  remintIds: f,
81
81
  fatal: i.some((e) => e.fatal)
82
82
  };
83
- }, Le = (e, t) => [
83
+ }, Ie = (e, t) => [
84
84
  `back up '${e.from}' to a restorable dump`,
85
85
  `copy rows: INSERT INTO ${e.into} (${t.assignments.map((e) => e.target).join(", ")}) SELECT … FROM ${e.from}`,
86
86
  ...t.remintIds ? ["record old id → new id in a translation table", `rewrite every reference to '${e.from}', JSON columns included`] : [],
87
87
  "verify: row counts match and a sample round-trips",
88
88
  `drop '${e.from}' — LAST, and only after the verify`
89
- ], Re = (e, t, n) => {
89
+ ], Le = (e, t, n) => {
90
90
  let r = [`adopt · ${e.from} (${n} row(s)) → ${e.into}`, ""];
91
91
  for (let e of t.assignments) r.push(` ${e.target.padEnd(24)} ← ${e.raw ? `${e.source} (raw)` : e.source}`);
92
92
  t.problems.length > 0 && r.push("");
93
93
  for (let e of t.problems) r.push(` ${e.fatal ? "✗" : "⚠"} ${e.detail}`);
94
94
  if (r.push(""), t.fatal) return r.push(" REFUSED — fix the problems above. Nothing was written."), r;
95
95
  r.push(" would run, in this order:");
96
- for (let [n, i] of Le(e, t).entries()) r.push(` ${n + 1}. ${i}`);
96
+ for (let [n, i] of Ie(e, t).entries()) r.push(` ${n + 1}. ${i}`);
97
97
  return r;
98
- }, ze = (e) => e === "mysql" || e === "mariadb" ? (e) => `\`${e}\`` : e === "mssql" ? (e) => `[${e}]` : (e) => `"${e}"`, Be = (e) => `${e}__adopt_snapshot`, Ve = (e, t, n, r, i) => {
99
- let a = ze(n), o = Be(e.from), s = t.assignments.map((e) => e.target), c = t.assignments.map((e) => e.raw ? e.source : a(e.source));
98
+ }, Re = (e) => e === "mysql" || e === "mariadb" ? (e) => `\`${e}\`` : e === "mssql" ? (e) => `[${e}]` : (e) => `"${e}"`, ze = (e) => `${e}__adopt_snapshot`, Be = (e, t, n, r, i) => {
99
+ let a = Re(n), o = ze(e.from), s = t.assignments.map((e) => e.target), c = t.assignments.map((e) => e.raw ? e.source : a(e.source));
100
100
  return i !== void 0 && (s.unshift(r), c.unshift(i)), {
101
101
  snapshot: n === "mssql" ? `SELECT * INTO ${a(o)} FROM ${a(e.from)}` : `CREATE TABLE ${a(o)} AS SELECT * FROM ${a(e.from)}`,
102
102
  copy: `INSERT INTO ${a(e.into)} (${s.map(a).join(", ")}) SELECT ${c.join(", ")} FROM ${a(e.from)}`,
@@ -106,18 +106,18 @@ var Fe = (e) => typeof e != "string", Ie = (e, t, n, r) => {
106
106
  drop: `DROP TABLE ${a(e.from)}`,
107
107
  dropSnapshot: `DROP TABLE ${a(o)}`
108
108
  };
109
- }, He = (e) => {
109
+ }, Ve = (e) => {
110
110
  let t = e[0];
111
111
  if (t === void 0) return 0;
112
112
  let n = t.n ?? t.N ?? Object.values(t)[0];
113
113
  return Number(n ?? 0);
114
- }, Ue = async (e, t, n, r, i, a, o = {}) => {
114
+ }, He = async (e, t, n, r, i, a, o = {}) => {
115
115
  if (t.fatal) throw Error("adopt: the plan was refused — nothing was run");
116
- let s = Ve(e, t, n, r, i), c = Be(e.from), l = He(await a(s.verifySource));
116
+ let s = Be(e, t, n, r, i), c = ze(e.from), l = Ve(await a(s.verifySource));
117
117
  await a(s.snapshot);
118
118
  for (let e of s.translations) await a(e);
119
119
  await a(s.copy);
120
- let u = He(await a(s.verifyTarget));
120
+ let u = Ve(await a(s.verifyTarget));
121
121
  return u === l ? o.keepSource === !0 ? {
122
122
  copied: u,
123
123
  sourceRows: l,
@@ -137,7 +137,7 @@ var Fe = (e) => typeof e != "string", Ie = (e, t, n, r) => {
137
137
  snapshotTable: c,
138
138
  sourceDropped: !1
139
139
  };
140
- }, I = [
140
+ }, L = [
141
141
  "token",
142
142
  "secret",
143
143
  "password",
@@ -146,7 +146,7 @@ var Fe = (e) => typeof e != "string", Ie = (e, t, n, r) => {
146
146
  "credential",
147
147
  "privatekey",
148
148
  "private_key"
149
- ], We = [
149
+ ], Ue = [
150
150
  {
151
151
  table: "_voltro_audit_log",
152
152
  column: "subject"
@@ -191,7 +191,7 @@ var Fe = (e) => typeof e != "string", Ie = (e, t, n, r) => {
191
191
  table: "_voltro_row_history",
192
192
  column: "subjectId"
193
193
  }
194
- ], Ge = (e, t) => {
194
+ ], We = (e, t) => {
195
195
  switch (t) {
196
196
  case "postgres": return `LOWER(CAST(${e} AS text))`;
197
197
  case "mysql":
@@ -200,17 +200,17 @@ var Fe = (e) => typeof e != "string", Ie = (e, t, n, r) => {
200
200
  case "sqlite":
201
201
  case "turso": return `LOWER(CAST(${e} AS TEXT))`;
202
202
  }
203
- }, Ke = (e, t, n = I) => n.map((n) => `${Ge(e, t)} LIKE '%${n}%'`).join("\n OR "), qe = ["_omitted", "__redacted"], Je = (e, t) => {
203
+ }, Ge = (e, t, n = L) => n.map((n) => `${We(e, t)} LIKE '%${n}%'`).join("\n OR "), Ke = ["_omitted", "__redacted"], qe = (e, t) => {
204
204
  let n = e.toLowerCase();
205
205
  return t.some((e) => n.includes(e));
206
- }, Ye = (e, t = []) => {
206
+ }, Je = (e, t = []) => {
207
207
  if (Array.isArray(e)) {
208
- for (let n of e) Ye(n, t);
208
+ for (let n of e) Je(n, t);
209
209
  return t;
210
210
  }
211
- if (typeof e == "object" && e) for (let [n, r] of Object.entries(e)) t.push(n), Ye(r, t);
211
+ if (typeof e == "object" && e) for (let [n, r] of Object.entries(e)) t.push(n), Je(r, t);
212
212
  return t;
213
- }, Xe = (e) => Array.isArray(e) ? e.map(Xe) : typeof e == "object" && e ? Object.fromEntries(Object.entries(e).map(([e, t]) => [e, qe.includes(e) ? null : Xe(t)])) : e, Ze = (e, t = I) => {
213
+ }, Ye = (e) => Array.isArray(e) ? e.map(Ye) : typeof e == "object" && e ? Object.fromEntries(Object.entries(e).map(([e, t]) => [e, Ke.includes(e) ? null : Ye(t)])) : e, Xe = (e, t = L) => {
214
214
  let n;
215
215
  try {
216
216
  n = JSON.parse(e);
@@ -222,33 +222,33 @@ var Fe = (e) => typeof e != "string", Ie = (e, t, n, r) => {
222
222
  };
223
223
  }
224
224
  return {
225
- asKey: Ye(n).some((e) => Je(e, t)),
226
- redactionMarkerOnly: !Je(JSON.stringify(Xe(n)) ?? "", t),
225
+ asKey: Je(n).some((e) => qe(e, t)),
226
+ redactionMarkerOnly: !qe(JSON.stringify(Ye(n)) ?? "", t),
227
227
  undecidable: !1
228
228
  };
229
- }, Qe = (e) => ({
229
+ }, Ze = (e) => ({
230
230
  examined: e.length,
231
231
  asKey: e.filter((e) => e.asKey).length,
232
232
  redactionMarkerOnly: e.filter((e) => e.redactionMarkerOnly && !e.asKey).length,
233
233
  undecidable: e.filter((e) => e.undecidable).length
234
- }), L = (e) => {
234
+ }), R = (e) => {
235
235
  let t = e.classification;
236
236
  return t === void 0 || e.hits === void 0 || e.hits === 0 ? !1 : t.examined === e.hits && t.undecidable === 0 && t.asKey === 0 && t.redactionMarkerOnly === e.hits;
237
- }, $e = (e, t, n, r) => {
238
- let i = `WHERE ${Ke(t, n)}`, a = Ge(t, n).replace(/^LOWER\((.*)\)$/s, "$1");
237
+ }, Qe = (e, t, n, r) => {
238
+ let i = `WHERE ${Ge(t, n)}`, a = We(t, n).replace(/^LOWER\((.*)\)$/s, "$1");
239
239
  return n === "mssql" ? `SELECT TOP (${r}) ${a} AS v FROM ${e}\n ${i}` : `SELECT ${a} AS v FROM ${e}\n ${i}\n LIMIT ${r}`;
240
- }, et = async (e, t, n, r, i) => (await k.runPromise(e.unsafe($e(t, n, r, i)))).map((e) => {
240
+ }, $e = async (e, t, n, r, i) => (await k.runPromise(e.unsafe(Qe(t, n, r, i)))).map((e) => {
241
241
  let t = Object.values(e)[0];
242
242
  return typeof t == "string" ? t : JSON.stringify(t ?? null);
243
- }), tt = async (e, t) => {
243
+ }), et = async (e, t) => {
244
244
  let n = await k.runPromise(e.unsafe(t));
245
245
  return Number(Object.values(n[0] ?? { n: 0 })[0] ?? 0);
246
- }, nt = async (e, t, n, r) => {
246
+ }, tt = async (e, t, n, r) => {
247
247
  let i = [];
248
248
  for (let a of n) {
249
249
  let n = r(a.table), o;
250
250
  try {
251
- o = await tt(e, `SELECT COUNT(*) AS n FROM ${n}`);
251
+ o = await et(e, `SELECT COUNT(*) AS n FROM ${n}`);
252
252
  } catch {
253
253
  i.push({
254
254
  table: a.table,
@@ -260,9 +260,9 @@ var Fe = (e) => typeof e != "string", Ie = (e, t, n, r) => {
260
260
  continue;
261
261
  }
262
262
  try {
263
- let s = await tt(e, `SELECT COUNT(*) AS n FROM ${n}\n WHERE ${Ke(r(a.column), t)}`), c = [];
264
- if (s > 0) for (let i of I) try {
265
- let o = await tt(e, `SELECT COUNT(*) AS n FROM ${n}\n WHERE ${Ke(r(a.column), t, [i])}`);
263
+ let s = await et(e, `SELECT COUNT(*) AS n FROM ${n}\n WHERE ${Ge(r(a.column), t)}`), c = [];
264
+ if (s > 0) for (let i of L) try {
265
+ let o = await et(e, `SELECT COUNT(*) AS n FROM ${n}\n WHERE ${Ge(r(a.column), t, [i])}`);
266
266
  o > 0 && c.push({
267
267
  needle: i,
268
268
  rows: o
@@ -270,7 +270,7 @@ var Fe = (e) => typeof e != "string", Ie = (e, t, n, r) => {
270
270
  } catch {}
271
271
  let l;
272
272
  if (s > 0) try {
273
- l = Qe((await et(e, n, r(a.column), t, 500)).map((e) => Ze(e)));
273
+ l = Ze((await $e(e, n, r(a.column), t, 500)).map((e) => Xe(e)));
274
274
  } catch {}
275
275
  i.push({
276
276
  table: a.table,
@@ -291,8 +291,8 @@ var Fe = (e) => typeof e != "string", Ie = (e, t, n, r) => {
291
291
  }
292
292
  }
293
293
  return i;
294
- }, rt = (e, t) => {
295
- let n = I.length, r = [`credential scan · dialect ${t}`, ""], i = /* @__PURE__ */ new Set();
294
+ }, nt = (e, t) => {
295
+ let n = L.length, r = [`credential scan · dialect ${t}`, ""], i = /* @__PURE__ */ new Set();
296
296
  for (let t of e) {
297
297
  if (t.unavailable === "column") {
298
298
  r.push(` · ${t.table}.${t.column} — column is not present on this deployment (${t.scanned} row(s) exist but this column was not scanned)`);
@@ -306,14 +306,14 @@ var Fe = (e) => typeof e != "string", Ie = (e, t, n, r) => {
306
306
  r.push(` · ${t.table} — table is EMPTY (0 rows scanned; this is not a clean bill of health)`);
307
307
  continue;
308
308
  }
309
- let e = L(t), n = (t.hits ?? 0) === 0 ? "✓" : e ? "~" : "✗";
309
+ let e = R(t), n = (t.hits ?? 0) === 0 ? "✓" : e ? "~" : "✗";
310
310
  r.push(` ${n} ${t.table}.${t.column} — ${t.hits} of ${t.scanned} row(s) contain a credential-shaped NAME (anywhere in the value)`), (t.matchedNeedles?.length ?? 0) > 0 && r.push(` matched (rows per needle, may overlap): ${t.matchedNeedles.map((e) => `${e.needle} (${e.rows})`).join(", ")}`);
311
311
  let a = t.classification;
312
- a !== void 0 && (r.push(` examined ${a.examined} of ${t.hits} matched row(s)${a.examined < (t.hits ?? 0) ? " (capped at 500)" : ""}: ${a.asKey} as a JSON KEY, ${a.redactionMarkerOnly} only inside a redaction marker${a.undecidable > 0 ? `, ${a.undecidable} not parseable as JSON` : ""}`), e && r.push(` EXPLAINED — every match is \`${qe.join("` / `")}\`, the framework's own`, " record that a `.sensitive()` column was left OUT. Nothing to purge, nothing to rotate."));
312
+ a !== void 0 && (r.push(` examined ${a.examined} of ${t.hits} matched row(s)${a.examined < (t.hits ?? 0) ? " (capped at 500)" : ""}: ${a.asKey} as a JSON KEY, ${a.redactionMarkerOnly} only inside a redaction marker${a.undecidable > 0 ? `, ${a.undecidable} not parseable as JSON` : ""}`), e && r.push(` EXPLAINED — every match is \`${Ke.join("` / `")}\`, the framework's own`, " record that a `.sensitive()` column was left OUT. Nothing to purge, nothing to rotate."));
313
313
  }
314
- let a = e.reduce((e, t) => e + (L(t) ? 0 : t.hits ?? 0), 0), o = e.reduce((e, t) => e + (L(t) ? t.hits ?? 0 : 0), 0);
314
+ let a = e.reduce((e, t) => e + (R(t) ? 0 : t.hits ?? 0), 0), o = e.reduce((e, t) => e + (R(t) ? t.hits ?? 0 : 0), 0);
315
315
  return r.push(""), o > 0 && r.push(` ${o} row(s) matched only the framework's own redaction markers and are NOT findings.`), a > 0 ? r.push(` ${a} row(s) carry something credential-shaped.`, " Purge them AND rotate the credentials — assume anything written to a log", " table has been read. Then stop putting the credential on the Subject:", " `connectionCredentials(...)` keeps it in the framework vault.") : e.every((e) => e.scanned === void 0 || e.scanned === 0 || e.unavailable !== void 0) ? r.push(" NOTHING WAS SCANNED. This run proves nothing about your data.") : r.push(" No credential-shaped keys found in the rows that exist."), r.push("", ` These are NAME heuristics (${n} of them), not proof. A credential in a`, " column whose key is not credential-shaped — `keyValue`, `pat`, `authz` —", " is invisible here. A clean run means \"no credential-shaped NAME found\",", " which is not the same as \"no credential\".", "", " Run this on EVERY environment. A dev database is not a sample of production."), r.join("\n");
316
- }, it = (e) => e.some((e) => (e.hits ?? 0) > 0 && !L(e)) ? 1 : e.every((e) => e.unavailable !== void 0 || e.scanned === void 0 || e.scanned === 0) ? 2 : 0, at = /\.migration\.ts$/, ot = async (e, t) => {
316
+ }, rt = (e) => e.some((e) => (e.hits ?? 0) > 0 && !R(e)) ? 1 : e.every((e) => e.unavailable !== void 0 || e.scanned === void 0 || e.scanned === 0) ? 2 : 0, it = /\.migration\.ts$/, at = async (e, t) => {
317
317
  let n = [];
318
318
  for (let r of e) {
319
319
  let e;
@@ -323,7 +323,7 @@ var Fe = (e) => typeof e != "string", Ie = (e, t, n, r) => {
323
323
  t.warn("migration: failed to import", { file: r }, e);
324
324
  continue;
325
325
  }
326
- let i = (e.default && we(e.default) ? e.default : void 0) ?? Object.values(e).find(we);
326
+ let i = (e.default && Ce(e.default) ? e.default : void 0) ?? Object.values(e).find(Ce);
327
327
  if (!i) {
328
328
  t.warn("migration: no defineMigration export", { file: r });
329
329
  continue;
@@ -333,7 +333,7 @@ var Fe = (e) => typeof e != "string", Ie = (e, t, n, r) => {
333
333
  idInFile: i.id,
334
334
  idFromFile: ee(r).replace(/\.migration\.ts$/, "")
335
335
  });
336
- let a = await E.readFile(r, "utf8").catch(() => ""), o = Pe("sha256").update(a).digest("hex").slice(0, 16);
336
+ let a = await E.readFile(r, "utf8").catch(() => ""), o = Ne("sha256").update(a).digest("hex").slice(0, 16);
337
337
  n.push({
338
338
  file: r,
339
339
  definition: i,
@@ -341,13 +341,13 @@ var Fe = (e) => typeof e != "string", Ie = (e, t, n, r) => {
341
341
  });
342
342
  }
343
343
  return [...n].sort((e, t) => e.definition.id < t.definition.id ? -1 : 1);
344
- }, st = async (e) => {
344
+ }, ot = async (e) => {
345
345
  let t = (process.env.DB_DIALECT ?? "postgres").toLowerCase(), n = t === "memory" ? "postgres" : t, r = n, i = t === "memory" ? void 0 : await l(n).then((e) => e.retryFilter, () => void 0);
346
- return k.runPromise(re(Ce, r, void 0, i === void 0 ? {} : { retryFilter: i }).pipe(k.provide(e)));
347
- }, ct = (e) => k.runPromise(k.gen(function* () {
346
+ return k.runPromise(re(Se, r, void 0, i === void 0 ? {} : { retryFilter: i }).pipe(k.provide(e)));
347
+ }, st = (e) => k.runPromise(k.gen(function* () {
348
348
  let e = yield* (yield* A.SqlClient)`SELECT id, status, hash, "appliedAt" FROM "_voltro_migrations"`.pipe(k.orElseSucceed(() => []));
349
349
  return new Map(e.map((e) => [e.id, e]));
350
- }).pipe(k.provide(e))), R = (e, t) => k.runPromise(k.gen(function* () {
350
+ }).pipe(k.provide(e))), z = (e, t) => k.runPromise(k.gen(function* () {
351
351
  yield* (yield* A.SqlClient)`
352
352
  INSERT INTO "_voltro_migrations"
353
353
  (id, name, hash, status, "appliedAt", "durationMs", "errorMessage", "errorStack")
@@ -363,14 +363,14 @@ var Fe = (e) => typeof e != "string", Ie = (e, t, n, r) => {
363
363
  "errorStack" = EXCLUDED."errorStack",
364
364
  "updatedAt" = now()
365
365
  `;
366
- }).pipe(k.provide(e))), lt = async (e, t, n) => {
366
+ }).pipe(k.provide(e))), ct = async (e, t, n) => {
367
367
  if (e.length === 0) return {
368
368
  applied: [],
369
369
  failed: null,
370
370
  skipped: []
371
371
  };
372
- await st(t);
373
- let r = await ct(t), i = [], a = [], o = null;
372
+ await ot(t);
373
+ let r = await st(t), i = [], a = [], o = null;
374
374
  for (let s of e) {
375
375
  let e = r.get(s.definition.id);
376
376
  if (e && e.status === "applied") {
@@ -391,7 +391,7 @@ var Fe = (e) => typeof e != "string", Ie = (e, t, n, r) => {
391
391
  name: s.definition.name
392
392
  });
393
393
  let c = Date.now(), l = [];
394
- await R(t, {
394
+ await z(t, {
395
395
  id: s.definition.id,
396
396
  name: s.definition.name,
397
397
  hash: s.hash,
@@ -432,7 +432,7 @@ var Fe = (e) => typeof e != "string", Ie = (e, t, n, r) => {
432
432
  ...a.stack ? { stack: a.stack } : {}
433
433
  }
434
434
  };
435
- o = f, i.push(f), await R(t, {
435
+ o = f, i.push(f), await z(t, {
436
436
  id: s.definition.id,
437
437
  name: s.definition.name,
438
438
  hash: s.hash,
@@ -451,7 +451,7 @@ var Fe = (e) => typeof e != "string", Ie = (e, t, n, r) => {
451
451
  status: "applied",
452
452
  durationMs: Date.now() - c,
453
453
  steps: l
454
- }), await R(t, {
454
+ }), await z(t, {
455
455
  id: s.definition.id,
456
456
  name: s.definition.name,
457
457
  hash: s.hash,
@@ -471,9 +471,9 @@ var Fe = (e) => typeof e != "string", Ie = (e, t, n, r) => {
471
471
  failed: o,
472
472
  skipped: a
473
473
  };
474
- }, ut = async (e, t, n, r = {}) => {
475
- await st(t);
476
- let i = await ct(t), a = e.filter((e) => i.get(e.definition.id)?.status === "applied");
474
+ }, lt = async (e, t, n, r = {}) => {
475
+ await ot(t);
476
+ let i = await st(t), a = e.filter((e) => i.get(e.definition.id)?.status === "applied");
477
477
  if (a.length === 0) return n.info("migration: nothing to roll back"), {
478
478
  applied: [],
479
479
  failed: null,
@@ -526,7 +526,7 @@ var Fe = (e) => typeof e != "string", Ie = (e, t, n, r) => {
526
526
  status: "applied",
527
527
  durationMs: Date.now() - r,
528
528
  steps: i
529
- }), await R(t, {
529
+ }), await z(t, {
530
530
  id: e.definition.id,
531
531
  name: e.definition.name,
532
532
  hash: e.hash,
@@ -542,9 +542,9 @@ var Fe = (e) => typeof e != "string", Ie = (e, t, n, r) => {
542
542
  failed: c,
543
543
  skipped: []
544
544
  };
545
- }, dt = async (e, t) => {
546
- await st(t);
547
- let n = await ct(t);
545
+ }, ut = async (e, t) => {
546
+ await ot(t);
547
+ let n = await st(t);
548
548
  return e.map((e) => {
549
549
  let t = n.get(e.definition.id);
550
550
  return t ? {
@@ -561,7 +561,7 @@ var Fe = (e) => typeof e != "string", Ie = (e, t, n, r) => {
561
561
  hashMatches: !0
562
562
  };
563
563
  });
564
- }, ft = (e) => {
564
+ }, dt = (e) => {
565
565
  if (!e.failed) return "";
566
566
  let t = e.failed, n = [
567
567
  `✗ Migration failed: ${t.migrationId} / step '${t.error?.stepName ?? "?"}'`,
@@ -574,22 +574,22 @@ var Fe = (e) => typeof e != "string", Ie = (e, t, n, r) => {
574
574
  ""
575
575
  ];
576
576
  return e.applied.length > 0 && n.unshift("", `(${e.applied.length} migration(s) applied successfully before the failure.)`), n.join("\n");
577
- }, pt = (e) => {
577
+ }, ft = (e) => {
578
578
  let t = e.split(".");
579
579
  if (t.length !== 2 || !t[0] || !t[1]) throw Error(`voltro db encrypt-column: expected <table>.<column>, got "${e}"`);
580
580
  return {
581
581
  table: t[0],
582
582
  column: t[1]
583
583
  };
584
- }, mt = (e) => 49 + 4 * Math.ceil(e / 3), ht = (e, t) => {
585
- let n = mt(e);
584
+ }, pt = (e) => 49 + 4 * Math.ceil(e / 3), mt = (e, t) => {
585
+ let n = pt(e);
586
586
  return {
587
587
  longestPlaintextBytes: e,
588
588
  longestCiphertext: n,
589
589
  declaredMaxLength: t,
590
590
  fits: t === void 0 || n <= t
591
591
  };
592
- }, gt = (e, t) => `${e.table}.${e.column} is too narrow: its longest value encodes to ${t.longestPlaintextBytes} byte(s), which encrypts to ${t.longestCiphertext} characters, and the column is declared as ${t.declaredMaxLength}. Widen it first (\`.maxLength(${t.longestCiphertext})\` or more, then \`voltro db apply\`) and run this again. Nothing was written.`, _t = (e, t) => {
592
+ }, ht = (e, t) => `${e.table}.${e.column} is too narrow: its longest value encodes to ${t.longestPlaintextBytes} byte(s), which encrypts to ${t.longestCiphertext} characters, and the column is declared as ${t.declaredMaxLength}. Widen it first (\`.maxLength(${t.longestCiphertext})\` or more, then \`voltro db apply\`) and run this again. Nothing was written.`, gt = (e, t) => {
593
593
  let n = t ? "would encrypt" : "encrypted";
594
594
  return [
595
595
  ` ${e.table}.${e.column}`,
@@ -599,25 +599,25 @@ var Fe = (e) => typeof e != "string", Ie = (e, t, n, r) => {
599
599
  ` null / empty ${e.empty}`,
600
600
  ` ${n.padEnd(18)} ${e.encrypted}`
601
601
  ].join("\n");
602
- }, vt = (e, t, n) => {
602
+ }, _t = (e, t, n) => {
603
603
  if (e == null) return;
604
604
  let r = typeof e == "string" ? e : String(e);
605
- if (r === "" || F(r)) return;
606
- let i = Se(t, r), a;
605
+ if (r === "" || I(r)) return;
606
+ let i = xe(t, r), a;
607
607
  try {
608
- a = xe(t, i);
608
+ a = be(t, i);
609
609
  } catch (e) {
610
610
  throw Error(`${n.table}.${n.column}: the value could not be read back the way the app reads it (${e.message ?? String(e)}). Nothing was written.`);
611
611
  }
612
612
  if (a !== r) throw Error(`${n.table}.${n.column}: round-trip mismatch — reading the encrypted value back did not return what it was given. Nothing was written.`);
613
613
  return i;
614
- }, yt = (e) => Buffer.byteLength(e, "utf8"), bt = (e) => yt(JSON.stringify(typeof e == "string" ? e : String(e))), xt = (e, t) => {
614
+ }, vt = (e) => Buffer.byteLength(e, "utf8"), yt = (e) => vt(JSON.stringify(typeof e == "string" ? e : String(e))), bt = (e, t) => {
615
615
  if (e !== void 0) try {
616
616
  return t.decrypt(e), !0;
617
617
  } catch {
618
618
  return !1;
619
619
  }
620
- }, St = (e, t) => `${e.table}.${e.column} already holds values encrypted with a DIFFERENT key than ${t} — the active key cannot decrypt them. Continuing would encrypt the remaining rows under a second key, and the column would then be readable with neither key alone. Nothing was written. Point ${t} at the key the existing rows were written with.`, Ct = (e) => [
620
+ }, xt = (e, t) => `${e.table}.${e.column} already holds values encrypted with a DIFFERENT key than ${t} — the active key cannot decrypt them. Continuing would encrypt the remaining rows under a second key, and the column would then be readable with neither key alone. Nothing was written. Point ${t} at the key the existing rows were written with.`, St = (e) => [
621
621
  "",
622
622
  " NEXT — this converted the rows that exist. New writes are still plaintext",
623
623
  " until the column carries the modifier:",
@@ -627,25 +627,25 @@ var Fe = (e) => typeof e != "string", Ie = (e, t, n, r) => {
627
627
  " Order does not matter: a read returns a non-ciphertext value unchanged, so",
628
628
  " the column may hold a mix while you deploy. Run this again afterwards to",
629
629
  " catch anything written in between — it skips what is already encrypted."
630
- ].join("\n"), wt = (e, t, n) => {
631
- if (typeof e != "string" || !F(e)) return;
630
+ ].join("\n"), Ct = (e, t, n) => {
631
+ if (typeof e != "string" || !I(e)) return;
632
632
  let r;
633
633
  try {
634
- r = Te(t, e);
634
+ r = we(t, e);
635
635
  } catch {
636
636
  return;
637
637
  }
638
638
  if (r !== !0) return;
639
- let i = xe(t, e);
639
+ let i = be(t, e);
640
640
  if (typeof i != "string") return;
641
- let a = Se(t, i);
642
- if (xe(t, a) !== i) throw Error(`${n.table}.${n.column}: re-encoding did not round-trip. Nothing was written.`);
641
+ let a = xe(t, i);
642
+ if (be(t, a) !== i) throw Error(`${n.table}.${n.column}: re-encoding did not round-trip. Nothing was written.`);
643
643
  return a;
644
- }, Tt = (e, t, n) => e === "sqlite" ? `SELECT NULL AS n FROM pragma_table_info('${t.table}') WHERE name = '${t.column}'` : `SELECT character_maximum_length AS n FROM information_schema.columns\n WHERE ${n} AND table_name = '${t.table}' AND column_name = '${t.column}'`, Et = (e) => {
644
+ }, wt = (e, t, n) => e === "sqlite" ? `SELECT NULL AS n FROM pragma_table_info('${t.table}') WHERE name = '${t.column}'` : `SELECT character_maximum_length AS n FROM information_schema.columns\n WHERE ${n} AND table_name = '${t.table}' AND column_name = '${t.column}'`, Tt = (e) => {
645
645
  if (e == null) return;
646
646
  let t = Number(e);
647
647
  return Number.isFinite(t) && t >= 0 ? t : void 0;
648
- }, z = O({ scope: "voltro:db" }), Dt = /* @__PURE__ */ new Set([
648
+ }, B = O({ scope: "voltro:db" }), Et = /* @__PURE__ */ new Set([
649
649
  "node_modules",
650
650
  "dist",
651
651
  "build",
@@ -653,17 +653,17 @@ var Fe = (e) => typeof e != "string", Ie = (e, t, n, r) => {
653
653
  ".vite",
654
654
  ".next",
655
655
  ".git"
656
- ]), B = async (e, t) => {
656
+ ]), V = async (e, t) => {
657
657
  let n = [], r = async (e) => {
658
658
  let i = await E.readdir(e, { withFileTypes: !0 }).catch(() => []);
659
659
  for (let a of i) {
660
- if (Dt.has(a.name)) continue;
660
+ if (Et.has(a.name)) continue;
661
661
  let i = C(e, a.name);
662
662
  a.isDirectory() ? await r(i) : a.isFile() && t.test(a.name) && n.push(i);
663
663
  }
664
664
  };
665
665
  return await r(e), n;
666
- }, Ot = [
666
+ }, Dt = [
667
667
  "--against",
668
668
  "--batch",
669
669
  "--before",
@@ -682,63 +682,63 @@ var Fe = (e) => typeof e != "string", Ie = (e, t, n, r) => {
682
682
  "--store",
683
683
  "--to",
684
684
  "--token"
685
- ], V = (e) => T(c(e, Ot) ?? process.cwd()), H = () => u("migration"), kt = (e) => {
685
+ ], H = (e) => T(c(e, Dt) ?? process.cwd()), U = () => u("migration"), Ot = (e) => {
686
686
  let t = e;
687
687
  if (typeof t != "object" || !t) return !1;
688
688
  if (t.code === "ERR_OUT_OF_RANGE" || t.cause?.code === "ERR_OUT_OF_RANGE") return !0;
689
689
  let n = `${t.message ?? ""} ${t.cause?.message ?? ""} ${t.stack ?? ""}`;
690
690
  return /ERR_OUT_OF_RANGE|out of range/i.test(n) && /pg-protocol|parseDataRow|buffer-reader|BufferReader/i.test(n);
691
- }, At = "Live-DB introspection got a corrupt / misaligned response from the database. This happens when `voltro db plan` / `apply` / `drift` / `migrate` runs through a connection POOLER (Supabase Supavisor / PgBouncer) on a LARGE schema — the pooler mis-frames a big catalog response. The introspection already batches by table to keep responses small; if a batch still trips it:\n 1. Lower the batch: set `VOLTRO_INTROSPECT_BATCH` to a smaller number of tables (default 20 — try 5 or 1). This keeps `db plan` on the normal pooler, no direct connection needed.\n 2. Or use a DIRECT (non-pooler) connection: set `DB_DIRECT_URL` (or `DB_MIGRATE_URL`) to the direct database URL — the runtime keeps `DB_URL`, so only the migration path is affected. (Supabase: direct = `db.<project-ref>.supabase.co` [IPv6-only on newer projects]; pooler = `aws-0-<region>.pooler.supabase.com`.)", U = () => {
691
+ }, kt = "Live-DB introspection got a corrupt / misaligned response from the database. This happens when `voltro db plan` / `apply` / `drift` / `migrate` runs through a connection POOLER (Supabase Supavisor / PgBouncer) on a LARGE schema — the pooler mis-frames a big catalog response. The introspection already batches by table to keep responses small; if a batch still trips it:\n 1. Lower the batch: set `VOLTRO_INTROSPECT_BATCH` to a smaller number of tables (default 20 — try 5 or 1). This keeps `db plan` on the normal pooler, no direct connection needed.\n 2. Or use a DIRECT (non-pooler) connection: set `DB_DIRECT_URL` (or `DB_MIGRATE_URL`) to the direct database URL — the runtime keeps `DB_URL`, so only the migration path is affected. (Supabase: direct = `db.<project-ref>.supabase.co` [IPv6-only on newer projects]; pooler = `aws-0-<region>.pooler.supabase.com`.)", W = () => {
692
692
  let e = (process.env.DB_DIALECT ?? "postgres").toLowerCase();
693
693
  if (e === "memory") throw new r("voltro db: subcommands require a real dialect, not DB_DIALECT=memory.");
694
694
  return e;
695
- }, W = (e) => Oe(e, U()), G = (e) => e === "mysql" || e === "mariadb" ? "table_schema = DATABASE()" : e === "mssql" ? "table_schema = SCHEMA_NAME()" : "table_schema = 'public'", K = async () => (await l(U())).makeSqlLayer(H()), jt = async (e) => {
696
- let t = V(e), n = e.includes("--dry-run"), r = await ot(await B(t, at), z);
697
- if (r.length === 0) return z.info("no migrations found", { root: t }), 0;
695
+ }, G = (e) => De(e, W()), K = (e) => e === "mysql" || e === "mariadb" ? "table_schema = DATABASE()" : e === "mssql" ? "table_schema = SCHEMA_NAME()" : "table_schema = 'public'", q = async () => (await l(W())).makeSqlLayer(U()), At = async (e) => {
696
+ let t = H(e), n = e.includes("--dry-run"), r = await at(await V(t, it), B);
697
+ if (r.length === 0) return B.info("no migrations found", { root: t }), 0;
698
698
  if (n) {
699
699
  let e = /* @__PURE__ */ new Set();
700
700
  try {
701
- let t = await dt(r, await K());
701
+ let t = await ut(r, await q());
702
702
  e = new Set(t.filter((e) => e.status === "applied").map((e) => e.id));
703
703
  } catch {
704
- z.warn("migrate --dry-run: could not read the migration ledger — showing ALL as pending");
704
+ B.warn("migrate --dry-run: could not read the migration ledger — showing ALL as pending");
705
705
  }
706
706
  let t = r.filter((t) => !e.has(t.definition.id));
707
- if (t.length === 0) return z.info("migrate --dry-run: nothing pending — every migration is applied"), 0;
708
- z.info(`migrate --dry-run: ${t.length} pending (nothing applied)`);
707
+ if (t.length === 0) return B.info("migrate --dry-run: nothing pending — every migration is applied"), 0;
708
+ B.info(`migrate --dry-run: ${t.length} pending (nothing applied)`);
709
709
  for (let e of t) console.log(` pending ${e.definition.id}`);
710
710
  return 0;
711
711
  }
712
- let i = await lt(r, await K(), z);
713
- return i.failed ? (process.stderr.write(ft(i) + "\n"), 1) : (z.info("migrate complete", {
712
+ let i = await ct(r, await q(), B);
713
+ return i.failed ? (process.stderr.write(dt(i) + "\n"), 1) : (B.info("migrate complete", {
714
714
  applied: i.applied.length,
715
715
  skipped: i.skipped.length
716
716
  }), 0);
717
+ }, jt = async (e) => {
718
+ let t = H(e), n = s(e, "--to"), r = await at(await V(t, it), B);
719
+ if (r.length === 0) return B.info("no migrations found", { root: t }), 0;
720
+ let i = await lt(r, await q(), B, n ? { to: n } : {});
721
+ return i.failed ? (process.stderr.write(dt(i) + "\n"), 1) : (B.info("rollback complete", { reverted: i.applied.length }), 0);
717
722
  }, Mt = async (e) => {
718
- let t = V(e), n = s(e, "--to"), r = await ot(await B(t, at), z);
719
- if (r.length === 0) return z.info("no migrations found", { root: t }), 0;
720
- let i = await ut(r, await K(), z, n ? { to: n } : {});
721
- return i.failed ? (process.stderr.write(ft(i) + "\n"), 1) : (z.info("rollback complete", { reverted: i.applied.length }), 0);
722
- }, Nt = async (e) => {
723
- let t = await ot(await B(V(e), at), z);
723
+ let t = await at(await V(H(e), it), B);
724
724
  if (t.length === 0) return console.log("no migrations found"), 0;
725
- let n = await dt(t, await K());
725
+ let n = await ut(t, await q());
726
726
  for (let e of n) {
727
727
  let t = e.status === "applied" ? "✓" : e.status === "failed" ? "✗" : e.status === "reverted" ? "↩" : "·", n = e.hashMatches ? "" : " (hash drift!)", r = e.appliedAt ? ` @ ${e.appliedAt.toISOString()}` : "";
728
728
  console.log(` ${t} ${e.id} [${e.status}] ${e.name}${r}${n}`);
729
729
  }
730
730
  return 0;
731
- }, Pt = async (e) => {
731
+ }, Nt = async (e) => {
732
732
  let t = (s(e, "--store") ?? process.env.DB_DIALECT ?? "postgres").toLowerCase();
733
- if (t === "memory") return z.warn("voltro db seed: using in-memory store (explicit opt-in via --store memory / DB_DIALECT=memory)"), z.warn(" rows written by this run will NOT persist beyond the process. set DB_DIALECT=postgres or unset to seed the real DB."), {
734
- store: new Me(),
733
+ if (t === "memory") return B.warn("voltro db seed: using in-memory store (explicit opt-in via --store memory / DB_DIALECT=memory)"), B.warn(" rows written by this run will NOT persist beyond the process. set DB_DIALECT=postgres or unset to seed the real DB."), {
734
+ store: new je(),
735
735
  dispose: async () => {},
736
736
  dialectId: "memory"
737
737
  };
738
738
  let n = await l(t);
739
- z.info(`voltro db seed: target store=${n.id} — rows will persist`);
739
+ B.info(`voltro db seed: target store=${n.id} — rows will persist`);
740
740
  let r = await n.makeStore({
741
- sqlLayer: n.makeSqlLayer(H()),
741
+ sqlLayer: n.makeSqlLayer(U()),
742
742
  changeStrategy: "inline"
743
743
  }), i = r;
744
744
  return {
@@ -748,12 +748,12 @@ var Fe = (e) => typeof e != "string", Ie = (e, t, n, r) => {
748
748
  },
749
749
  dialectId: n.id
750
750
  };
751
- }, Ft = async (e) => {
752
- let t = V(e), n = s(e, "--id"), r = s(e, "--lifecycle"), i = await B(t, b), a = await f(i, z);
753
- if (a.length === 0) return z.info("no seeds found", { root: t }), 0;
754
- let { store: o, dispose: c, dialectId: l } = await Pt(e);
751
+ }, Pt = async (e) => {
752
+ let t = H(e), n = s(e, "--id"), r = s(e, "--lifecycle"), i = await V(t, b), a = await f(i, B);
753
+ if (a.length === 0) return B.info("no seeds found", { root: t }), 0;
754
+ let { store: o, dispose: c, dialectId: l } = await Nt(e);
755
755
  try {
756
- if (n) return +((await d(a, n, o, z)).status === "failed");
756
+ if (n) return +((await d(a, n, o, B)).status === "failed");
757
757
  let e = r ? a.filter((e) => e.definition.lifecycle === r) : a.filter((e) => e.definition.lifecycle === "boot");
758
758
  return +((await p(e.map((e) => ({
759
759
  ...e,
@@ -761,66 +761,66 @@ var Fe = (e) => typeof e != "string", Ie = (e, t, n, r) => {
761
761
  ...e.definition,
762
762
  lifecycle: "boot"
763
763
  }
764
- })), o, z, { force: !0 })).filter((e) => e.status === "failed").length > 0);
764
+ })), o, B, { force: !0 })).filter((e) => e.status === "failed").length > 0);
765
765
  } finally {
766
766
  await c().catch((e) => {
767
- z.warn("voltro db seed: store dispose failed", { error: String(e) });
767
+ B.warn("voltro db seed: store dispose failed", { error: String(e) });
768
768
  });
769
769
  }
770
- }, It = (e) => typeof e == "object" && !!e && "tableName" in e && "fields" in e && typeof e.tableName == "string", Lt = async (e) => {
771
- let t = await B(e, y), n = [];
770
+ }, Ft = (e) => typeof e == "object" && !!e && "tableName" in e && "fields" in e && typeof e.tableName == "string", It = async (e) => {
771
+ let t = await V(e, y), n = [];
772
772
  for (let r of t) {
773
773
  let t;
774
774
  try {
775
775
  t = await import(D(r).href);
776
776
  } catch (t) {
777
- z.warn("db: failed to import schema file", {
777
+ B.warn("db: failed to import schema file", {
778
778
  file: w(e, r),
779
779
  error: String(t)
780
780
  });
781
781
  continue;
782
782
  }
783
- for (let e of Object.values(t)) It(e) && n.push(e);
783
+ for (let e of Object.values(t)) Ft(e) && n.push(e);
784
784
  }
785
785
  return n;
786
- }, Rt = (e) => {
786
+ }, Lt = (e) => {
787
787
  let t = new Map(e.map((e) => [e.tableName, e]));
788
- t.has("actors") || t.set("actors", ye);
788
+ t.has("actors") || t.set("actors", ve);
789
789
  let n = t.get("actors"), r = t.get("tenants");
790
- return ke({
790
+ return Oe({
791
791
  actors: () => n,
792
792
  ...r === void 0 ? {} : { tenants: () => r }
793
793
  }), [...t.values()];
794
- }, zt = (e) => {
794
+ }, Rt = (e) => {
795
795
  let t = /* @__PURE__ */ new Map();
796
796
  for (let n of e) {
797
797
  let e = n.tableName;
798
798
  e !== void 0 && !t.has(e) && t.set(e, n);
799
799
  }
800
800
  return [...t.values()];
801
- }, Bt = (e) => {
801
+ }, zt = (e) => {
802
802
  let t = se(process.env.VOLTRO_DESTRUCTIVE_OK);
803
803
  if (t === void 0 || !e.operations.filter((e) => e.blocked).every((e) => e.classification === "lossy")) return {
804
804
  plan: e,
805
805
  acknowledged: !1
806
806
  };
807
- let n = ve(e, t);
807
+ let n = _e(e, t);
808
808
  return {
809
809
  plan: n,
810
810
  acknowledged: !n.operations.some((e) => e.blocked)
811
811
  };
812
- }, q = async (e, t) => k.runPromise(t.pipe(k.provide(e))), J = async (e) => {
812
+ }, J = async (e, t) => k.runPromise(t.pipe(k.provide(e))), Y = async (e) => {
813
813
  try {
814
- return await q(e, A.SqlClient.pipe(k.flatMap(ue)));
814
+ return await J(e, A.SqlClient.pipe(k.flatMap(N)));
815
815
  } catch (e) {
816
816
  let t = String(e?.message ?? e);
817
- if (kt(e) || /connection error/i.test(t)) {
818
- let n = /* @__PURE__ */ Error(`${At}\n\nOriginal error: ${t}`);
817
+ if (Ot(e) || /connection error/i.test(t)) {
818
+ let n = /* @__PURE__ */ Error(`${kt}\n\nOriginal error: ${t}`);
819
819
  throw n.cause = e, n;
820
820
  }
821
821
  throw e;
822
822
  }
823
- }, Vt = {
823
+ }, Bt = {
824
824
  safe: "\x1B[32m✓\x1B[0m",
825
825
  "needs-default": "\x1B[32m⊕\x1B[0m",
826
826
  "needs-backfill": "\x1B[33m⊕\x1B[0m",
@@ -828,7 +828,7 @@ var Fe = (e) => typeof e != "string", Ie = (e, t, n, r) => {
828
828
  lossy: "\x1B[31m✗\x1B[0m",
829
829
  "online-required": "\x1B[36m◷\x1B[0m",
830
830
  "multi-step": "\x1B[35m⇉\x1B[0m"
831
- }, Ht = (e) => {
831
+ }, Vt = (e) => {
832
832
  let t = e.op, n;
833
833
  switch (t.kind) {
834
834
  case "create-table":
@@ -890,9 +890,9 @@ var Fe = (e) => typeof e != "string", Ie = (e, t, n, r) => {
890
890
  break;
891
891
  case "drop-check": n = `ALTER TABLE ${t.table} DROP CHECK ${t.column}`;
892
892
  }
893
- let r = Vt[e.classification], i = e.reason ? ` # ${e.reason}` : "", a = e.blocked ? `\n ! ${e.blocked.fix}` : "";
893
+ let r = Bt[e.classification], i = e.reason ? ` # ${e.reason}` : "", a = e.blocked ? `\n ! ${e.blocked.fix}` : "";
894
894
  return ` ${r} ${n}${i}${a}`;
895
- }, Ut = async (e, t) => {
895
+ }, Ht = async (e, t) => {
896
896
  let n = e.operations.filter((e) => e.classification === "needs-default" && e.op.kind === "add-column");
897
897
  if (n.length === 0) return;
898
898
  let r = [];
@@ -901,7 +901,7 @@ var Fe = (e) => typeof e != "string", Ie = (e, t, n, r) => {
901
901
  if (i === void 0 || a === void 0) continue;
902
902
  let o = 0;
903
903
  try {
904
- let e = await q(t, A.SqlClient.pipe(k.flatMap((e) => e.unsafe(`SELECT COUNT(*) AS n FROM ${Oe(i, U())}`))));
904
+ let e = await J(t, A.SqlClient.pipe(k.flatMap((e) => e.unsafe(`SELECT COUNT(*) AS n FROM ${De(i, W())}`))));
905
905
  o = Number(Object.values(e[0] ?? { n: 0 })[0] ?? 0);
906
906
  } catch {
907
907
  continue;
@@ -913,86 +913,86 @@ var Fe = (e) => typeof e != "string", Ie = (e, t, n, r) => {
913
913
  for (let e of r) console.log(e);
914
914
  console.log(" (the shape is correct either way — this is the VALUE a state diff cannot know)");
915
915
  }
916
- }, Wt = async (e, t) => {
917
- if (U() !== "postgres") return;
916
+ }, Ut = async (e, t) => {
917
+ if (W() !== "postgres") return;
918
918
  let n = j, r;
919
919
  try {
920
- r = await q(t, A.SqlClient.pipe(k.flatMap((t) => m(t, e, n))));
920
+ r = await J(t, A.SqlClient.pipe(k.flatMap((t) => m(t, e, n))));
921
921
  } catch {
922
922
  return;
923
923
  }
924
924
  let { drift: i, statements: a } = r;
925
925
  if (a.length === 0) return;
926
- z.info(i.missing.length + i.stale.length > 0 ? `db apply: installing change triggers on ${i.missing.length} table(s)` + (i.stale.length > 0 ? `, removing ${i.stale.length} stale one(s)` : "") + (i.functionOutdated ? ", replacing an outdated notify function" : "") : "db apply: replacing an outdated change-notify function (no table drift)");
926
+ B.info(i.missing.length + i.stale.length > 0 ? `db apply: installing change triggers on ${i.missing.length} table(s)` + (i.stale.length > 0 ? `, removing ${i.stale.length} stale one(s)` : "") + (i.functionOutdated ? ", replacing an outdated notify function" : "") : "db apply: replacing an outdated change-notify function (no table drift)");
927
927
  let o = 0;
928
- for (let e of a) await q(t, A.SqlClient.pipe(k.flatMap((t) => t.unsafe(e)))), o += 1;
929
- z.info(`db apply: change triggers converged (${o} statement(s))`, {
928
+ for (let e of a) await J(t, A.SqlClient.pipe(k.flatMap((t) => t.unsafe(e)))), o += 1;
929
+ B.info(`db apply: change triggers converged (${o} statement(s))`, {
930
930
  installed: i.missing.length,
931
931
  removed: i.stale.length,
932
932
  functionReplaced: i.functionOutdated
933
933
  });
934
- }, Y = (e) => {
934
+ }, X = (e) => {
935
935
  let t = e.summary, n = e.operations.length;
936
936
  if (console.log(`\nschema diff: ${n} operation${n === 1 ? "" : "s"}, ${t.blocked} blocked\n`), n === 0) {
937
937
  console.log(" (schema is up to date)\n");
938
938
  return;
939
939
  }
940
- for (let t of e.operations) console.log(Ht(t));
941
- console.log(), console.log(` safe: ${t.safe} needs-default: ${t.needsDefault} needs-backfill: ${t.needsBackfill}`), console.log(` rename: ${t.needsRenameAnnotation} lossy: ${t.lossy} blocked: ${t.blocked}`), console.log(` fingerprint: ${e.fromFingerprint.slice(0, 16)} → ${e.toFingerprint.slice(0, 16)}\n`), Gt(e);
942
- }, Gt = (e) => {
943
- let t = he(e.operations);
940
+ for (let t of e.operations) console.log(Vt(t));
941
+ console.log(), console.log(` safe: ${t.safe} needs-default: ${t.needsDefault} needs-backfill: ${t.needsBackfill}`), console.log(` rename: ${t.needsRenameAnnotation} lossy: ${t.lossy} blocked: ${t.blocked}`), console.log(` fingerprint: ${e.fromFingerprint.slice(0, 16)} → ${e.toFingerprint.slice(0, 16)}\n`), Wt(e);
942
+ }, Wt = (e) => {
943
+ let t = me(e.operations);
944
944
  if (t.length !== 0) {
945
945
  console.log(` ⚠ ${t.length} operation(s) UNSAFE under a rolling deploy`), console.log(" (old + new instances overlap → old code breaks against the new schema):");
946
946
  for (let e of t) console.log(` • ${e.op.op.kind}: ${e.reason}`), console.log(` → ${e.remedy}`);
947
947
  console.log(" Deploy with a maintenance window / scale-to-zero, or split into"), console.log(" expand → deploy → contract. See docs: deployment/production-hardening.\n");
948
948
  }
949
- }, Kt = (e, t) => {
949
+ }, Gt = (e, t) => {
950
950
  let n = ie({
951
951
  enabled: process.env.VOLTRO_ROLLING_DEPLOY === "1",
952
952
  forced: t.includes("--force"),
953
- unsafeCount: he(e.operations).length
953
+ unsafeCount: me(e.operations).length
954
954
  });
955
- return n.refuse ? (z.error(`db apply: ${n.message}`), !0) : (n.warnForced && z.warn(`db apply: ${n.message}`), !1);
956
- }, qt = (e) => {
955
+ return n.refuse ? (B.error(`db apply: ${n.message}`), !0) : (n.warnForced && B.warn(`db apply: ${n.message}`), !1);
956
+ }, Kt = (e) => {
957
957
  let t = s(e, "--online-after") ?? process.env.VOLTRO_ONLINE_THRESHOLD;
958
958
  if (t === void 0) return;
959
959
  let n = Number(t);
960
960
  if (!Number.isInteger(n) || n < 0) throw Error(`--online-after / VOLTRO_ONLINE_THRESHOLD must be a non-negative integer, got "${t}"`);
961
961
  return n;
962
- }, X = async (e) => {
963
- let t = await Lt(e);
962
+ }, Z = async (e) => {
963
+ let t = await It(e);
964
964
  if (t.length === 0) return;
965
965
  let n = await g({ root: e });
966
- return Rt(zt([
966
+ return Lt(Rt([
967
967
  ...t,
968
- ...Ce,
968
+ ...Se,
969
969
  ...n
970
970
  ]));
971
- }, Z = async (e, t, n) => {
971
+ }, Q = async (e, t, n) => {
972
972
  let r;
973
973
  try {
974
974
  let t = await _(e);
975
- await q(n, v(t, (e, t) => {
976
- z.info(`db apply: ${e}`, t ?? {});
975
+ await J(n, v(t, (e, t) => {
976
+ B.info(`db apply: ${e}`, t ?? {});
977
977
  }));
978
978
  } catch (e) {
979
979
  r = e;
980
980
  }
981
- return await Wt(t, n), r === void 0 ? 0 : (z.error("db apply: a plugin migration FAILED — the schema was applied, the plugin steps were not", { error: r instanceof Error ? r.message : String(r) }), 1);
982
- }, Jt = async (e, t) => {
983
- let n = { close: async () => {} }, r = await B(e, b);
981
+ return await Ut(t, n), r === void 0 ? 0 : (B.error("db apply: a plugin migration FAILED — the schema was applied, the plugin steps were not", { error: r instanceof Error ? r.message : String(r) }), 1);
982
+ }, qt = async (e, t) => {
983
+ let n = { close: async () => {} }, r = await V(e, b);
984
984
  if (r.length === 0) return n;
985
- let i = await f(r, z), a = i.filter((e) => e.definition.lifecycle === "onSchemaChange");
985
+ let i = await f(r, B), a = i.filter((e) => e.definition.lifecycle === "onSchemaChange");
986
986
  if (a.length === 0) return n;
987
- let { store: o, dispose: s } = await Pt(t), c = h(i, o, z.child("seeds"));
988
- return z.info(`db apply: ${a.length} onSchemaChange seed(s) armed for this apply`, { ids: a.map((e) => e.definition.id) }), { close: async () => {
987
+ let { store: o, dispose: s } = await Nt(t), c = h(i, o, B.child("seeds"));
988
+ return B.info(`db apply: ${a.length} onSchemaChange seed(s) armed for this apply`, { ids: a.map((e) => e.definition.id) }), { close: async () => {
989
989
  c(), await s().catch((e) => {
990
- z.warn("db apply: seed store dispose failed", { error: String(e) });
990
+ B.warn("db apply: seed store dispose failed", { error: String(e) });
991
991
  });
992
992
  } };
993
- }, Yt = async (e) => {
994
- let t = qt(e), n = V(e), r = await X(n);
995
- if (r === void 0) return z.warn("db plan: no schema files found", {
993
+ }, Jt = async (e) => {
994
+ let t = Kt(e), n = H(e), r = await Z(n);
995
+ if (r === void 0) return B.warn("db plan: no schema files found", {
996
996
  root: n,
997
997
  hint: "looked for *.entity.ts / *.schema.ts / schema.ts"
998
998
  }), 1;
@@ -1002,133 +1002,133 @@ var Fe = (e) => typeof e != "string", Ie = (e, t, n, r) => {
1002
1002
  a && (o.authorization = `Bearer ${a}`);
1003
1003
  try {
1004
1004
  let e = n.endsWith("/_voltro/inspect/migrations") ? n : `${n.replace(/\/+$/, "")}/_voltro/inspect/migrations`, i = await fetch(e, { headers: o });
1005
- if (!i.ok) return z.error(`db plan --against: remote returned ${i.status}`, { url: e }), x(i.status) && console.error(` ${S(i.status)}`), 1;
1005
+ if (!i.ok) return B.error(`db plan --against: remote returned ${i.status}`, { url: e }), x(i.status) && console.error(` ${S(i.status)}`), 1;
1006
1006
  let a = (await i.json()).drift?.liveSnapshot;
1007
- if (!a) return z.error("db plan --against: remote inspect payload missing drift.liveSnapshot", { url: e }), 1;
1008
- let s = N({
1007
+ if (!a) return B.error("db plan --against: remote inspect payload missing drift.liveSnapshot", { url: e }), 1;
1008
+ let s = P({
1009
1009
  declared: r,
1010
1010
  live: a,
1011
- dialect: U(),
1011
+ dialect: W(),
1012
1012
  ...M(),
1013
1013
  ...t === void 0 ? {} : { onlineAfter: t }
1014
1014
  });
1015
- return console.log(`\n[--against ${e}] — diff vs remote live schema:\n`), Y(s), s.summary.blocked > 0 ? 2 : 0;
1015
+ return console.log(`\n[--against ${e}] — diff vs remote live schema:\n`), X(s), s.summary.blocked > 0 ? 2 : 0;
1016
1016
  } catch (e) {
1017
- return z.error(`db plan --against: ${e.message}`), 1;
1017
+ return B.error(`db plan --against: ${e.message}`), 1;
1018
1018
  }
1019
1019
  }
1020
- let a = await J(await K()), o = N({
1020
+ let a = await Y(await q()), o = P({
1021
1021
  declared: r,
1022
1022
  live: a,
1023
- dialect: U(),
1023
+ dialect: W(),
1024
1024
  ...M(),
1025
1025
  ...t === void 0 ? {} : { onlineAfter: t }
1026
1026
  });
1027
- return e.includes("--json") ? (te(1, `${JSON.stringify(o, null, 2)}\n`), o.summary.blocked > 0 ? 2 : 0) : (Y(o), o.summary.blocked > 0 ? 2 : 0);
1028
- }, Q = n, Xt = async (e, t, n) => {
1027
+ return e.includes("--json") ? (te(1, `${JSON.stringify(o, null, 2)}\n`), o.summary.blocked > 0 ? 2 : 0) : (X(o), o.summary.blocked > 0 ? 2 : 0);
1028
+ }, $ = n, Yt = async (e, t, n) => {
1029
1029
  let r;
1030
1030
  try {
1031
1031
  let t = await E.readFile(T(e), "utf8");
1032
1032
  r = JSON.parse(t);
1033
1033
  } catch (t) {
1034
- return z.error(`db apply --plan: cannot read/parse plan file '${e}': ${t.message}`), 1;
1034
+ return B.error(`db apply --plan: cannot read/parse plan file '${e}': ${t.message}`), 1;
1035
1035
  }
1036
- if (!Array.isArray(r?.operations) || typeof r?.fromFingerprint != "string" || typeof r?.toFingerprint != "string") return z.error(`db apply --plan: '${e}' is not a valid plan file (expected the output of \`voltro db plan --json\`).`), 1;
1037
- let i = await X(n);
1038
- if (i === void 0) return z.warn("db apply --plan: no schema files found", { root: n }), 1;
1039
- let a = await K(), o = await q(a, A.SqlClient.pipe(k.flatMap((e) => de(e, n)))).catch(() => []);
1040
- if (o.length > 0) return z.error(`db apply --plan: refusing — ${o.length} pending file-based migration(s).`), console.error(` ${o.join("\n ")}`), console.error(""), console.error(" These perform the changes a state diff cannot infer, so they change the shape"), console.error(" this plan was computed against. Apply them and regenerate the plan:"), console.error(""), console.error(" voltro db files ."), console.error(" voltro db plan --json > plan.json"), console.error(" voltro db apply --plan plan.json"), 1;
1041
- let c = await J(a), l = N({
1036
+ if (!Array.isArray(r?.operations) || typeof r?.fromFingerprint != "string" || typeof r?.toFingerprint != "string") return B.error(`db apply --plan: '${e}' is not a valid plan file (expected the output of \`voltro db plan --json\`).`), 1;
1037
+ let i = await Z(n);
1038
+ if (i === void 0) return B.warn("db apply --plan: no schema files found", { root: n }), 1;
1039
+ let a = await q(), o = await J(a, A.SqlClient.pipe(k.flatMap((e) => ue(e, n)))).catch(() => []);
1040
+ if (o.length > 0) return B.error(`db apply --plan: refusing — ${o.length} pending file-based migration(s).`), console.error(` ${o.join("\n ")}`), console.error(""), console.error(" These perform the changes a state diff cannot infer, so they change the shape"), console.error(" this plan was computed against. Apply them and regenerate the plan:"), console.error(""), console.error(" voltro db files ."), console.error(" voltro db plan --json > plan.json"), console.error(" voltro db apply --plan plan.json"), 1;
1041
+ let c = await Y(a), l = P({
1042
1042
  declared: i,
1043
1043
  live: c,
1044
- dialect: U(),
1044
+ dialect: W(),
1045
1045
  ...M()
1046
1046
  });
1047
- if (l.fromFingerprint !== r.fromFingerprint) return z.error("db apply --plan: refusing — the live schema has drifted since this plan was generated."), console.error(` plan.from=${r.fromFingerprint.slice(0, 16)} live=${l.fromFingerprint.slice(0, 16)}`), console.error(" Regenerate against the current live schema: `voltro db plan --json > plan.json`"), 2;
1048
- if (l.toFingerprint !== r.toFingerprint) return z.error("db apply --plan: refusing — the declared schema differs from what this plan targets."), console.error(` plan.to=${r.toFingerprint.slice(0, 16)} declared=${l.toFingerprint.slice(0, 16)}`), console.error(" The schema files changed since the plan was generated. Regenerate the plan."), 2;
1049
- let u = Bt(l), d = u.plan;
1050
- if (d.summary.blocked > 0 && !u.acknowledged) return Y(d), z.error(`db apply --plan: refusing — ${l.summary.blocked} blocked operation(s). See the fix hints above.`), process.env.VOLTRO_DESTRUCTIVE_OK !== void 0 && (z.error(" VOLTRO_DESTRUCTIVE_OK is set but did not cover this plan — it only relaxes"), z.error(" `lossy` operations, and only the tables it names. Anything else stays refused.")), 2;
1051
- if (u.acknowledged && z.warn("db apply --plan: proceeding with acknowledged lossy operation(s) (VOLTRO_DESTRUCTIVE_OK)"), Kt(d, t)) return 2;
1047
+ if (l.fromFingerprint !== r.fromFingerprint) return B.error("db apply --plan: refusing — the live schema has drifted since this plan was generated."), console.error(` plan.from=${r.fromFingerprint.slice(0, 16)} live=${l.fromFingerprint.slice(0, 16)}`), console.error(" Regenerate against the current live schema: `voltro db plan --json > plan.json`"), 2;
1048
+ if (l.toFingerprint !== r.toFingerprint) return B.error("db apply --plan: refusing — the declared schema differs from what this plan targets."), console.error(` plan.to=${r.toFingerprint.slice(0, 16)} declared=${l.toFingerprint.slice(0, 16)}`), console.error(" The schema files changed since the plan was generated. Regenerate the plan."), 2;
1049
+ let u = zt(l), d = u.plan;
1050
+ if (d.summary.blocked > 0 && !u.acknowledged) return X(d), B.error(`db apply --plan: refusing — ${l.summary.blocked} blocked operation(s). See the fix hints above.`), process.env.VOLTRO_DESTRUCTIVE_OK !== void 0 && (B.error(" VOLTRO_DESTRUCTIVE_OK is set but did not cover this plan — it only relaxes"), B.error(" `lossy` operations, and only the tables it names. Anything else stays refused.")), 2;
1051
+ if (u.acknowledged && B.warn("db apply --plan: proceeding with acknowledged lossy operation(s) (VOLTRO_DESTRUCTIVE_OK)"), Gt(d, t)) return 2;
1052
1052
  if (d.operations.length === 0) {
1053
- let e = await q(a, A.SqlClient.pipe(k.flatMap((e) => fe(e, d, {
1053
+ let e = await J(a, A.SqlClient.pipe(k.flatMap((e) => de(e, d, {
1054
1054
  appliedBy: process.env.USER ? `cli:${process.env.USER}` : "cli:plan",
1055
- environment: Q(),
1055
+ environment: $(),
1056
1056
  source: "file"
1057
1057
  }))));
1058
- return z.info(e === "recorded" ? `db apply --plan: schema is up to date — no DDL to apply, recorded fingerprint=${d.toFingerprint.slice(0, 16)} (change triggers are reconciled separately below)` : "db apply --plan: schema is up to date — no DDL to apply (change triggers are reconciled separately below)"), Z(n, i, a);
1058
+ return B.info(e === "recorded" ? `db apply --plan: schema is up to date — no DDL to apply, recorded fingerprint=${d.toFingerprint.slice(0, 16)} (change triggers are reconciled separately below)` : "db apply --plan: schema is up to date — no DDL to apply (change triggers are reconciled separately below)"), Q(n, i, a);
1059
1059
  }
1060
- Y(d);
1061
- let f = s(t, "--note"), p = await q(a, A.SqlClient.pipe(k.flatMap((e) => ne(e, d, {
1060
+ X(d);
1061
+ let f = s(t, "--note"), p = await J(a, A.SqlClient.pipe(k.flatMap((e) => ne(e, d, {
1062
1062
  declared: i,
1063
1063
  appliedBy: process.env.USER ? `cli:${process.env.USER}` : "cli:plan",
1064
- environment: Q(),
1064
+ environment: $(),
1065
1065
  source: "file",
1066
1066
  ...f ? { notes: f } : {},
1067
- replan: () => k.promise(() => J(a)).pipe(k.map((e) => N({
1067
+ replan: (e) => N(e).pipe(k.map((e) => P({
1068
1068
  declared: i,
1069
1069
  live: e,
1070
- dialect: U(),
1070
+ dialect: W(),
1071
1071
  ...M()
1072
1072
  })))
1073
1073
  }))));
1074
- return z.info(`db apply --plan: applied ${p.appliedOps} op(s) in ${p.durationMs}ms`, {
1074
+ return B.info(`db apply --plan: applied ${p.appliedOps} op(s) in ${p.durationMs}ms`, {
1075
1075
  id: p.id,
1076
1076
  fingerprint: p.fingerprint.slice(0, 16)
1077
- }), Z(n, i, a);
1078
- }, Zt = async (e) => {
1079
- let t = V(e), n = await Jt(t, e);
1077
+ }), Q(n, i, a);
1078
+ }, Xt = async (e) => {
1079
+ let t = H(e), n = await qt(t, e);
1080
1080
  try {
1081
- return await Qt(e, t);
1081
+ return await Zt(e, t);
1082
1082
  } finally {
1083
1083
  await n.close();
1084
1084
  }
1085
- }, Qt = async (e, n) => {
1086
- let r = qt(e), i = s(e, "--plan");
1087
- if (i) return Xt(i, e, n);
1088
- if ((process.env.NODE_ENV ?? "").toLowerCase() === "production") return z.error(`voltro db apply: refusing — auto-apply on prod is not allowed.${t()}`), console.error("In production, schema changes go through `voltro db plan --json > plan.json`"), console.error("then `voltro db apply --plan plan.json` as an explicit step in your deploy pipeline."), 3;
1089
- let a = await X(n);
1090
- if (a === void 0) return z.warn("db apply: no schema files found", { root: n }), 1;
1091
- let o = await K(), c = await hn(n, o);
1092
- if ("failed" in c) return z.error("db apply: a file-based migration FAILED — the schema diff was NOT run"), console.error(c.failed), console.error("Fix the migration and re-run. `voltro db files` runs them alone."), 1;
1093
- let l = await J(o), u = N({
1085
+ }, Zt = async (e, n) => {
1086
+ let r = Kt(e), i = s(e, "--plan");
1087
+ if (i) return Yt(i, e, n);
1088
+ if ((process.env.NODE_ENV ?? "").toLowerCase() === "production") return B.error(`voltro db apply: refusing — auto-apply on prod is not allowed.${t()}`), console.error("In production, schema changes go through `voltro db plan --json > plan.json`"), console.error("then `voltro db apply --plan plan.json` as an explicit step in your deploy pipeline."), 3;
1089
+ let a = await Z(n);
1090
+ if (a === void 0) return B.warn("db apply: no schema files found", { root: n }), 1;
1091
+ let o = await q(), c = await mn(n, o);
1092
+ if ("failed" in c) return B.error("db apply: a file-based migration FAILED — the schema diff was NOT run"), console.error(c.failed), console.error("Fix the migration and re-run. `voltro db files` runs them alone."), 1;
1093
+ let l = await Y(o), u = P({
1094
1094
  declared: a,
1095
1095
  live: l,
1096
- dialect: U(),
1096
+ dialect: W(),
1097
1097
  ...M(),
1098
1098
  ...r === void 0 ? {} : { onlineAfter: r }
1099
1099
  });
1100
- Y(u), await Ut(u, o);
1101
- let d = Bt(u), f = d.plan;
1102
- if (f.summary.blocked > 0 && !d.acknowledged) return z.error(`db apply: refusing — ${f.summary.blocked} blocked operation(s). See the fix hints above.`), process.env.VOLTRO_DESTRUCTIVE_OK !== void 0 && (z.error(" VOLTRO_DESTRUCTIVE_OK is set but did not cover this plan — it only relaxes"), z.error(" `lossy` operations, and only the tables it names. Anything else stays refused.")), 2;
1103
- if (d.acknowledged && z.warn(`db apply: proceeding with ${u.summary.blocked} acknowledged lossy operation(s) (VOLTRO_DESTRUCTIVE_OK)`), Kt(f, e)) return 2;
1100
+ X(u), await Ht(u, o);
1101
+ let d = zt(u), f = d.plan;
1102
+ if (f.summary.blocked > 0 && !d.acknowledged) return B.error(`db apply: refusing — ${f.summary.blocked} blocked operation(s). See the fix hints above.`), process.env.VOLTRO_DESTRUCTIVE_OK !== void 0 && (B.error(" VOLTRO_DESTRUCTIVE_OK is set but did not cover this plan — it only relaxes"), B.error(" `lossy` operations, and only the tables it names. Anything else stays refused.")), 2;
1103
+ if (d.acknowledged && B.warn(`db apply: proceeding with ${u.summary.blocked} acknowledged lossy operation(s) (VOLTRO_DESTRUCTIVE_OK)`), Gt(f, e)) return 2;
1104
1104
  if (f.operations.length === 0) {
1105
- z.info("db apply: schema is up to date — no DDL to apply (change triggers are reconciled separately below)");
1106
- let t = await q(o, A.SqlClient.pipe(k.flatMap((e) => fe(e, f, {
1105
+ B.info("db apply: schema is up to date — no DDL to apply (change triggers are reconciled separately below)");
1106
+ let t = await J(o, A.SqlClient.pipe(k.flatMap((e) => de(e, f, {
1107
1107
  appliedBy: process.env.USER ? `cli:${process.env.USER}` : "cli:apply",
1108
- environment: Q(),
1108
+ environment: $(),
1109
1109
  source: "auto-diff"
1110
1110
  }))));
1111
- return t === "recorded" && z.info(`db apply: recorded fingerprint=${f.toFingerprint.slice(0, 16)} (0 operations)`), await un(o), s(e, "--note") !== void 0 && t !== "recorded" && (z.warn("db apply: --note was ignored — this schema is already the latest recorded one, so there is no new history row to attach it to."), console.error("To record that the CURRENT live schema is the accepted baseline, use `voltro db drift --accept`.")), Z(n, a, o);
1111
+ return t === "recorded" && B.info(`db apply: recorded fingerprint=${f.toFingerprint.slice(0, 16)} (0 operations)`), await ln(o), s(e, "--note") !== void 0 && t !== "recorded" && (B.warn("db apply: --note was ignored — this schema is already the latest recorded one, so there is no new history row to attach it to."), console.error("To record that the CURRENT live schema is the accepted baseline, use `voltro db drift --accept`.")), Q(n, a, o);
1112
1112
  }
1113
- let p = s(e, "--note"), m = await q(o, A.SqlClient.pipe(k.flatMap((e) => ne(e, f, {
1113
+ let p = s(e, "--note"), m = await J(o, A.SqlClient.pipe(k.flatMap((e) => ne(e, f, {
1114
1114
  declared: a,
1115
1115
  appliedBy: process.env.USER ? `cli:${process.env.USER}` : "cli:user",
1116
- environment: Q(),
1116
+ environment: $(),
1117
1117
  source: "auto-diff",
1118
1118
  ...p ? { notes: p } : {},
1119
- replan: () => k.promise(() => J(o)).pipe(k.map((e) => N({
1119
+ replan: (e) => N(e).pipe(k.map((e) => P({
1120
1120
  declared: a,
1121
1121
  live: e,
1122
- dialect: U(),
1122
+ dialect: W(),
1123
1123
  ...M(),
1124
1124
  ...r === void 0 ? {} : { onlineAfter: r }
1125
1125
  })))
1126
1126
  }))));
1127
- return z.info(`db apply: applied ${m.appliedOps} op(s) in ${m.durationMs}ms`, {
1127
+ return B.info(`db apply: applied ${m.appliedOps} op(s) in ${m.durationMs}ms`, {
1128
1128
  id: m.id,
1129
1129
  fingerprint: m.fingerprint.slice(0, 16)
1130
- }), Z(n, a, o);
1131
- }, $t = (e) => {
1130
+ }), Q(n, a, o);
1131
+ }, Qt = (e) => {
1132
1132
  let t = [];
1133
1133
  for (let n of e.tables) for (let e of n.columns) {
1134
1134
  let r = e.references;
@@ -1141,7 +1141,7 @@ var Fe = (e) => typeof e != "string", Ie = (e, t, n, r) => {
1141
1141
  });
1142
1142
  }
1143
1143
  return t;
1144
- }, en = (e) => {
1144
+ }, $t = (e) => {
1145
1145
  let t = [];
1146
1146
  for (let n of e.tables) for (let e of n.indexes) e.expression !== !0 && e.name !== `${n.name}_pkey` && e.columns.length !== 0 && t.push({
1147
1147
  table: n.name,
@@ -1150,7 +1150,7 @@ var Fe = (e) => typeof e != "string", Ie = (e, t, n, r) => {
1150
1150
  name: e.name
1151
1151
  });
1152
1152
  return t;
1153
- }, tn = (e, t) => {
1153
+ }, en = (e, t) => {
1154
1154
  let n = (e) => JSON.stringify(e.op), r = new Set(e.operations.map(n)), i = new Set(t.operations.map(n)), a = [...t.operations.filter((e) => !r.has(n(e))), ...e.operations.filter((e) => !i.has(n(e)))];
1155
1155
  return {
1156
1156
  ...t,
@@ -1160,57 +1160,57 @@ var Fe = (e) => typeof e != "string", Ie = (e, t, n, r) => {
1160
1160
  blocked: 0
1161
1161
  }
1162
1162
  };
1163
- }, nn = (e) => {
1163
+ }, tn = (e) => {
1164
1164
  if (e === void 0) return "empty";
1165
1165
  if (e === "empty" || e === "copy") return e;
1166
1166
  throw e === "fresh" ? new r("voltro db branch: --seed fresh is not implemented — the branch lifecycle has no executor step that runs boot seeds, so the branch would come up EMPTY while this reported it as seeded. Use --seed copy (the parent's rows) or --seed empty (schema only).") : new r(`voltro db branch: --seed must be one of empty|copy, got "${e}"`);
1167
- }, rn = (e) => {
1167
+ }, nn = (e) => {
1168
1168
  if (e !== void 0) {
1169
1169
  if (e === "namespace" || e === "neon-cow") return e;
1170
1170
  throw new r(`voltro db branch: --prefer must be one of namespace|neon-cow, got "${e}"`);
1171
1171
  }
1172
- }, an = async (e) => {
1173
- let t = V(e), n = nn(s(e, "--seed")), i = rn(s(e, "--prefer")), a = e.includes("--keep"), o = e.includes("--json"), c = qt(e), u = U();
1174
- if (u !== "postgres") return z.error(`voltro db branch: not supported on '${u}'.`), console.error(" The branch PLAN is dialect-agnostic; the shipped namespace EXECUTOR is Postgres-only"), console.error(" (CREATE SCHEMA / CREATE TABLE … LIKE … INCLUDING ALL / \"-quoted identifiers)."), console.error(" MySQL, MariaDB, SQLite and SQL Server need their own BranchExecutor — see"), console.error(" makeNamespaceBranchExecutor in @voltro/database."), 1;
1175
- let d = await X(t);
1176
- if (d === void 0) return z.warn("db branch: no schema files found", {
1172
+ }, rn = async (e) => {
1173
+ let t = H(e), n = tn(s(e, "--seed")), i = nn(s(e, "--prefer")), a = e.includes("--keep"), o = e.includes("--json"), c = Kt(e), u = W();
1174
+ if (u !== "postgres") return B.error(`voltro db branch: not supported on '${u}'.`), console.error(" The branch PLAN is dialect-agnostic; the shipped namespace EXECUTOR is Postgres-only"), console.error(" (CREATE SCHEMA / CREATE TABLE … LIKE … INCLUDING ALL / \"-quoted identifiers)."), console.error(" MySQL, MariaDB, SQLite and SQL Server need their own BranchExecutor — see"), console.error(" makeNamespaceBranchExecutor in @voltro/database."), 1;
1175
+ let d = await Z(t);
1176
+ if (d === void 0) return B.warn("db branch: no schema files found", {
1177
1177
  root: t,
1178
1178
  hint: "looked for *.entity.ts / *.schema.ts / schema.ts"
1179
1179
  }), 1;
1180
- let f = H(), p = Ae({
1180
+ let f = U(), p = ke({
1181
1181
  seed: n,
1182
1182
  ...f.url === void 0 ? {} : { dbUrl: f.url },
1183
1183
  ...i === void 0 ? {} : { prefer: i }
1184
1184
  });
1185
- if (p === "neon-cow") return z.error("voltro db branch: this connection resolves to the Neon copy-on-write mechanism, which the CLI cannot execute."), console.error(" A Neon CoW branch is a single call to Neon's branch REST API and needs a Neon API token;"), console.error(" the framework ships the PLAN, and the cloud control plane executes it."), console.error(" Re-run with `--prefer namespace` to rehearse on a schema-per-branch copy instead"), console.error(` (portable, no vendor API — it copies ${n === "copy" ? "every row" : "the schema only"}).`), 1;
1185
+ if (p === "neon-cow") return B.error("voltro db branch: this connection resolves to the Neon copy-on-write mechanism, which the CLI cannot execute."), console.error(" A Neon CoW branch is a single call to Neon's branch REST API and needs a Neon API token;"), console.error(" the framework ships the PLAN, and the cloud control plane executes it."), console.error(" Re-run with `--prefer namespace` to rehearse on a schema-per-branch copy instead"), console.error(` (portable, no vendor API — it copies ${n === "copy" ? "every row" : "the schema only"}).`), 1;
1186
1186
  let m = f.schema ?? "public", h = s(e, "--name") ?? ee(t), g = s(e, "--pr"), _ = g === void 0 ? 0 : Number(g);
1187
1187
  if (!Number.isInteger(_) || _ < 0) throw new r(`voltro db branch: --pr must be a non-negative integer, got "${String(g)}"`);
1188
- let v = be(h, _), y = await l(u), b = y.makeSqlLayer(f), x = y.makeSqlLayer({
1188
+ let v = ye(h, _), y = await l(u), b = y.makeSqlLayer(f), x = y.makeSqlLayer({
1189
1189
  ...f,
1190
1190
  schema: v
1191
- }), S = await J(b), C = N({
1191
+ }), S = await Y(b), C = P({
1192
1192
  declared: d,
1193
1193
  live: S,
1194
1194
  dialect: u,
1195
1195
  ...M(),
1196
1196
  ...c === void 0 ? {} : { onlineAfter: c }
1197
- }), w = S.tables.map((e) => e.name), T = $t(S), E = en(S), D = Ee({ run: (e) => q(b, A.SqlClient.pipe(k.flatMap((t) => t.unsafe(e)), k.asVoid)) }), O = async () => N({
1197
+ }), w = S.tables.map((e) => e.name), T = Qt(S), E = $t(S), D = Te({ run: (e) => J(b, A.SqlClient.pipe(k.flatMap((t) => t.unsafe(e)), k.asVoid)) }), O = async () => P({
1198
1198
  declared: d,
1199
- live: await J(x),
1199
+ live: await Y(x),
1200
1200
  dialect: u,
1201
1201
  ...M(),
1202
1202
  ...c === void 0 ? {} : { onlineAfter: c }
1203
- }), j = await pe({
1203
+ }), j = await fe({
1204
1204
  branchId: v,
1205
1205
  mechanism: p,
1206
1206
  branchedTables: w.length,
1207
1207
  replayedForeignKeys: T.length,
1208
1208
  keep: a,
1209
1209
  log: (e) => {
1210
- o || z.info(`db branch: ${e}`);
1210
+ o || B.info(`db branch: ${e}`);
1211
1211
  },
1212
1212
  provision: async () => {
1213
- await De({
1213
+ await Ee({
1214
1214
  appSlug: h,
1215
1215
  prNumber: _,
1216
1216
  seed: n,
@@ -1222,13 +1222,13 @@ var Fe = (e) => typeof e != "string", Ie = (e, t, n, r) => {
1222
1222
  ...f.url === void 0 ? {} : { dbUrl: f.url }
1223
1223
  }, D);
1224
1224
  },
1225
- fidelityPlan: async () => tn(C, await O()),
1225
+ fidelityPlan: async () => en(C, await O()),
1226
1226
  plan: O,
1227
1227
  apply: async (e) => {
1228
- await q(x, A.SqlClient.pipe(k.flatMap((t) => ne(t, e, {
1228
+ await J(x, A.SqlClient.pipe(k.flatMap((t) => ne(t, e, {
1229
1229
  declared: d,
1230
1230
  appliedBy: "cli:db-branch",
1231
- environment: Q(),
1231
+ environment: $(),
1232
1232
  source: "auto-diff",
1233
1233
  notes: `migration rehearsal on branch ${v}`,
1234
1234
  replan: () => k.promise(O)
@@ -1236,12 +1236,12 @@ var Fe = (e) => typeof e != "string", Ie = (e, t, n, r) => {
1236
1236
  },
1237
1237
  replan: async () => await O(),
1238
1238
  teardown: async () => {
1239
- await je(v, "namespace", D);
1239
+ await Ae(v, "namespace", D);
1240
1240
  }
1241
1241
  });
1242
1242
  return o ? te(1, `${JSON.stringify(j, null, 2)}\n`) : console.log(`\n${le(j)}\n`), ae(j);
1243
- }, on = async (e) => {
1244
- let t = Math.max(1, Number(s(e, "--limit") ?? "20")), n = await q(await K(), A.SqlClient.pipe(k.flatMap((e) => e`
1243
+ }, an = async (e) => {
1244
+ let t = Math.max(1, Number(s(e, "--limit") ?? "20")), n = await J(await q(), A.SqlClient.pipe(k.flatMap((e) => e`
1245
1245
  SELECT ${e("id")}, ${e("fingerprint")}, ${e("operations")},
1246
1246
  ${e("appliedBy")}, ${e("environment")}, ${e("source")},
1247
1247
  ${e("durationMs")}, ${e("notes")}, ${e("appliedAt")}
@@ -1249,25 +1249,25 @@ var Fe = (e) => typeof e != "string", Ie = (e, t, n, r) => {
1249
1249
  ORDER BY ${e("appliedAt")} DESC
1250
1250
  LIMIT ${t}
1251
1251
  `)));
1252
- if (n.length === 0) return z.info("db plans: no planner-based migrations applied yet"), console.log("Run `voltro db apply` after a schema change to start a plan history."), 0;
1252
+ if (n.length === 0) return B.info("db plans: no planner-based migrations applied yet"), console.log("Run `voltro db apply` after a schema change to start a plan history."), 0;
1253
1253
  console.log(`\n${n.length} plan${n.length === 1 ? "" : "s"} (newest first):\n`);
1254
1254
  for (let e of n) {
1255
1255
  let t = 0;
1256
1256
  try {
1257
- t = JSON.parse(dn(e.operations)).length;
1257
+ t = JSON.parse(un(e.operations)).length;
1258
1258
  } catch {}
1259
- console.log(` ${e.id} fp=${P(e.fingerprint)} env=${e.environment} src=${e.source} ${t} op(s) ${e.durationMs}ms ${fn(e.appliedAt)} by=${e.appliedBy}`), e.notes && console.log(` [2mnote: ${e.notes}[0m`);
1259
+ console.log(` ${e.id} fp=${F(e.fingerprint)} env=${e.environment} src=${e.source} ${t} op(s) ${e.durationMs}ms ${dn(e.appliedAt)} by=${e.appliedBy}`), e.notes && console.log(` [2mnote: ${e.notes}[0m`);
1260
1260
  }
1261
1261
  return console.log(), 0;
1262
- }, sn = async (e) => {
1262
+ }, on = async (e) => {
1263
1263
  let t = e[0];
1264
1264
  if (!t) return console.error("voltro db restore-snapshot <plan-id>"), console.error(" Renames soft-dropped columns/tables from a plan back to their original names."), console.error(" Requires the plan to have been applied with VOLTRO_SOFT_DROP=1."), 2;
1265
- let n = await K(), r = await q(n, A.SqlClient.pipe(k.flatMap((e) => e`SELECT ${e("id")}, ${e("operations")}
1265
+ let n = await q(), r = await J(n, A.SqlClient.pipe(k.flatMap((e) => e`SELECT ${e("id")}, ${e("operations")}
1266
1266
  FROM ${e("_voltro_migration_plans")} WHERE ${e("id")} = ${t}`)));
1267
1267
  if (r.length === 0) return console.error(`restore-snapshot: plan '${t}' not found`), 1;
1268
1268
  let i;
1269
1269
  try {
1270
- i = JSON.parse(dn(r[0].operations));
1270
+ i = JSON.parse(un(r[0].operations));
1271
1271
  } catch {
1272
1272
  return console.error(`restore-snapshot: plan '${t}' has corrupted operations JSON`), 1;
1273
1273
  }
@@ -1281,9 +1281,9 @@ var Fe = (e) => typeof e != "string", Ie = (e, t, n, r) => {
1281
1281
  if (a.length === 0 && o.length === 0) return console.log(`restore-snapshot: plan '${t}' has no drop-column / drop-table ops to restore`), 0;
1282
1282
  let s = 0;
1283
1283
  for (let e of a) {
1284
- let t = await q(n, A.SqlClient.pipe(k.flatMap((t) => t`
1284
+ let t = await J(n, A.SqlClient.pipe(k.flatMap((t) => t`
1285
1285
  SELECT column_name FROM information_schema.columns
1286
- WHERE ${t.unsafe(G(U()))}
1286
+ WHERE ${t.unsafe(K(W()))}
1287
1287
  AND table_name = ${e.table}
1288
1288
  AND column_name LIKE ${e.column + "__dropped_%"}
1289
1289
  ORDER BY column_name DESC LIMIT 1
@@ -1293,13 +1293,13 @@ var Fe = (e) => typeof e != "string", Ie = (e, t, n, r) => {
1293
1293
  continue;
1294
1294
  }
1295
1295
  let r = t[0].column_name;
1296
- await q(n, A.SqlClient.pipe(k.flatMap((t) => t.unsafe(`ALTER TABLE ${W(e.table)} RENAME COLUMN ${W(r)} TO ${W(e.column)}`)))), s++, console.log(` ↩ restored ${e.table}.${e.column} (from ${r})`);
1296
+ await J(n, A.SqlClient.pipe(k.flatMap((t) => t.unsafe(`ALTER TABLE ${G(e.table)} RENAME COLUMN ${G(r)} TO ${G(e.column)}`)))), s++, console.log(` ↩ restored ${e.table}.${e.column} (from ${r})`);
1297
1297
  }
1298
1298
  let c = 0;
1299
1299
  for (let e of o) {
1300
- let t = await q(n, A.SqlClient.pipe(k.flatMap((t) => t`
1300
+ let t = await J(n, A.SqlClient.pipe(k.flatMap((t) => t`
1301
1301
  SELECT table_name FROM information_schema.tables
1302
- WHERE ${t.unsafe(G(U()))}
1302
+ WHERE ${t.unsafe(K(W()))}
1303
1303
  AND table_name LIKE ${e.table + "__dropped_%"}
1304
1304
  ORDER BY table_name DESC LIMIT 1
1305
1305
  `)));
@@ -1308,57 +1308,57 @@ var Fe = (e) => typeof e != "string", Ie = (e, t, n, r) => {
1308
1308
  continue;
1309
1309
  }
1310
1310
  let r = t[0].table_name;
1311
- await q(n, A.SqlClient.pipe(k.flatMap((t) => t.unsafe(`ALTER TABLE ${W(r)} RENAME TO ${W(e.table)}`)))), c++, console.log(` ↩ restored table ${e.table} (from ${r})`);
1311
+ await J(n, A.SqlClient.pipe(k.flatMap((t) => t.unsafe(`ALTER TABLE ${G(r)} RENAME TO ${G(e.table)}`)))), c++, console.log(` ↩ restored table ${e.table} (from ${r})`);
1312
1312
  }
1313
1313
  return console.log(`\n✓ restored ${s} column(s) + ${c} table(s) from plan '${t}'\n`), 0;
1314
- }, cn = async (e) => {
1314
+ }, sn = async (e) => {
1315
1315
  let t = s(e, "--before");
1316
1316
  if (!t) return console.error("voltro db gc-snapshots --before <date> [--dry-run]"), console.error(" Permanently drops soft-dropped columns/tables (<name>__dropped_<ts>) older than <date>."), console.error(" <date> is ISO — e.g. 2026-01-01 or 2026-01-01T00:00:00Z. NOT reversible."), 2;
1317
1317
  let n = t.replace(/[^0-9]/g, "");
1318
1318
  if (n.length < 8) return console.error(`gc-snapshots: --before must be at least a full date (YYYY-MM-DD), got "${t}"`), 2;
1319
- let r = (n + "00000000000000").slice(0, 14), i = e.includes("--dry-run"), a = await K(), o = await q(a, A.SqlClient.pipe(k.flatMap((e) => e`
1319
+ let r = (n + "00000000000000").slice(0, 14), i = e.includes("--dry-run"), a = await q(), o = await J(a, A.SqlClient.pipe(k.flatMap((e) => e`
1320
1320
  SELECT table_name, column_name FROM information_schema.columns
1321
- WHERE ${e.unsafe(G(U()))} AND column_name LIKE ${"%__dropped_%"}
1322
- `))), c = await q(a, A.SqlClient.pipe(k.flatMap((e) => e`
1321
+ WHERE ${e.unsafe(K(W()))} AND column_name LIKE ${"%__dropped_%"}
1322
+ `))), c = await J(a, A.SqlClient.pipe(k.flatMap((e) => e`
1323
1323
  SELECT table_name FROM information_schema.tables
1324
- WHERE ${e.unsafe(G(U()))} AND table_name LIKE ${"%__dropped_%"}
1324
+ WHERE ${e.unsafe(K(W()))} AND table_name LIKE ${"%__dropped_%"}
1325
1325
  `))), l = (e) => {
1326
1326
  let t = /__dropped_(\d{14})$/.exec(e);
1327
1327
  return t ? t[1] : null;
1328
1328
  }, u = 0;
1329
1329
  for (let e of o) {
1330
1330
  let t = l(e.column_name);
1331
- t === null || t >= r || (console.log(` ${i ? "[dry-run] would drop column" : "dropping column"} ${e.table_name}.${e.column_name}`), i || await q(a, A.SqlClient.pipe(k.flatMap((t) => t.unsafe(`ALTER TABLE ${W(e.table_name)} DROP COLUMN ${W(e.column_name)}`)))), u++);
1331
+ t === null || t >= r || (console.log(` ${i ? "[dry-run] would drop column" : "dropping column"} ${e.table_name}.${e.column_name}`), i || await J(a, A.SqlClient.pipe(k.flatMap((t) => t.unsafe(`ALTER TABLE ${G(e.table_name)} DROP COLUMN ${G(e.column_name)}`)))), u++);
1332
1332
  }
1333
1333
  for (let e of c) {
1334
1334
  let t = l(e.table_name);
1335
- t === null || t >= r || (console.log(` ${i ? "[dry-run] would drop table" : "dropping table"} ${e.table_name}`), i || await q(a, A.SqlClient.pipe(k.flatMap((t) => t.unsafe(`DROP TABLE ${W(e.table_name)}`)))), u++);
1335
+ t === null || t >= r || (console.log(` ${i ? "[dry-run] would drop table" : "dropping table"} ${e.table_name}`), i || await J(a, A.SqlClient.pipe(k.flatMap((t) => t.unsafe(`DROP TABLE ${G(e.table_name)}`)))), u++);
1336
1336
  }
1337
1337
  return console.log(`\n${i ? `[dry-run] ${u} snapshot(s) would be dropped` : `✓ dropped ${u} snapshot(s)`} (older than ${r}).\n`), 0;
1338
- }, ln = async (e) => {
1338
+ }, cn = async (e) => {
1339
1339
  let t = s(e, "--before");
1340
1340
  if (!t) return console.error("voltro db squash --before <iso-date> [--note \"<text>\"]"), 2;
1341
1341
  let n = t;
1342
1342
  if (Number.isNaN(new Date(n).getTime())) return console.error(`voltro db squash: --before '${n}' is not a valid ISO date`), 2;
1343
- let r = s(e, "--note"), i = V(e), a = await X(i);
1344
- if (a === void 0) return z.warn("db squash: no schema files found", { root: i }), 1;
1345
- let o = ce(oe(a)), c = await K();
1343
+ let r = s(e, "--note"), i = H(e), a = await Z(i);
1344
+ if (a === void 0) return B.warn("db squash: no schema files found", { root: i }), 1;
1345
+ let o = ce(oe(a)), c = await q();
1346
1346
  try {
1347
- let e = await q(c, _e({
1347
+ let e = await J(c, ge({
1348
1348
  before: n,
1349
1349
  fingerprint: o,
1350
1350
  appliedBy: process.env.USER ?? "cli",
1351
- environment: Q(),
1351
+ environment: $(),
1352
1352
  ...r === void 0 ? {} : { note: r }
1353
1353
  }));
1354
- return console.log(`\n✓ squashed ${e.squashedCount} migration plan(s)\n snapshot id: ${e.snapshotId}\n fingerprint: ${P(e.snapshotFingerprint)}\n`), 0;
1354
+ return console.log(`\n✓ squashed ${e.squashedCount} migration plan(s)\n snapshot id: ${e.snapshotId}\n fingerprint: ${F(e.snapshotFingerprint)}\n`), 0;
1355
1355
  } catch (e) {
1356
1356
  return console.error(`squash refused: ${e.message}`), 1;
1357
1357
  }
1358
- }, un = async (e) => {
1358
+ }, ln = async (e) => {
1359
1359
  try {
1360
- let t = await J(e), n = ce(t);
1361
- await q(e, A.SqlClient.pipe(k.flatMap((e) => e`
1360
+ let t = await Y(e), n = ce(t);
1361
+ await J(e, A.SqlClient.pipe(k.flatMap((e) => e`
1362
1362
  UPDATE ${e("_voltro_migration_plans")}
1363
1363
  SET ${e("liveFingerprint")} = ${n}
1364
1364
  WHERE ${e("id")} = (
@@ -1370,7 +1370,7 @@ var Fe = (e) => typeof e != "string", Ie = (e, t, n, r) => {
1370
1370
  AND ${e("liveFingerprint")} IS NULL
1371
1371
  `)));
1372
1372
  } catch {}
1373
- }, dn = (e) => typeof e == "string" ? e : e == null ? "" : JSON.stringify(e), fn = (e) => e instanceof Date ? e.toISOString() : String(e ?? ""), pn = (e) => e === void 0 ? {
1373
+ }, un = (e) => typeof e == "string" ? e : e == null ? "" : JSON.stringify(e), dn = (e) => e instanceof Date ? e.toISOString() : String(e ?? ""), fn = (e) => e === void 0 ? {
1374
1374
  accept: !1,
1375
1375
  reason: "no-declared-schema"
1376
1376
  } : e > 0 ? {
@@ -1379,23 +1379,23 @@ var Fe = (e) => typeof e != "string", Ie = (e, t, n, r) => {
1379
1379
  } : {
1380
1380
  accept: !0,
1381
1381
  reason: "converged"
1382
- }, mn = async (e) => {
1383
- let t = e.includes("--accept"), n = await K(), r = await q(n, A.SqlClient.pipe(k.flatMap((e) => e`
1382
+ }, pn = async (e) => {
1383
+ let t = e.includes("--accept"), n = await q(), r = await J(n, A.SqlClient.pipe(k.flatMap((e) => e`
1384
1384
  SELECT * FROM ${e("_voltro_migration_plans")}
1385
1385
  ORDER BY ${e("appliedAt")} DESC
1386
1386
  LIMIT 1
1387
- `))), i = await J(n), a = ce(i);
1388
- if (r.length === 0) return z.info("db drift: no _voltro_migration_plans rows yet"), console.log(`live user-schema fingerprint: ${P(a)}`), console.log("No baseline to compare against. Run `voltro db apply` to lock in the current state."), 0;
1387
+ `))), i = await Y(n), a = ce(i);
1388
+ if (r.length === 0) return B.info("db drift: no _voltro_migration_plans rows yet"), console.log(`live user-schema fingerprint: ${F(a)}`), console.log("No baseline to compare against. Run `voltro db apply` to lock in the current state."), 0;
1389
1389
  let o = r[0];
1390
- if (o.liveFingerprint === null || o.liveFingerprint === void 0) return z.warn("db drift: no drift baseline recorded yet — cannot compare"), console.log(), console.log(` last applied: ${o.id} at ${fn(o.appliedAt)}`), console.log(` live now: ${P(a)}`), console.log(), console.log("That row was written before the framework recorded a live-schema baseline,"), console.log("and the value it does carry is the DECLARED snapshot's hash — not comparable"), console.log("with a live one. Run `voltro db apply` once to establish the baseline (a no-op"), console.log("apply backfills it too); use `voltro db plan` meanwhile, which compares declared"), console.log("against live directly."), console.log(), console.log("Exit code 3 — NOT 0. \"Did not compare\" is not \"clean\", and a gate on the exit"), console.log("code has to be able to tell them apart."), 3;
1391
- if (o.liveFingerprint === a) return z.info(`db drift: live matches last applied (${P(a)})`), 0;
1390
+ if (o.liveFingerprint === null || o.liveFingerprint === void 0) return B.warn("db drift: no drift baseline recorded yet — cannot compare"), console.log(), console.log(` last applied: ${o.id} at ${dn(o.appliedAt)}`), console.log(` live now: ${F(a)}`), console.log(), console.log("That row was written before the framework recorded a live-schema baseline,"), console.log("and the value it does carry is the DECLARED snapshot's hash — not comparable"), console.log("with a live one. Run `voltro db apply` once to establish the baseline (a no-op"), console.log("apply backfills it too); use `voltro db plan` meanwhile, which compares declared"), console.log("against live directly."), console.log(), console.log("Exit code 3 — NOT 0. \"Did not compare\" is not \"clean\", and a gate on the exit"), console.log("code has to be able to tell them apart."), 3;
1391
+ if (o.liveFingerprint === a) return B.info(`db drift: live matches last applied (${F(a)})`), 0;
1392
1392
  let s = await (async () => {
1393
1393
  try {
1394
- let t = await X(V(e));
1395
- return t === void 0 ? void 0 : N({
1394
+ let t = await Z(H(e));
1395
+ return t === void 0 ? void 0 : P({
1396
1396
  declared: t,
1397
1397
  live: i,
1398
- dialect: U(),
1398
+ dialect: W(),
1399
1399
  ...M()
1400
1400
  }).operations;
1401
1401
  } catch {
@@ -1403,14 +1403,14 @@ var Fe = (e) => typeof e != "string", Ie = (e, t, n, r) => {
1403
1403
  }
1404
1404
  })();
1405
1405
  if (t) {
1406
- let e = pn(s?.length);
1407
- if (e.reason === "no-declared-schema") return z.error("db drift --accept: no schema files found — cannot verify the live schema is current."), 1;
1406
+ let e = fn(s?.length);
1407
+ if (e.reason === "no-declared-schema") return B.error("db drift --accept: no schema files found — cannot verify the live schema is current."), 1;
1408
1408
  if (!e.accept && s !== void 0) {
1409
- z.error(`db drift --accept: refusing — ${s.length} operation(s) still pending against your declared schema.`), console.log();
1409
+ B.error(`db drift --accept: refusing — ${s.length} operation(s) still pending against your declared schema.`), console.log();
1410
1410
  for (let e of s.slice(0, 10)) console.log(` - ${e.op.kind} ${"table" in e.op ? `[${e.op.table}]` : ""}`);
1411
1411
  return s.length > 10 && console.log(` … and ${s.length - 10} more`), console.log(), console.log("`--accept` records the CURRENT live schema as the applied baseline. It is for a"), console.log("change that already landed out of band and left the schema correct — not for one"), console.log("that has not landed. Run `voltro db apply` instead; it writes a real baseline."), 4;
1412
1412
  }
1413
- return await q(n, A.SqlClient.pipe(k.flatMap((e) => e`
1413
+ return await J(n, A.SqlClient.pipe(k.flatMap((e) => e`
1414
1414
  UPDATE ${e("_voltro_migration_plans")}
1415
1415
  SET ${e("liveFingerprint")} = ${a}
1416
1416
  WHERE ${e("id")} = (
@@ -1419,43 +1419,43 @@ var Fe = (e) => typeof e != "string", Ie = (e, t, n, r) => {
1419
1419
  ORDER BY ${e("appliedAt")} DESC LIMIT 1
1420
1420
  ) AS ${e("newest")}
1421
1421
  )
1422
- `))), z.info(`db drift: accepted the live schema as the baseline (${P(a)})`), console.log(), console.log("`voltro db plan` reports 0 operations against this schema, so the live state already"), console.log("matches your declaration — only the ledger did not know. It does now."), console.log(), console.log("No history entry was invented: the latest row's baseline was updated in place,"), console.log("because no migration ran."), 0;
1422
+ `))), B.info(`db drift: accepted the live schema as the baseline (${F(a)})`), console.log(), console.log("`voltro db plan` reports 0 operations against this schema, so the live state already"), console.log("matches your declaration — only the ledger did not know. It does now."), console.log(), console.log("No history entry was invented: the latest row's baseline was updated in place,"), console.log("because no migration ran."), 0;
1423
1423
  }
1424
- return z.error("db drift: live schema DIVERGED from last applied state"), console.log(), console.log(` baseline: ${P(o.liveFingerprint)} at ${fn(o.appliedAt)} (${o.id})`), console.log(` live now: ${P(a)}`), console.log(), console.log("Something changed the live schema after the last apply. This command can see"), console.log("THAT it changed, not what or who — the fingerprints are hashes, not a diff."), console.log(), s === void 0 ? (console.log("No schema files found here, so the declared side could not be compared."), console.log("Run `voltro db plan` from your project root for the actual difference."), 4) : s.length === 0 ? (console.log("Your DECLARED schema is already satisfied — `voltro db plan` reports 0 operations"), console.log("against this database. So the live schema is not wrong, only unrecorded: something"), console.log("applied a change without going through the planner (a hand-run ALTER, a DBA"), console.log("window, a restored dump), or it touched a table your code does not declare."), console.log(), console.log("If that was deliberate and the schema is right, record it:"), console.log(), console.log(" voltro db drift --accept"), console.log(), console.log("It updates the latest ledger row's baseline to the live schema and invents no"), console.log("history entry. Drift then measures from here."), 4) : (console.log(`\`voltro db plan\` reports ${s.length} operation(s) still pending against your`), console.log("declared schema, so this is not merely an unrecorded change — run it for the diff,"), console.log("then `voltro db apply`, which writes a fresh baseline of its own."), 4);
1425
- }, hn = async (e, t) => {
1426
- let n = Q();
1424
+ return B.error("db drift: live schema DIVERGED from last applied state"), console.log(), console.log(` baseline: ${F(o.liveFingerprint)} at ${dn(o.appliedAt)} (${o.id})`), console.log(` live now: ${F(a)}`), console.log(), console.log("Something changed the live schema after the last apply. This command can see"), console.log("THAT it changed, not what or who — the fingerprints are hashes, not a diff."), console.log(), s === void 0 ? (console.log("No schema files found here, so the declared side could not be compared."), console.log("Run `voltro db plan` from your project root for the actual difference."), 4) : s.length === 0 ? (console.log("Your DECLARED schema is already satisfied — `voltro db plan` reports 0 operations"), console.log("against this database. So the live schema is not wrong, only unrecorded: something"), console.log("applied a change without going through the planner (a hand-run ALTER, a DBA"), console.log("window, a restored dump), or it touched a table your code does not declare."), console.log(), console.log("If that was deliberate and the schema is right, record it:"), console.log(), console.log(" voltro db drift --accept"), console.log(), console.log("It updates the latest ledger row's baseline to the live schema and invents no"), console.log("history entry. Drift then measures from here."), 4) : (console.log(`\`voltro db plan\` reports ${s.length} operation(s) still pending against your`), console.log("declared schema, so this is not merely an unrecorded change — run it for the diff,"), console.log("then `voltro db apply`, which writes a fresh baseline of its own."), 4);
1425
+ }, mn = async (e, t) => {
1426
+ let n = $();
1427
1427
  try {
1428
- let r = await q(t, A.SqlClient.pipe(k.flatMap((t) => ge(t, {
1428
+ let r = await J(t, A.SqlClient.pipe(k.flatMap((t) => he(t, {
1429
1429
  projectRoot: e,
1430
1430
  env: n,
1431
1431
  appliedBy: process.env.USER ? `cli:${process.env.USER}` : "cli:user"
1432
1432
  }))));
1433
- return r.applied.length > 0 && z.info(`db apply: applied ${r.applied.length} pending file-based migration(s) first`, { applied: r.applied.map((e) => `${e.id} (${e.durationMs}ms)`) }), { applied: r.applied.length };
1433
+ return r.applied.length > 0 && B.info(`db apply: applied ${r.applied.length} pending file-based migration(s) first`, { applied: r.applied.map((e) => `${e.id} (${e.durationMs}ms)`) }), { applied: r.applied.length };
1434
1434
  } catch (e) {
1435
1435
  return { failed: e };
1436
1436
  }
1437
- }, gn = async (e) => {
1438
- let t = V(e), n = await K(), r = Q();
1439
- await q(n, re(Ce, U(), void 0, { retryFilter: (await l(U())).retryFilter }));
1440
- let i = await q(n, A.SqlClient.pipe(k.flatMap((e) => ge(e, {
1437
+ }, hn = async (e) => {
1438
+ let t = H(e), n = await q(), r = $();
1439
+ await J(n, re(Se, W(), void 0, { retryFilter: (await l(W())).retryFilter }));
1440
+ let i = await J(n, A.SqlClient.pipe(k.flatMap((e) => he(e, {
1441
1441
  projectRoot: t,
1442
1442
  env: r,
1443
1443
  appliedBy: process.env.USER ? `cli:${process.env.USER}` : "cli:user"
1444
1444
  }))));
1445
- return i.applied.length === 0 ? (z.info(`db files: no pending file-based migrations (${i.skipped.length} already applied)`), 0) : (z.info(`db files: applied ${i.applied.length} migration(s)`, {
1445
+ return i.applied.length === 0 ? (B.info(`db files: no pending file-based migrations (${i.skipped.length} already applied)`), 0) : (B.info(`db files: applied ${i.applied.length} migration(s)`, {
1446
1446
  applied: i.applied.map((e) => `${e.id} (${e.durationMs}ms)`),
1447
1447
  skipped: i.skipped.length
1448
1448
  }), 0);
1449
- }, _n = async (e) => {
1450
- let n = V(e), r = c(e, Ot);
1451
- if (!r) return z.error("voltro db rollback-file <migration-id>"), 2;
1452
- if ((process.env.NODE_ENV ?? "").toLowerCase() === "production") return z.error("voltro db rollback-file: refusing on prod — schema rollback runs as an explicit deploy step." + t()), 3;
1453
- let i = await q(await K(), A.SqlClient.pipe(k.flatMap((e) => me(e, {
1449
+ }, gn = async (e) => {
1450
+ let n = H(e), r = c(e, Dt);
1451
+ if (!r) return B.error("voltro db rollback-file <migration-id>"), 2;
1452
+ if ((process.env.NODE_ENV ?? "").toLowerCase() === "production") return B.error("voltro db rollback-file: refusing on prod — schema rollback runs as an explicit deploy step." + t()), 3;
1453
+ let i = await J(await q(), A.SqlClient.pipe(k.flatMap((e) => pe(e, {
1454
1454
  projectRoot: n,
1455
1455
  id: r
1456
1456
  }))));
1457
- return z.info(`db rollback-file: rolled back ${i.id} in ${i.durationMs}ms`), 0;
1458
- }, vn = () => {
1457
+ return B.info(`db rollback-file: rolled back ${i.id} in ${i.durationMs}ms`), 0;
1458
+ }, _n = () => {
1459
1459
  let e = /* @__PURE__ */ new Date();
1460
1460
  return [
1461
1461
  e.getUTCFullYear(),
@@ -1465,7 +1465,7 @@ var Fe = (e) => typeof e != "string", Ie = (e, t, n, r) => {
1465
1465
  String(e.getUTCMinutes()).padStart(2, "0"),
1466
1466
  String(e.getUTCSeconds()).padStart(2, "0")
1467
1467
  ].join("");
1468
- }, yn = (e) => e.trim().toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "") || "migration", bn = (e, t) => `import { defineMigration, SqlClient } from '@voltro/database'
1468
+ }, vn = (e) => e.trim().toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "") || "migration", yn = (e, t) => `import { defineMigration, SqlClient } from '@voltro/database'
1469
1469
  import { Effect } from 'effect'
1470
1470
 
1471
1471
  // A hand-written migration. Reach for this when the DECLARATIVE differ can't
@@ -1497,25 +1497,25 @@ export default defineMigration({
1497
1497
  }),
1498
1498
  ],
1499
1499
  })
1500
- `, $ = {
1501
- plan: Yt,
1502
- apply: Zt,
1503
- branch: an,
1504
- plans: on,
1505
- drift: mn,
1506
- files: gn,
1507
- "rollback-file": _n,
1508
- migrate: jt,
1509
- rollback: Mt,
1510
- status: Nt,
1511
- seed: Ft,
1500
+ `, bn = {
1501
+ plan: Jt,
1502
+ apply: Xt,
1503
+ branch: rn,
1504
+ plans: an,
1505
+ drift: pn,
1506
+ files: hn,
1507
+ "rollback-file": gn,
1508
+ migrate: At,
1509
+ rollback: jt,
1510
+ status: Mt,
1511
+ seed: Pt,
1512
1512
  generate: async (e) => {
1513
- let { value: t, rest: n } = a(e, "--root"), { value: r, rest: i } = a(n, "--name"), o = t ? T(t) : process.cwd(), s = yn(r ?? c(i, []) ?? "migration"), l = `${vn()}_${s}`, u = C(o, "migrations"), d = C(u, `${l}.migration.ts`);
1514
- return await E.mkdir(u, { recursive: !0 }), await E.writeFile(d, bn(l, s), "utf8"), z.info(`created ${w(o, d)}`), console.error("Fill in the apply/undo steps, then run `voltro db migrate` (rollback with `voltro db rollback`)."), console.error("For a plain schema shape change you may not need this — `voltro db apply` diffs declared vs live."), 0;
1513
+ let { value: t, rest: n } = a(e, "--root"), { value: r, rest: i } = a(n, "--name"), o = t ? T(t) : process.cwd(), s = vn(r ?? c(i, []) ?? "migration"), l = `${_n()}_${s}`, u = C(o, "migrations"), d = C(u, `${l}.migration.ts`);
1514
+ return await E.mkdir(u, { recursive: !0 }), await E.writeFile(d, yn(l, s), "utf8"), B.info(`created ${w(o, d)}`), console.error("Fill in the apply/undo steps, then run `voltro db migrate` (rollback with `voltro db rollback`)."), console.error("For a plain schema shape change you may not need this — `voltro db apply` diffs declared vs live."), 0;
1515
1515
  },
1516
- squash: ln,
1517
- "restore-snapshot": sn,
1518
- "gc-snapshots": cn,
1516
+ squash: cn,
1517
+ "restore-snapshot": on,
1518
+ "gc-snapshots": sn,
1519
1519
  adopt: async (e) => {
1520
1520
  let t = (t) => {
1521
1521
  let n = e.indexOf(`--${t}`);
@@ -1529,22 +1529,22 @@ export default defineMigration({
1529
1529
  into: r,
1530
1530
  map: o.map,
1531
1531
  ...o.leaveUnset ? { leaveUnset: o.leaveUnset } : {}
1532
- }, c = U(), l = await K(), u = await q(l, A.SqlClient.pipe(k.flatMap(ue))), d = (e) => u.tables.find((t) => t.name === e)?.columns.map((e) => ({
1532
+ }, c = W(), l = await q(), u = await J(l, A.SqlClient.pipe(k.flatMap(N))), d = (e) => u.tables.find((t) => t.name === e)?.columns.map((e) => ({
1533
1533
  name: e.name,
1534
1534
  nullable: e.nullable,
1535
1535
  hasDefault: e.defaultValue !== void 0 && e.defaultValue !== null
1536
1536
  })), f = d(n), p = d(r);
1537
1537
  if (f === void 0) return console.error(`voltro db adopt: '${n}' does not exist in the database`), 1;
1538
1538
  if (p === void 0) return console.error(`voltro db adopt: '${r}' does not exist in the database — boot once so the plugin's table is created`), 1;
1539
- let m = async (e) => await q(l, A.SqlClient.pipe(k.flatMap((t) => t.unsafe(e)))), h = async (e) => Number(Object.values((await m(`SELECT COUNT(*) AS n FROM "${e}"`))[0] ?? { n: 0 })[0] ?? 0), g = Ie(s, f, p, await h(r));
1540
- for (let e of Re(s, g, await h(n))) console.log(e);
1539
+ let m = async (e) => await J(l, A.SqlClient.pipe(k.flatMap((t) => t.unsafe(e)))), h = async (e) => Number(Object.values((await m(`SELECT COUNT(*) AS n FROM "${e}"`))[0] ?? { n: 0 })[0] ?? 0), g = Fe(s, f, p, await h(r));
1540
+ for (let e of Le(s, g, await h(n))) console.log(e);
1541
1541
  if (g.fatal) return 1;
1542
1542
  if (!e.includes("--apply")) return console.log(""), console.log(" (dry run — nothing written. Re-run with --apply.)"), 0;
1543
- let _ = await Ue(s, g, c, "id", void 0, m, { keepSource: e.includes("--keep-source") });
1543
+ let _ = await He(s, g, c, "id", void 0, m, { keepSource: e.includes("--keep-source") });
1544
1544
  return console.log(""), console.log(` copied ${_.copied}/${_.sourceRows} row(s)`), console.log(` snapshot: ${_.snapshotTable} — restore from here, then drop it yourself`), _.verified ? (console.log(_.sourceDropped ? ` dropped ${n}` : ` ${n} left in place (--keep-source)`), 0) : (console.error(" ✗ counts DIFFER — the source was NOT dropped. Compare the two tables before doing anything else."), 1);
1545
1545
  },
1546
1546
  "scan-credentials": async (e) => {
1547
- let t = U(), n = [];
1547
+ let t = W(), n = [];
1548
1548
  for (let t = 0; t < e.length; t += 1) {
1549
1549
  if (e[t] !== "--table") continue;
1550
1550
  let i = e[t + 1];
@@ -1555,29 +1555,29 @@ export default defineMigration({
1555
1555
  column: o
1556
1556
  });
1557
1557
  }
1558
- let i = [...We, ...n], a = await q(await K(), A.SqlClient.pipe(k.flatMap((e) => k.promise(() => nt(e, t, i, W)))));
1559
- return console.log(rt(a, t)), it(a);
1558
+ let i = [...Ue, ...n], a = await J(await q(), A.SqlClient.pipe(k.flatMap((e) => k.promise(() => tt(e, t, i, G)))));
1559
+ return console.log(nt(a, t)), rt(a);
1560
1560
  },
1561
1561
  "encrypt-column": async (e) => {
1562
- let t = U(), n = e.includes("--dry-run"), i = e.includes("--yes"), a = (t) => {
1562
+ let t = W(), n = e.includes("--dry-run"), i = e.includes("--yes"), a = (t) => {
1563
1563
  let n = e.indexOf(t);
1564
1564
  return n >= 0 ? e[n + 1] : void 0;
1565
1565
  }, s = Math.max(1, Number(a("--batch") ?? 500)), c = a("--key-env") ?? "FIELD_ENCRYPTION_KEY", l = process.env[c];
1566
1566
  if (!l) throw new r(`voltro db encrypt-column: ${c} is not set. It must be the SAME key your app runs with (\`governancePlugin({ fieldEncryption: { key } })\`) — encrypting with a different one produces rows the app cannot read. Use --key-env to name a different variable.`);
1567
- let u = Ne(l), d = o(e, Ot).filter((e) => e.includes(".")).map(pt);
1567
+ let u = Me(l), d = o(e, Dt).filter((e) => e.includes(".")).map(ft);
1568
1568
  if (d.length === 0) throw new r("voltro db encrypt-column: name at least one <table>.<column>");
1569
- let f = await K(), p = [];
1569
+ let f = await q(), p = [];
1570
1570
  for (let e of d) {
1571
- let a = W(e.table), o = W(e.column), l = await q(f, A.SqlClient.pipe(k.flatMap((n) => k.promise(async () => {
1572
- let i = await k.runPromise(n.unsafe(Tt(t, e, G(t))));
1571
+ let a = G(e.table), o = G(e.column), l = await J(f, A.SqlClient.pipe(k.flatMap((n) => k.promise(async () => {
1572
+ let i = await k.runPromise(n.unsafe(wt(t, e, K(t))));
1573
1573
  if (i.length === 0) throw new r(`voltro db encrypt-column: ${e.table}.${e.column} does not exist on this database`);
1574
- return Et(Object.values(i[0])[0]);
1575
- })))), d = await q(f, A.SqlClient.pipe(k.flatMap((e) => k.promise(async () => await k.runPromise(e.unsafe(`SELECT ${W("id")} AS id, ${o} AS v FROM ${a}`)))))), m = 0;
1576
- for (let e of d) typeof e.v != "string" || F(e.v) || (m = Math.max(m, bt(e.v)));
1577
- let h = ht(m, l);
1578
- if (!h.fits) return console.error(` ✗ ${gt(e, h)}`), 1;
1579
- if (xt(d.map((e) => e.v).find((e) => typeof e == "string" && F(e)), u) === !1) return console.error(` ✗ ${St(e, c)}`), 1;
1580
- let g = d.filter((t) => vt(t.v, u, e) !== void 0 || wt(t.v, u, e) !== void 0).length;
1574
+ return Tt(Object.values(i[0])[0]);
1575
+ })))), d = await J(f, A.SqlClient.pipe(k.flatMap((e) => k.promise(async () => await k.runPromise(e.unsafe(`SELECT ${G("id")} AS id, ${o} AS v FROM ${a}`)))))), m = 0;
1576
+ for (let e of d) typeof e.v != "string" || I(e.v) || (m = Math.max(m, yt(e.v)));
1577
+ let h = mt(m, l);
1578
+ if (!h.fits) return console.error(` ✗ ${ht(e, h)}`), 1;
1579
+ if (bt(d.map((e) => e.v).find((e) => typeof e == "string" && I(e)), u) === !1) return console.error(` ✗ ${xt(e, c)}`), 1;
1580
+ let g = d.filter((t) => _t(t.v, u, e) !== void 0 || Ct(t.v, u, e) !== void 0).length;
1581
1581
  if (!n && !i) return console.error(` ✗ ${e.table}.${e.column}: ${g} row(s) would be rewritten in place. Re-run with --yes, or --dry-run to see the counts without writing.`), 1;
1582
1582
  let _ = 0, v = 0, y = 0, b = 0, x = [];
1583
1583
  for (let t of d) {
@@ -1585,8 +1585,8 @@ export default defineMigration({
1585
1585
  y += 1;
1586
1586
  continue;
1587
1587
  }
1588
- if (typeof t.v == "string" && F(t.v)) {
1589
- let n = wt(t.v, u, e);
1588
+ if (typeof t.v == "string" && I(t.v)) {
1589
+ let n = Ct(t.v, u, e);
1590
1590
  if (n === void 0) {
1591
1591
  _ += 1;
1592
1592
  continue;
@@ -1597,7 +1597,7 @@ export default defineMigration({
1597
1597
  }), v += 1;
1598
1598
  continue;
1599
1599
  }
1600
- let n = vt(t.v, u, e);
1600
+ let n = _t(t.v, u, e);
1601
1601
  if (n === void 0) {
1602
1602
  y += 1;
1603
1603
  continue;
@@ -1609,9 +1609,9 @@ export default defineMigration({
1609
1609
  }
1610
1610
  if (!n && x.length > 0) for (let t = 0; t < x.length; t += s) {
1611
1611
  let n = x.slice(t, t + s);
1612
- await q(f, A.SqlClient.pipe(k.flatMap((t) => k.promise(async () => {
1612
+ await J(f, A.SqlClient.pipe(k.flatMap((t) => k.promise(async () => {
1613
1613
  for (let r of n) await k.runPromise(t`UPDATE ${t(e.table)} SET ${t(e.column)} = ${r.value} WHERE ${t("id")} = ${r.id}`);
1614
- })))), z.info(`encrypt-column ${e.table}.${e.column}: ${Math.min(t + n.length, x.length)}/${x.length}`);
1614
+ })))), B.info(`encrypt-column ${e.table}.${e.column}: ${Math.min(t + n.length, x.length)}/${x.length}`);
1615
1615
  }
1616
1616
  p.push({
1617
1617
  table: e.table,
@@ -1624,21 +1624,21 @@ export default defineMigration({
1624
1624
  });
1625
1625
  }
1626
1626
  console.log(`field encryption · dialect ${t}${n ? " · DRY RUN, nothing written" : ""}`), console.log("");
1627
- for (let e of p) console.log(_t(e, n));
1628
- return n || console.log(Ct(d)), 0;
1627
+ for (let e of p) console.log(gt(e, n));
1628
+ return n || console.log(St(d)), 0;
1629
1629
  }
1630
- }, xn = (e) => Object.prototype.hasOwnProperty.call($, e), Sn = async (t) => {
1630
+ }, xn = (e) => Object.prototype.hasOwnProperty.call(bn, e), Sn = async (t) => {
1631
1631
  let [n, ...r] = t;
1632
1632
  if (!n) {
1633
1633
  console.error("voltro db <subcommand> [args]"), console.error("subcommands:");
1634
- for (let e of Object.keys($)) console.error(` ${e}`);
1634
+ for (let e of Object.keys(bn)) console.error(` ${e}`);
1635
1635
  return 1;
1636
1636
  }
1637
1637
  if (!xn(n)) return console.error(`voltro db: unknown subcommand '${n}'`), console.error(` known: ${e.join(", ")}`), 2;
1638
- let i = $[n];
1639
- (process.env.DB_DIRECT_URL !== void 0 || process.env.DB_MIGRATE_URL !== void 0) && z.info("using a DIRECT (non-pooler) connection for the db-command path (DB_DIRECT_URL/DB_MIGRATE_URL set)");
1638
+ let i = bn[n];
1639
+ (process.env.DB_DIRECT_URL !== void 0 || process.env.DB_MIGRATE_URL !== void 0) && B.info("using a DIRECT (non-pooler) connection for the db-command path (DB_DIRECT_URL/DB_MIGRATE_URL set)");
1640
1640
  let a = (e) => {
1641
- kt(e) ? z.error(At) : console.error(e), process.exit(1);
1641
+ Ot(e) ? B.error(kt) : console.error(e), process.exit(1);
1642
1642
  };
1643
1643
  process.on("uncaughtException", a);
1644
1644
  try {
@@ -1648,4 +1648,4 @@ export default defineMigration({
1648
1648
  }
1649
1649
  };
1650
1650
  //#endregion
1651
- export { Rt as a, pn as i, H as n, kt as o, Lt as r, Sn as s, At as t };
1651
+ export { Lt as a, fn as i, U as n, Ot as o, It as r, Sn as s, kt as t };