@voltro/cli 0.40.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.
- package/CHANGELOG.md +171 -0
- package/dist/{apiBuild-C8xBEYbL.js → apiBuild-B_iH24qf.js} +2 -2
- package/dist/apiBuild-RM5W5YXk.js +2 -0
- package/dist/bin.js +1 -1
- package/dist/{build-CkhFGnKA.js → build-DUdi6F_Q.js} +150 -150
- package/dist/{checkCommand-QbHshOac.js → checkCommand-B2RWrpWi.js} +1 -1
- package/dist/{checkCommand-BcXJa2IS.js → checkCommand-DWL2_PPR.js} +2 -2
- package/dist/{codegenCommand-DF2OJh3O.js → codegenCommand-DkjoJ30Q.js} +2 -2
- package/dist/{codemodRunner-BcOvi4A2.js → codemodRunner-sFuWDETH.js} +520 -460
- package/dist/{commands-7Z7-HOE3.js → commands-DoTClnSk.js} +22 -22
- package/dist/{dashboardCommand-CUycH6dR.js → dashboardCommand-Bro7Jwts.js} +5 -5
- package/dist/dataCommand-Rj57y1vg.js +669 -0
- package/dist/dataProfile-Cm0YVKSy.js +18 -0
- package/dist/{dbCommand-DSwGv9wS.js → dbCommand-B237qI-j.js} +343 -316
- package/dist/dbCommand-BvQeKQOb.js +2 -0
- package/dist/{dev-Dh1NuYx1.js → dev-D4l_YOzI.js} +22 -22
- package/dist/{dev-D8JSKlBM.js → dev-DuqBJC7g.js} +1 -1
- package/dist/doctorCommand-Bw3V4L1j.js +2 -0
- package/dist/{doctorCommand-C-8-Z9D6.js → doctorCommand-TmZTAepc.js} +385 -279
- package/dist/{dormancyCommand-A79Odglm.js → dormancyCommand-CUKhRmGG.js} +1 -1
- package/dist/{embeddingsCommand-CoiyHfkY.js → embeddingsCommand-Db-iQM3l.js} +1 -1
- package/dist/{envCommand-B6d0s-jZ.js → envCommand-DQ_URZq9.js} +12 -12
- package/dist/{evolveCommand-BC5a9lxX.js → evolveCommand-CghRPrGO.js} +2 -2
- package/dist/index.js +1 -1
- package/dist/{infoCommand-ZqSVzJZ4.js → infoCommand-BCs_ZFnl.js} +1 -1
- package/dist/{migrate-BnPw2zC8.js → migrate-DN47p2PG.js} +1 -1
- package/dist/{runtimeTrace-BslKJjDY.js → runtimeTrace-jFKvOPBz.js} +1 -1
- package/dist/{sdkgen-DQ8uEmmn.js → sdkgen-COQqHB9V.js} +1 -1
- package/dist/{serveCommand-Dqb9Ku1-.js → serveCommand-C512kzZA.js} +417 -411
- package/dist/serveCommand-gj7MsqXY.js +2 -0
- package/dist/serveEntry.js +1 -1
- package/dist/{start-dkNYKtgQ.js → start-BjcuFME_.js} +379 -343
- package/dist/{start-BA7txHhY.js → start-fifc0xpW.js} +1 -1
- package/dist/startEntry.js +1 -1
- package/dist/updateCommand-B2alql9k.js +2 -0
- package/dist/{updateCommand-eoGpZr3E.js → updateCommand-HZQVBU3T.js} +1 -1
- package/dist/webDev-D6QeXw3P.js +2 -0
- package/dist/{webDev-bybjZA0o.js → webDev-Dk8lFUzf.js} +642 -525
- package/dist/{webhooksCommand-DubZWNOx.js → webhooksCommand-D7ZpH7w0.js} +1 -1
- package/package.json +23 -17
- package/templates/AGENTS.md +1 -1
- package/templates/agent-docs/_index.md +1 -1
- package/templates/agent-docs/_manifest.json +1 -1
- package/templates/agent-docs/cli.md +79 -6
- package/templates/agent-docs/data.md +33 -0
- package/templates/agent-docs/plugins/governance.md +8 -0
- package/templates/agent-docs/routing.md +141 -28
- package/templates/agent-docs/security.md +24 -0
- package/templates/agent-docs/whats-new.md +48 -109
- package/templates/apps/api-ai/package.json +7 -7
- package/templates/apps/api-auth/package.json +8 -8
- package/templates/apps/api-backend/package.json +7 -7
- package/templates/apps/api-backend-deactivation/package.json +7 -7
- package/templates/apps/api-backend-mail/package.json +8 -8
- package/templates/apps/api-backend-mariadb/package.json +9 -9
- package/templates/apps/api-backend-sqlite/package.json +8 -8
- package/templates/apps/api-backend-storage/package.json +8 -8
- package/templates/apps/api-cms/package.json +10 -10
- package/templates/apps/api-collab/package.json +8 -8
- package/templates/apps/api-data-advanced/package.json +8 -8
- package/templates/apps/api-durable/package.json +8 -8
- package/templates/apps/api-feature-flags/package.json +9 -9
- package/templates/apps/api-governance/package.json +8 -8
- package/templates/apps/api-kv/package.json +8 -8
- package/templates/apps/api-moderation/package.json +8 -8
- package/templates/apps/api-observability/package.json +8 -8
- package/templates/apps/api-ratelimit/package.json +8 -8
- package/templates/apps/api-rbac/package.json +8 -8
- package/templates/apps/api-rest/package.json +7 -7
- package/templates/apps/api-saas/package.json +11 -11
- package/templates/apps/api-saas-starter/package.json +10 -10
- package/templates/apps/api-search/package.json +8 -8
- package/templates/apps/api-status/package.json +8 -8
- package/templates/apps/api-versioning/package.json +8 -8
- package/templates/apps/api-webhooks/package.json +9 -9
- package/templates/apps/changelog/package.json +6 -6
- package/templates/apps/edge-functions/package.json +2 -2
- package/templates/apps/frontend-admin/package.json +8 -8
- package/templates/apps/frontend-app/package.json +9 -9
- package/templates/apps/frontend-auth/package.json +8 -8
- package/templates/apps/frontend-blank/package.json +7 -7
- package/templates/apps/frontend-cms/package.json +9 -9
- package/templates/apps/frontend-collab/package.json +10 -10
- package/templates/apps/frontend-contact/package.json +7 -7
- package/templates/apps/frontend-dashboard/package.json +7 -7
- package/templates/apps/frontend-docs/package.json +7 -7
- package/templates/apps/frontend-i18n/package.json +6 -6
- package/templates/apps/frontend-landing/package.json +7 -7
- package/templates/apps/frontend-portal/package.json +8 -8
- package/templates/apps/frontend-saas/package.json +8 -8
- package/templates/apps/frontend-spa/package.json +7 -7
- package/templates/apps/frontend-ssr/package.json +7 -7
- package/templates/apps/frontend-ssr-api/package.json +8 -8
- package/templates/apps/frontend-static-blog/package.json +6 -6
- package/templates/apps/frontend-status/package.json +8 -8
- package/templates/apps/mobile-app/package.json +4 -4
- package/dist/apiBuild-BIyGkym8.js +0 -2
- package/dist/dataCommand-By78lscK.js +0 -540
- package/dist/dataProfile-dW-PsfLB.js +0 -15
- package/dist/dbCommand-DcqEyxju.js +0 -2
- package/dist/doctorCommand-FhQ7EVYL.js +0 -2
- package/dist/serveCommand-BmvEQCMS.js +0 -2
- package/dist/updateCommand-BauSVxPp.js +0 -2
- package/dist/webDev-CBbKs4dZ.js +0 -2
|
@@ -8,19 +8,19 @@ import { a as u } from "./connectionConfig-Bk9IC7D0.js";
|
|
|
8
8
|
import { i as d, n as f, r as p, s as m, t as h } from "./seedRunner-IdHEprqf.js";
|
|
9
9
|
import { n as g, s as _, y as v } from "./frameworkTableAssembly-oMPBKqlE.js";
|
|
10
10
|
import { b as y, x as b } from "./fileConventions-Cof68_BL.js";
|
|
11
|
-
import { r as
|
|
12
|
-
import { basename as
|
|
13
|
-
import { promises as
|
|
14
|
-
import { pathToFileURL as
|
|
15
|
-
import { createLogger as
|
|
16
|
-
import { Effect as
|
|
17
|
-
import { SqlClient as
|
|
18
|
-
import { DEFAULT_CDC_CHANNEL as
|
|
19
|
-
import { actorsTable as
|
|
20
|
-
import { InMemoryDataStore as
|
|
21
|
-
import { createHash as
|
|
11
|
+
import { r as x, t as S } from "./inspectGateHint-BjnFubmH.js";
|
|
12
|
+
import { basename as ee, join as C, relative as w, resolve as T } from "node:path";
|
|
13
|
+
import { promises as E, writeSync as te } from "node:fs";
|
|
14
|
+
import { pathToFileURL as D } from "node:url";
|
|
15
|
+
import { createLogger as O } from "@voltro/logger";
|
|
16
|
+
import { Effect as k } from "effect";
|
|
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 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
|
|
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 Ne = (e) => typeof e != "string", Pe = (e, t, n, r) => {
|
|
|
37
37
|
});
|
|
38
38
|
continue;
|
|
39
39
|
}
|
|
40
|
-
if (
|
|
40
|
+
if (Pe(n)) {
|
|
41
41
|
c.push({
|
|
42
42
|
target: t,
|
|
43
43
|
source: n.expr,
|
|
@@ -80,23 +80,23 @@ var Ne = (e) => typeof e != "string", Pe = (e, t, n, r) => {
|
|
|
80
80
|
remintIds: f,
|
|
81
81
|
fatal: i.some((e) => e.fatal)
|
|
82
82
|
};
|
|
83
|
-
},
|
|
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
|
-
],
|
|
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
|
|
96
|
+
for (let [n, i] of Ie(e, t).entries()) r.push(` ${n + 1}. ${i}`);
|
|
97
97
|
return r;
|
|
98
|
-
},
|
|
99
|
-
let a =
|
|
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 Ne = (e) => typeof e != "string", Pe = (e, t, n, r) => {
|
|
|
106
106
|
drop: `DROP TABLE ${a(e.from)}`,
|
|
107
107
|
dropSnapshot: `DROP TABLE ${a(o)}`
|
|
108
108
|
};
|
|
109
|
-
},
|
|
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
|
-
},
|
|
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 =
|
|
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 =
|
|
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 Ne = (e) => typeof e != "string", Pe = (e, t, n, r) => {
|
|
|
137
137
|
snapshotTable: c,
|
|
138
138
|
sourceDropped: !1
|
|
139
139
|
};
|
|
140
|
-
},
|
|
140
|
+
}, L = [
|
|
141
141
|
"token",
|
|
142
142
|
"secret",
|
|
143
143
|
"password",
|
|
@@ -146,7 +146,7 @@ var Ne = (e) => typeof e != "string", Pe = (e, t, n, r) => {
|
|
|
146
146
|
"credential",
|
|
147
147
|
"privatekey",
|
|
148
148
|
"private_key"
|
|
149
|
-
],
|
|
149
|
+
], Ue = [
|
|
150
150
|
{
|
|
151
151
|
table: "_voltro_audit_log",
|
|
152
152
|
column: "subject"
|
|
@@ -191,7 +191,7 @@ var Ne = (e) => typeof e != "string", Pe = (e, t, n, r) => {
|
|
|
191
191
|
table: "_voltro_row_history",
|
|
192
192
|
column: "subjectId"
|
|
193
193
|
}
|
|
194
|
-
],
|
|
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 Ne = (e) => typeof e != "string", Pe = (e, t, n, r) => {
|
|
|
200
200
|
case "sqlite":
|
|
201
201
|
case "turso": return `LOWER(CAST(${e} AS TEXT))`;
|
|
202
202
|
}
|
|
203
|
-
},
|
|
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
|
-
},
|
|
206
|
+
}, Je = (e, t = []) => {
|
|
207
207
|
if (Array.isArray(e)) {
|
|
208
|
-
for (let n of e)
|
|
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),
|
|
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
|
-
},
|
|
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 Ne = (e) => typeof e != "string", Pe = (e, t, n, r) => {
|
|
|
222
222
|
};
|
|
223
223
|
}
|
|
224
224
|
return {
|
|
225
|
-
asKey:
|
|
226
|
-
redactionMarkerOnly: !
|
|
225
|
+
asKey: Je(n).some((e) => qe(e, t)),
|
|
226
|
+
redactionMarkerOnly: !qe(JSON.stringify(Ye(n)) ?? "", t),
|
|
227
227
|
undecidable: !1
|
|
228
228
|
};
|
|
229
|
-
},
|
|
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
|
-
}),
|
|
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
|
-
},
|
|
238
|
-
let i = `WHERE ${
|
|
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
|
-
},
|
|
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
|
-
}),
|
|
244
|
-
let n = await
|
|
243
|
+
}), et = async (e, t) => {
|
|
244
|
+
let n = await k.runPromise(e.unsafe(t));
|
|
245
245
|
return Number(Object.values(n[0] ?? { n: 0 })[0] ?? 0);
|
|
246
|
-
},
|
|
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
|
|
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 Ne = (e) => typeof e != "string", Pe = (e, t, n, r) => {
|
|
|
260
260
|
continue;
|
|
261
261
|
}
|
|
262
262
|
try {
|
|
263
|
-
let s = await
|
|
264
|
-
if (s > 0) for (let i of
|
|
265
|
-
let o = await
|
|
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 Ne = (e) => typeof e != "string", Pe = (e, t, n, r) => {
|
|
|
270
270
|
} catch {}
|
|
271
271
|
let l;
|
|
272
272
|
if (s > 0) try {
|
|
273
|
-
l =
|
|
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 Ne = (e) => typeof e != "string", Pe = (e, t, n, r) => {
|
|
|
291
291
|
}
|
|
292
292
|
}
|
|
293
293
|
return i;
|
|
294
|
-
},
|
|
295
|
-
let n =
|
|
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,19 +306,19 @@ var Ne = (e) => typeof e != "string", Pe = (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 =
|
|
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 \`${
|
|
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 + (
|
|
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
|
-
},
|
|
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;
|
|
320
320
|
try {
|
|
321
|
-
e = await import(
|
|
321
|
+
e = await import(D(r).href);
|
|
322
322
|
} catch (e) {
|
|
323
323
|
t.warn("migration: failed to import", { file: r }, e);
|
|
324
324
|
continue;
|
|
@@ -328,12 +328,12 @@ var Ne = (e) => typeof e != "string", Pe = (e, t, n, r) => {
|
|
|
328
328
|
t.warn("migration: no defineMigration export", { file: r });
|
|
329
329
|
continue;
|
|
330
330
|
}
|
|
331
|
-
i.id !==
|
|
331
|
+
i.id !== ee(r).replace(/\.migration\.ts$/, "") && t.warn("migration: id does not match filename — id wins for ordering, but rename the file for clarity", {
|
|
332
332
|
file: r,
|
|
333
333
|
idInFile: i.id,
|
|
334
|
-
idFromFile:
|
|
334
|
+
idFromFile: ee(r).replace(/\.migration\.ts$/, "")
|
|
335
335
|
});
|
|
336
|
-
let a = await
|
|
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,14 +341,14 @@ var Ne = (e) => typeof e != "string", Pe = (e, t, n, r) => {
|
|
|
341
341
|
});
|
|
342
342
|
}
|
|
343
343
|
return [...n].sort((e, t) => e.definition.id < t.definition.id ? -1 : 1);
|
|
344
|
-
},
|
|
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
|
|
347
|
-
},
|
|
348
|
-
let e = yield* (yield*
|
|
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
|
+
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(
|
|
351
|
-
yield* (yield*
|
|
350
|
+
}).pipe(k.provide(e))), z = (e, t) => k.runPromise(k.gen(function* () {
|
|
351
|
+
yield* (yield* A.SqlClient)`
|
|
352
352
|
INSERT INTO "_voltro_migrations"
|
|
353
353
|
(id, name, hash, status, "appliedAt", "durationMs", "errorMessage", "errorStack")
|
|
354
354
|
VALUES
|
|
@@ -363,14 +363,14 @@ var Ne = (e) => typeof e != "string", Pe = (e, t, n, r) => {
|
|
|
363
363
|
"errorStack" = EXCLUDED."errorStack",
|
|
364
364
|
"updatedAt" = now()
|
|
365
365
|
`;
|
|
366
|
-
}).pipe(
|
|
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
|
|
373
|
-
let r = await
|
|
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") {
|
|
@@ -405,7 +405,7 @@ var Ne = (e) => typeof e != "string", Pe = (e, t, n, r) => {
|
|
|
405
405
|
for (let e of s.definition.steps) {
|
|
406
406
|
let n = Date.now();
|
|
407
407
|
try {
|
|
408
|
-
await
|
|
408
|
+
await k.runPromise(e.apply.pipe(k.provide(t))), l.push({
|
|
409
409
|
stepName: e.name,
|
|
410
410
|
status: "applied",
|
|
411
411
|
durationMs: Date.now() - n
|
|
@@ -471,9 +471,9 @@ var Ne = (e) => typeof e != "string", Pe = (e, t, n, r) => {
|
|
|
471
471
|
failed: o,
|
|
472
472
|
skipped: a
|
|
473
473
|
};
|
|
474
|
-
},
|
|
475
|
-
await
|
|
476
|
-
let i = await
|
|
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,
|
|
@@ -491,7 +491,7 @@ var Ne = (e) => typeof e != "string", Pe = (e, t, n, r) => {
|
|
|
491
491
|
for (let n = e.definition.steps.length - 1; n >= 0; n--) {
|
|
492
492
|
let o = e.definition.steps[n], s = Date.now();
|
|
493
493
|
try {
|
|
494
|
-
await
|
|
494
|
+
await k.runPromise(o.undo.pipe(k.provide(t))), i.push({
|
|
495
495
|
stepName: o.name,
|
|
496
496
|
status: "applied",
|
|
497
497
|
durationMs: Date.now() - s
|
|
@@ -542,9 +542,9 @@ var Ne = (e) => typeof e != "string", Pe = (e, t, n, r) => {
|
|
|
542
542
|
failed: c,
|
|
543
543
|
skipped: []
|
|
544
544
|
};
|
|
545
|
-
},
|
|
546
|
-
await
|
|
547
|
-
let n = await
|
|
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 Ne = (e) => typeof e != "string", Pe = (e, t, n, r) => {
|
|
|
561
561
|
hashMatches: !0
|
|
562
562
|
};
|
|
563
563
|
});
|
|
564
|
-
},
|
|
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,49 +574,50 @@ var Ne = (e) => typeof e != "string", Pe = (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
|
-
},
|
|
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
|
-
},
|
|
585
|
-
let n =
|
|
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
|
-
},
|
|
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}`,
|
|
596
596
|
` scanned ${e.scanned}`,
|
|
597
597
|
` already encrypted ${e.alreadyEncrypted} (skipped — a re-run is safe)`,
|
|
598
|
+
` ${(t ? "would re-encode" : "re-encoded").padEnd(18)} ${e.recoded} (old encoding — reads correctly either way)`,
|
|
598
599
|
` null / empty ${e.empty}`,
|
|
599
600
|
` ${n.padEnd(18)} ${e.encrypted}`
|
|
600
601
|
].join("\n");
|
|
601
|
-
},
|
|
602
|
+
}, _t = (e, t, n) => {
|
|
602
603
|
if (e == null) return;
|
|
603
604
|
let r = typeof e == "string" ? e : String(e);
|
|
604
|
-
if (r === "" ||
|
|
605
|
-
let i = t
|
|
605
|
+
if (r === "" || I(r)) return;
|
|
606
|
+
let i = xe(t, r), a;
|
|
606
607
|
try {
|
|
607
|
-
a = t
|
|
608
|
+
a = be(t, i);
|
|
608
609
|
} catch (e) {
|
|
609
|
-
throw Error(`${n.table}.${n.column}: the
|
|
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.`);
|
|
610
611
|
}
|
|
611
|
-
if (a !== r) throw Error(`${n.table}.${n.column}: round-trip mismatch — the
|
|
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.`);
|
|
612
613
|
return i;
|
|
613
|
-
},
|
|
614
|
+
}, vt = (e) => Buffer.byteLength(e, "utf8"), yt = (e) => vt(JSON.stringify(typeof e == "string" ? e : String(e))), bt = (e, t) => {
|
|
614
615
|
if (e !== void 0) try {
|
|
615
616
|
return t.decrypt(e), !0;
|
|
616
617
|
} catch {
|
|
617
618
|
return !1;
|
|
618
619
|
}
|
|
619
|
-
},
|
|
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) => [
|
|
620
621
|
"",
|
|
621
622
|
" NEXT — this converted the rows that exist. New writes are still plaintext",
|
|
622
623
|
" until the column carries the modifier:",
|
|
@@ -626,7 +627,25 @@ var Ne = (e) => typeof e != "string", Pe = (e, t, n, r) => {
|
|
|
626
627
|
" Order does not matter: a read returns a non-ciphertext value unchanged, so",
|
|
627
628
|
" the column may hold a mix while you deploy. Run this again afterwards to",
|
|
628
629
|
" catch anything written in between — it skips what is already encrypted."
|
|
629
|
-
].join("\n"),
|
|
630
|
+
].join("\n"), Ct = (e, t, n) => {
|
|
631
|
+
if (typeof e != "string" || !I(e)) return;
|
|
632
|
+
let r;
|
|
633
|
+
try {
|
|
634
|
+
r = we(t, e);
|
|
635
|
+
} catch {
|
|
636
|
+
return;
|
|
637
|
+
}
|
|
638
|
+
if (r !== !0) return;
|
|
639
|
+
let i = be(t, e);
|
|
640
|
+
if (typeof i != "string") return;
|
|
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
|
+
return a;
|
|
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
|
+
if (e == null) return;
|
|
646
|
+
let t = Number(e);
|
|
647
|
+
return Number.isFinite(t) && t >= 0 ? t : void 0;
|
|
648
|
+
}, B = O({ scope: "voltro:db" }), Et = /* @__PURE__ */ new Set([
|
|
630
649
|
"node_modules",
|
|
631
650
|
"dist",
|
|
632
651
|
"build",
|
|
@@ -636,15 +655,15 @@ var Ne = (e) => typeof e != "string", Pe = (e, t, n, r) => {
|
|
|
636
655
|
".git"
|
|
637
656
|
]), V = async (e, t) => {
|
|
638
657
|
let n = [], r = async (e) => {
|
|
639
|
-
let i = await
|
|
658
|
+
let i = await E.readdir(e, { withFileTypes: !0 }).catch(() => []);
|
|
640
659
|
for (let a of i) {
|
|
641
|
-
if (
|
|
642
|
-
let i =
|
|
660
|
+
if (Et.has(a.name)) continue;
|
|
661
|
+
let i = C(e, a.name);
|
|
643
662
|
a.isDirectory() ? await r(i) : a.isFile() && t.test(a.name) && n.push(i);
|
|
644
663
|
}
|
|
645
664
|
};
|
|
646
665
|
return await r(e), n;
|
|
647
|
-
},
|
|
666
|
+
}, Dt = [
|
|
648
667
|
"--against",
|
|
649
668
|
"--batch",
|
|
650
669
|
"--before",
|
|
@@ -663,23 +682,23 @@ var Ne = (e) => typeof e != "string", Pe = (e, t, n, r) => {
|
|
|
663
682
|
"--store",
|
|
664
683
|
"--to",
|
|
665
684
|
"--token"
|
|
666
|
-
], H = (e) =>
|
|
685
|
+
], H = (e) => T(c(e, Dt) ?? process.cwd()), U = () => u("migration"), Ot = (e) => {
|
|
667
686
|
let t = e;
|
|
668
687
|
if (typeof t != "object" || !t) return !1;
|
|
669
688
|
if (t.code === "ERR_OUT_OF_RANGE" || t.cause?.code === "ERR_OUT_OF_RANGE") return !0;
|
|
670
689
|
let n = `${t.message ?? ""} ${t.cause?.message ?? ""} ${t.stack ?? ""}`;
|
|
671
690
|
return /ERR_OUT_OF_RANGE|out of range/i.test(n) && /pg-protocol|parseDataRow|buffer-reader|BufferReader/i.test(n);
|
|
672
|
-
},
|
|
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 = () => {
|
|
673
692
|
let e = (process.env.DB_DIALECT ?? "postgres").toLowerCase();
|
|
674
693
|
if (e === "memory") throw new r("voltro db: subcommands require a real dialect, not DB_DIALECT=memory.");
|
|
675
694
|
return e;
|
|
676
|
-
}, G = (e) =>
|
|
677
|
-
let t = H(e), n = e.includes("--dry-run"), r = await
|
|
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);
|
|
678
697
|
if (r.length === 0) return B.info("no migrations found", { root: t }), 0;
|
|
679
698
|
if (n) {
|
|
680
699
|
let e = /* @__PURE__ */ new Set();
|
|
681
700
|
try {
|
|
682
|
-
let t = await
|
|
701
|
+
let t = await ut(r, await q());
|
|
683
702
|
e = new Set(t.filter((e) => e.status === "applied").map((e) => e.id));
|
|
684
703
|
} catch {
|
|
685
704
|
B.warn("migrate --dry-run: could not read the migration ledger — showing ALL as pending");
|
|
@@ -690,29 +709,29 @@ var Ne = (e) => typeof e != "string", Pe = (e, t, n, r) => {
|
|
|
690
709
|
for (let e of t) console.log(` pending ${e.definition.id}`);
|
|
691
710
|
return 0;
|
|
692
711
|
}
|
|
693
|
-
let i = await
|
|
694
|
-
return i.failed ? (process.stderr.write(
|
|
712
|
+
let i = await ct(r, await q(), B);
|
|
713
|
+
return i.failed ? (process.stderr.write(dt(i) + "\n"), 1) : (B.info("migrate complete", {
|
|
695
714
|
applied: i.applied.length,
|
|
696
715
|
skipped: i.skipped.length
|
|
697
716
|
}), 0);
|
|
698
|
-
},
|
|
699
|
-
let t = H(e), n = s(e, "--to"), r = await
|
|
717
|
+
}, jt = async (e) => {
|
|
718
|
+
let t = H(e), n = s(e, "--to"), r = await at(await V(t, it), B);
|
|
700
719
|
if (r.length === 0) return B.info("no migrations found", { root: t }), 0;
|
|
701
|
-
let i = await
|
|
702
|
-
return i.failed ? (process.stderr.write(
|
|
703
|
-
},
|
|
704
|
-
let t = await
|
|
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);
|
|
722
|
+
}, Mt = async (e) => {
|
|
723
|
+
let t = await at(await V(H(e), it), B);
|
|
705
724
|
if (t.length === 0) return console.log("no migrations found"), 0;
|
|
706
|
-
let n = await
|
|
725
|
+
let n = await ut(t, await q());
|
|
707
726
|
for (let e of n) {
|
|
708
727
|
let t = e.status === "applied" ? "✓" : e.status === "failed" ? "✗" : e.status === "reverted" ? "↩" : "·", n = e.hashMatches ? "" : " (hash drift!)", r = e.appliedAt ? ` @ ${e.appliedAt.toISOString()}` : "";
|
|
709
728
|
console.log(` ${t} ${e.id} [${e.status}] ${e.name}${r}${n}`);
|
|
710
729
|
}
|
|
711
730
|
return 0;
|
|
712
|
-
},
|
|
731
|
+
}, Nt = async (e) => {
|
|
713
732
|
let t = (s(e, "--store") ?? process.env.DB_DIALECT ?? "postgres").toLowerCase();
|
|
714
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."), {
|
|
715
|
-
store: new
|
|
734
|
+
store: new je(),
|
|
716
735
|
dispose: async () => {},
|
|
717
736
|
dialectId: "memory"
|
|
718
737
|
};
|
|
@@ -729,10 +748,10 @@ var Ne = (e) => typeof e != "string", Pe = (e, t, n, r) => {
|
|
|
729
748
|
},
|
|
730
749
|
dialectId: n.id
|
|
731
750
|
};
|
|
732
|
-
},
|
|
751
|
+
}, Pt = async (e) => {
|
|
733
752
|
let t = H(e), n = s(e, "--id"), r = s(e, "--lifecycle"), i = await V(t, b), a = await f(i, B);
|
|
734
753
|
if (a.length === 0) return B.info("no seeds found", { root: t }), 0;
|
|
735
|
-
let { store: o, dispose: c, dialectId: l } = await
|
|
754
|
+
let { store: o, dispose: c, dialectId: l } = await Nt(e);
|
|
736
755
|
try {
|
|
737
756
|
if (n) return +((await d(a, n, o, B)).status === "failed");
|
|
738
757
|
let e = r ? a.filter((e) => e.definition.lifecycle === r) : a.filter((e) => e.definition.lifecycle === "boot");
|
|
@@ -748,60 +767,60 @@ var Ne = (e) => typeof e != "string", Pe = (e, t, n, r) => {
|
|
|
748
767
|
B.warn("voltro db seed: store dispose failed", { error: String(e) });
|
|
749
768
|
});
|
|
750
769
|
}
|
|
751
|
-
},
|
|
770
|
+
}, Ft = (e) => typeof e == "object" && !!e && "tableName" in e && "fields" in e && typeof e.tableName == "string", It = async (e) => {
|
|
752
771
|
let t = await V(e, y), n = [];
|
|
753
772
|
for (let r of t) {
|
|
754
773
|
let t;
|
|
755
774
|
try {
|
|
756
|
-
t = await import(
|
|
775
|
+
t = await import(D(r).href);
|
|
757
776
|
} catch (t) {
|
|
758
777
|
B.warn("db: failed to import schema file", {
|
|
759
|
-
file:
|
|
778
|
+
file: w(e, r),
|
|
760
779
|
error: String(t)
|
|
761
780
|
});
|
|
762
781
|
continue;
|
|
763
782
|
}
|
|
764
|
-
for (let e of Object.values(t))
|
|
783
|
+
for (let e of Object.values(t)) Ft(e) && n.push(e);
|
|
765
784
|
}
|
|
766
785
|
return n;
|
|
767
|
-
},
|
|
786
|
+
}, Lt = (e) => {
|
|
768
787
|
let t = new Map(e.map((e) => [e.tableName, e]));
|
|
769
|
-
t.has("actors") || t.set("actors",
|
|
788
|
+
t.has("actors") || t.set("actors", ve);
|
|
770
789
|
let n = t.get("actors"), r = t.get("tenants");
|
|
771
|
-
return
|
|
790
|
+
return Oe({
|
|
772
791
|
actors: () => n,
|
|
773
792
|
...r === void 0 ? {} : { tenants: () => r }
|
|
774
793
|
}), [...t.values()];
|
|
775
|
-
},
|
|
794
|
+
}, Rt = (e) => {
|
|
776
795
|
let t = /* @__PURE__ */ new Map();
|
|
777
796
|
for (let n of e) {
|
|
778
797
|
let e = n.tableName;
|
|
779
798
|
e !== void 0 && !t.has(e) && t.set(e, n);
|
|
780
799
|
}
|
|
781
800
|
return [...t.values()];
|
|
782
|
-
},
|
|
783
|
-
let t =
|
|
801
|
+
}, zt = (e) => {
|
|
802
|
+
let t = se(process.env.VOLTRO_DESTRUCTIVE_OK);
|
|
784
803
|
if (t === void 0 || !e.operations.filter((e) => e.blocked).every((e) => e.classification === "lossy")) return {
|
|
785
804
|
plan: e,
|
|
786
805
|
acknowledged: !1
|
|
787
806
|
};
|
|
788
|
-
let n =
|
|
807
|
+
let n = _e(e, t);
|
|
789
808
|
return {
|
|
790
809
|
plan: n,
|
|
791
810
|
acknowledged: !n.operations.some((e) => e.blocked)
|
|
792
811
|
};
|
|
793
|
-
}, J = async (e, t) =>
|
|
812
|
+
}, J = async (e, t) => k.runPromise(t.pipe(k.provide(e))), Y = async (e) => {
|
|
794
813
|
try {
|
|
795
|
-
return await J(e,
|
|
814
|
+
return await J(e, A.SqlClient.pipe(k.flatMap(N)));
|
|
796
815
|
} catch (e) {
|
|
797
816
|
let t = String(e?.message ?? e);
|
|
798
|
-
if (
|
|
799
|
-
let n = /* @__PURE__ */ Error(`${
|
|
817
|
+
if (Ot(e) || /connection error/i.test(t)) {
|
|
818
|
+
let n = /* @__PURE__ */ Error(`${kt}\n\nOriginal error: ${t}`);
|
|
800
819
|
throw n.cause = e, n;
|
|
801
820
|
}
|
|
802
821
|
throw e;
|
|
803
822
|
}
|
|
804
|
-
},
|
|
823
|
+
}, Bt = {
|
|
805
824
|
safe: "\x1B[32m✓\x1B[0m",
|
|
806
825
|
"needs-default": "\x1B[32m⊕\x1B[0m",
|
|
807
826
|
"needs-backfill": "\x1B[33m⊕\x1B[0m",
|
|
@@ -809,7 +828,7 @@ var Ne = (e) => typeof e != "string", Pe = (e, t, n, r) => {
|
|
|
809
828
|
lossy: "\x1B[31m✗\x1B[0m",
|
|
810
829
|
"online-required": "\x1B[36m◷\x1B[0m",
|
|
811
830
|
"multi-step": "\x1B[35m⇉\x1B[0m"
|
|
812
|
-
},
|
|
831
|
+
}, Vt = (e) => {
|
|
813
832
|
let t = e.op, n;
|
|
814
833
|
switch (t.kind) {
|
|
815
834
|
case "create-table":
|
|
@@ -871,9 +890,9 @@ var Ne = (e) => typeof e != "string", Pe = (e, t, n, r) => {
|
|
|
871
890
|
break;
|
|
872
891
|
case "drop-check": n = `ALTER TABLE ${t.table} DROP CHECK ${t.column}`;
|
|
873
892
|
}
|
|
874
|
-
let r =
|
|
893
|
+
let r = Bt[e.classification], i = e.reason ? ` [2m# ${e.reason}[0m` : "", a = e.blocked ? `\n [31m! ${e.blocked.fix}[0m` : "";
|
|
875
894
|
return ` ${r} ${n}${i}${a}`;
|
|
876
|
-
},
|
|
895
|
+
}, Ht = async (e, t) => {
|
|
877
896
|
let n = e.operations.filter((e) => e.classification === "needs-default" && e.op.kind === "add-column");
|
|
878
897
|
if (n.length === 0) return;
|
|
879
898
|
let r = [];
|
|
@@ -882,7 +901,7 @@ var Ne = (e) => typeof e != "string", Pe = (e, t, n, r) => {
|
|
|
882
901
|
if (i === void 0 || a === void 0) continue;
|
|
883
902
|
let o = 0;
|
|
884
903
|
try {
|
|
885
|
-
let e = await J(t,
|
|
904
|
+
let e = await J(t, A.SqlClient.pipe(k.flatMap((e) => e.unsafe(`SELECT COUNT(*) AS n FROM ${De(i, W())}`))));
|
|
886
905
|
o = Number(Object.values(e[0] ?? { n: 0 })[0] ?? 0);
|
|
887
906
|
} catch {
|
|
888
907
|
continue;
|
|
@@ -894,11 +913,11 @@ var Ne = (e) => typeof e != "string", Pe = (e, t, n, r) => {
|
|
|
894
913
|
for (let e of r) console.log(e);
|
|
895
914
|
console.log(" (the shape is correct either way — this is the VALUE a state diff cannot know)");
|
|
896
915
|
}
|
|
897
|
-
},
|
|
916
|
+
}, Ut = async (e, t) => {
|
|
898
917
|
if (W() !== "postgres") return;
|
|
899
|
-
let n =
|
|
918
|
+
let n = j, r;
|
|
900
919
|
try {
|
|
901
|
-
r = await J(t,
|
|
920
|
+
r = await J(t, A.SqlClient.pipe(k.flatMap((t) => m(t, e, n))));
|
|
902
921
|
} catch {
|
|
903
922
|
return;
|
|
904
923
|
}
|
|
@@ -906,7 +925,7 @@ var Ne = (e) => typeof e != "string", Pe = (e, t, n, r) => {
|
|
|
906
925
|
if (a.length === 0) return;
|
|
907
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)");
|
|
908
927
|
let o = 0;
|
|
909
|
-
for (let e of a) await J(t,
|
|
928
|
+
for (let e of a) await J(t, A.SqlClient.pipe(k.flatMap((t) => t.unsafe(e)))), o += 1;
|
|
910
929
|
B.info(`db apply: change triggers converged (${o} statement(s))`, {
|
|
911
930
|
installed: i.missing.length,
|
|
912
931
|
removed: i.stale.length,
|
|
@@ -918,33 +937,33 @@ var Ne = (e) => typeof e != "string", Pe = (e, t, n, r) => {
|
|
|
918
937
|
console.log(" (schema is up to date)\n");
|
|
919
938
|
return;
|
|
920
939
|
}
|
|
921
|
-
for (let t of e.operations) console.log(
|
|
922
|
-
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`),
|
|
923
|
-
},
|
|
924
|
-
let t =
|
|
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);
|
|
925
944
|
if (t.length !== 0) {
|
|
926
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):");
|
|
927
946
|
for (let e of t) console.log(` • ${e.op.op.kind}: ${e.reason}`), console.log(` → ${e.remedy}`);
|
|
928
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");
|
|
929
948
|
}
|
|
930
|
-
},
|
|
931
|
-
let n =
|
|
949
|
+
}, Gt = (e, t) => {
|
|
950
|
+
let n = ie({
|
|
932
951
|
enabled: process.env.VOLTRO_ROLLING_DEPLOY === "1",
|
|
933
952
|
forced: t.includes("--force"),
|
|
934
|
-
unsafeCount:
|
|
953
|
+
unsafeCount: me(e.operations).length
|
|
935
954
|
});
|
|
936
955
|
return n.refuse ? (B.error(`db apply: ${n.message}`), !0) : (n.warnForced && B.warn(`db apply: ${n.message}`), !1);
|
|
937
|
-
},
|
|
956
|
+
}, Kt = (e) => {
|
|
938
957
|
let t = s(e, "--online-after") ?? process.env.VOLTRO_ONLINE_THRESHOLD;
|
|
939
958
|
if (t === void 0) return;
|
|
940
959
|
let n = Number(t);
|
|
941
960
|
if (!Number.isInteger(n) || n < 0) throw Error(`--online-after / VOLTRO_ONLINE_THRESHOLD must be a non-negative integer, got "${t}"`);
|
|
942
961
|
return n;
|
|
943
962
|
}, Z = async (e) => {
|
|
944
|
-
let t = await
|
|
963
|
+
let t = await It(e);
|
|
945
964
|
if (t.length === 0) return;
|
|
946
965
|
let n = await g({ root: e });
|
|
947
|
-
return
|
|
966
|
+
return Lt(Rt([
|
|
948
967
|
...t,
|
|
949
968
|
...Se,
|
|
950
969
|
...n
|
|
@@ -959,20 +978,20 @@ var Ne = (e) => typeof e != "string", Pe = (e, t, n, r) => {
|
|
|
959
978
|
} catch (e) {
|
|
960
979
|
r = e;
|
|
961
980
|
}
|
|
962
|
-
return await
|
|
963
|
-
},
|
|
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) => {
|
|
964
983
|
let n = { close: async () => {} }, r = await V(e, b);
|
|
965
984
|
if (r.length === 0) return n;
|
|
966
985
|
let i = await f(r, B), a = i.filter((e) => e.definition.lifecycle === "onSchemaChange");
|
|
967
986
|
if (a.length === 0) return n;
|
|
968
|
-
let { store: o, dispose: s } = await
|
|
987
|
+
let { store: o, dispose: s } = await Nt(t), c = h(i, o, B.child("seeds"));
|
|
969
988
|
return B.info(`db apply: ${a.length} onSchemaChange seed(s) armed for this apply`, { ids: a.map((e) => e.definition.id) }), { close: async () => {
|
|
970
989
|
c(), await s().catch((e) => {
|
|
971
990
|
B.warn("db apply: seed store dispose failed", { error: String(e) });
|
|
972
991
|
});
|
|
973
992
|
} };
|
|
974
|
-
},
|
|
975
|
-
let t =
|
|
993
|
+
}, Jt = async (e) => {
|
|
994
|
+
let t = Kt(e), n = H(e), r = await Z(n);
|
|
976
995
|
if (r === void 0) return B.warn("db plan: no schema files found", {
|
|
977
996
|
root: n,
|
|
978
997
|
hint: "looked for *.entity.ts / *.schema.ts / schema.ts"
|
|
@@ -983,14 +1002,14 @@ var Ne = (e) => typeof e != "string", Pe = (e, t, n, r) => {
|
|
|
983
1002
|
a && (o.authorization = `Bearer ${a}`);
|
|
984
1003
|
try {
|
|
985
1004
|
let e = n.endsWith("/_voltro/inspect/migrations") ? n : `${n.replace(/\/+$/, "")}/_voltro/inspect/migrations`, i = await fetch(e, { headers: o });
|
|
986
|
-
if (!i.ok) return B.error(`db plan --against: remote returned ${i.status}`, { url: e }),
|
|
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;
|
|
987
1006
|
let a = (await i.json()).drift?.liveSnapshot;
|
|
988
1007
|
if (!a) return B.error("db plan --against: remote inspect payload missing drift.liveSnapshot", { url: e }), 1;
|
|
989
|
-
let s =
|
|
1008
|
+
let s = P({
|
|
990
1009
|
declared: r,
|
|
991
1010
|
live: a,
|
|
992
1011
|
dialect: W(),
|
|
993
|
-
...
|
|
1012
|
+
...M(),
|
|
994
1013
|
...t === void 0 ? {} : { onlineAfter: t }
|
|
995
1014
|
});
|
|
996
1015
|
return console.log(`\n[--against ${e}] — diff vs remote live schema:\n`), X(s), s.summary.blocked > 0 ? 2 : 0;
|
|
@@ -998,18 +1017,18 @@ var Ne = (e) => typeof e != "string", Pe = (e, t, n, r) => {
|
|
|
998
1017
|
return B.error(`db plan --against: ${e.message}`), 1;
|
|
999
1018
|
}
|
|
1000
1019
|
}
|
|
1001
|
-
let a = await Y(await q()), o =
|
|
1020
|
+
let a = await Y(await q()), o = P({
|
|
1002
1021
|
declared: r,
|
|
1003
1022
|
live: a,
|
|
1004
1023
|
dialect: W(),
|
|
1005
|
-
...
|
|
1024
|
+
...M(),
|
|
1006
1025
|
...t === void 0 ? {} : { onlineAfter: t }
|
|
1007
1026
|
});
|
|
1008
|
-
return e.includes("--json") ? (
|
|
1009
|
-
}, $ = 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) => {
|
|
1010
1029
|
let r;
|
|
1011
1030
|
try {
|
|
1012
|
-
let t = await
|
|
1031
|
+
let t = await E.readFile(T(e), "utf8");
|
|
1013
1032
|
r = JSON.parse(t);
|
|
1014
1033
|
} catch (t) {
|
|
1015
1034
|
return B.error(`db apply --plan: cannot read/parse plan file '${e}': ${t.message}`), 1;
|
|
@@ -1017,21 +1036,21 @@ var Ne = (e) => typeof e != "string", Pe = (e, t, n, r) => {
|
|
|
1017
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;
|
|
1018
1037
|
let i = await Z(n);
|
|
1019
1038
|
if (i === void 0) return B.warn("db apply --plan: no schema files found", { root: n }), 1;
|
|
1020
|
-
let a = await q(), o = await J(a,
|
|
1039
|
+
let a = await q(), o = await J(a, A.SqlClient.pipe(k.flatMap((e) => ue(e, n)))).catch(() => []);
|
|
1021
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;
|
|
1022
|
-
let c = await Y(a), l =
|
|
1041
|
+
let c = await Y(a), l = P({
|
|
1023
1042
|
declared: i,
|
|
1024
1043
|
live: c,
|
|
1025
1044
|
dialect: W(),
|
|
1026
|
-
...
|
|
1045
|
+
...M()
|
|
1027
1046
|
});
|
|
1028
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;
|
|
1029
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;
|
|
1030
|
-
let u =
|
|
1049
|
+
let u = zt(l), d = u.plan;
|
|
1031
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;
|
|
1032
|
-
if (u.acknowledged && B.warn("db apply --plan: proceeding with acknowledged lossy operation(s) (VOLTRO_DESTRUCTIVE_OK)"),
|
|
1051
|
+
if (u.acknowledged && B.warn("db apply --plan: proceeding with acknowledged lossy operation(s) (VOLTRO_DESTRUCTIVE_OK)"), Gt(d, t)) return 2;
|
|
1033
1052
|
if (d.operations.length === 0) {
|
|
1034
|
-
let e = await J(a,
|
|
1053
|
+
let e = await J(a, A.SqlClient.pipe(k.flatMap((e) => de(e, d, {
|
|
1035
1054
|
appliedBy: process.env.USER ? `cli:${process.env.USER}` : "cli:plan",
|
|
1036
1055
|
environment: $(),
|
|
1037
1056
|
source: "file"
|
|
@@ -1039,69 +1058,69 @@ var Ne = (e) => typeof e != "string", Pe = (e, t, n, r) => {
|
|
|
1039
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);
|
|
1040
1059
|
}
|
|
1041
1060
|
X(d);
|
|
1042
|
-
let f = s(t, "--note"), p = await J(a,
|
|
1061
|
+
let f = s(t, "--note"), p = await J(a, A.SqlClient.pipe(k.flatMap((e) => ne(e, d, {
|
|
1043
1062
|
declared: i,
|
|
1044
1063
|
appliedBy: process.env.USER ? `cli:${process.env.USER}` : "cli:plan",
|
|
1045
1064
|
environment: $(),
|
|
1046
1065
|
source: "file",
|
|
1047
1066
|
...f ? { notes: f } : {},
|
|
1048
|
-
replan: () =>
|
|
1067
|
+
replan: (e) => N(e).pipe(k.map((e) => P({
|
|
1049
1068
|
declared: i,
|
|
1050
1069
|
live: e,
|
|
1051
1070
|
dialect: W(),
|
|
1052
|
-
...
|
|
1071
|
+
...M()
|
|
1053
1072
|
})))
|
|
1054
1073
|
}))));
|
|
1055
1074
|
return B.info(`db apply --plan: applied ${p.appliedOps} op(s) in ${p.durationMs}ms`, {
|
|
1056
1075
|
id: p.id,
|
|
1057
1076
|
fingerprint: p.fingerprint.slice(0, 16)
|
|
1058
1077
|
}), Q(n, i, a);
|
|
1059
|
-
},
|
|
1060
|
-
let t = H(e), n = await
|
|
1078
|
+
}, Xt = async (e) => {
|
|
1079
|
+
let t = H(e), n = await qt(t, e);
|
|
1061
1080
|
try {
|
|
1062
|
-
return await
|
|
1081
|
+
return await Zt(e, t);
|
|
1063
1082
|
} finally {
|
|
1064
1083
|
await n.close();
|
|
1065
1084
|
}
|
|
1066
|
-
},
|
|
1067
|
-
let r =
|
|
1068
|
-
if (i) return
|
|
1085
|
+
}, Zt = async (e, n) => {
|
|
1086
|
+
let r = Kt(e), i = s(e, "--plan");
|
|
1087
|
+
if (i) return Yt(i, e, n);
|
|
1069
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;
|
|
1070
1089
|
let a = await Z(n);
|
|
1071
1090
|
if (a === void 0) return B.warn("db apply: no schema files found", { root: n }), 1;
|
|
1072
|
-
let o = await q(), c = await
|
|
1091
|
+
let o = await q(), c = await mn(n, o);
|
|
1073
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;
|
|
1074
|
-
let l = await Y(o), u =
|
|
1093
|
+
let l = await Y(o), u = P({
|
|
1075
1094
|
declared: a,
|
|
1076
1095
|
live: l,
|
|
1077
1096
|
dialect: W(),
|
|
1078
|
-
...
|
|
1097
|
+
...M(),
|
|
1079
1098
|
...r === void 0 ? {} : { onlineAfter: r }
|
|
1080
1099
|
});
|
|
1081
|
-
X(u), await
|
|
1082
|
-
let d =
|
|
1100
|
+
X(u), await Ht(u, o);
|
|
1101
|
+
let d = zt(u), f = d.plan;
|
|
1083
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;
|
|
1084
|
-
if (d.acknowledged && B.warn(`db apply: proceeding with ${u.summary.blocked} acknowledged lossy operation(s) (VOLTRO_DESTRUCTIVE_OK)`),
|
|
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;
|
|
1085
1104
|
if (f.operations.length === 0) {
|
|
1086
1105
|
B.info("db apply: schema is up to date — no DDL to apply (change triggers are reconciled separately below)");
|
|
1087
|
-
let t = await J(o,
|
|
1106
|
+
let t = await J(o, A.SqlClient.pipe(k.flatMap((e) => de(e, f, {
|
|
1088
1107
|
appliedBy: process.env.USER ? `cli:${process.env.USER}` : "cli:apply",
|
|
1089
1108
|
environment: $(),
|
|
1090
1109
|
source: "auto-diff"
|
|
1091
1110
|
}))));
|
|
1092
|
-
return t === "recorded" && B.info(`db apply: recorded fingerprint=${f.toFingerprint.slice(0, 16)} (0 operations)`), await
|
|
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);
|
|
1093
1112
|
}
|
|
1094
|
-
let p = s(e, "--note"), m = await J(o,
|
|
1113
|
+
let p = s(e, "--note"), m = await J(o, A.SqlClient.pipe(k.flatMap((e) => ne(e, f, {
|
|
1095
1114
|
declared: a,
|
|
1096
1115
|
appliedBy: process.env.USER ? `cli:${process.env.USER}` : "cli:user",
|
|
1097
1116
|
environment: $(),
|
|
1098
1117
|
source: "auto-diff",
|
|
1099
1118
|
...p ? { notes: p } : {},
|
|
1100
|
-
replan: () =>
|
|
1119
|
+
replan: (e) => N(e).pipe(k.map((e) => P({
|
|
1101
1120
|
declared: a,
|
|
1102
1121
|
live: e,
|
|
1103
1122
|
dialect: W(),
|
|
1104
|
-
...
|
|
1123
|
+
...M(),
|
|
1105
1124
|
...r === void 0 ? {} : { onlineAfter: r }
|
|
1106
1125
|
})))
|
|
1107
1126
|
}))));
|
|
@@ -1109,7 +1128,7 @@ var Ne = (e) => typeof e != "string", Pe = (e, t, n, r) => {
|
|
|
1109
1128
|
id: m.id,
|
|
1110
1129
|
fingerprint: m.fingerprint.slice(0, 16)
|
|
1111
1130
|
}), Q(n, a, o);
|
|
1112
|
-
},
|
|
1131
|
+
}, Qt = (e) => {
|
|
1113
1132
|
let t = [];
|
|
1114
1133
|
for (let n of e.tables) for (let e of n.columns) {
|
|
1115
1134
|
let r = e.references;
|
|
@@ -1122,7 +1141,7 @@ var Ne = (e) => typeof e != "string", Pe = (e, t, n, r) => {
|
|
|
1122
1141
|
});
|
|
1123
1142
|
}
|
|
1124
1143
|
return t;
|
|
1125
|
-
},
|
|
1144
|
+
}, $t = (e) => {
|
|
1126
1145
|
let t = [];
|
|
1127
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({
|
|
1128
1147
|
table: n.name,
|
|
@@ -1131,7 +1150,7 @@ var Ne = (e) => typeof e != "string", Pe = (e, t, n, r) => {
|
|
|
1131
1150
|
name: e.name
|
|
1132
1151
|
});
|
|
1133
1152
|
return t;
|
|
1134
|
-
},
|
|
1153
|
+
}, en = (e, t) => {
|
|
1135
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)))];
|
|
1136
1155
|
return {
|
|
1137
1156
|
...t,
|
|
@@ -1141,88 +1160,88 @@ var Ne = (e) => typeof e != "string", Pe = (e, t, n, r) => {
|
|
|
1141
1160
|
blocked: 0
|
|
1142
1161
|
}
|
|
1143
1162
|
};
|
|
1144
|
-
},
|
|
1163
|
+
}, tn = (e) => {
|
|
1145
1164
|
if (e === void 0) return "empty";
|
|
1146
1165
|
if (e === "empty" || e === "copy") return e;
|
|
1147
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}"`);
|
|
1148
|
-
},
|
|
1167
|
+
}, nn = (e) => {
|
|
1149
1168
|
if (e !== void 0) {
|
|
1150
1169
|
if (e === "namespace" || e === "neon-cow") return e;
|
|
1151
1170
|
throw new r(`voltro db branch: --prefer must be one of namespace|neon-cow, got "${e}"`);
|
|
1152
1171
|
}
|
|
1153
|
-
},
|
|
1154
|
-
let t = H(e), n =
|
|
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();
|
|
1155
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;
|
|
1156
1175
|
let d = await Z(t);
|
|
1157
1176
|
if (d === void 0) return B.warn("db branch: no schema files found", {
|
|
1158
1177
|
root: t,
|
|
1159
1178
|
hint: "looked for *.entity.ts / *.schema.ts / schema.ts"
|
|
1160
1179
|
}), 1;
|
|
1161
|
-
let f = U(), p =
|
|
1180
|
+
let f = U(), p = ke({
|
|
1162
1181
|
seed: n,
|
|
1163
1182
|
...f.url === void 0 ? {} : { dbUrl: f.url },
|
|
1164
1183
|
...i === void 0 ? {} : { prefer: i }
|
|
1165
1184
|
});
|
|
1166
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;
|
|
1167
|
-
let m = f.schema ?? "public", h = s(e, "--name") ??
|
|
1186
|
+
let m = f.schema ?? "public", h = s(e, "--name") ?? ee(t), g = s(e, "--pr"), _ = g === void 0 ? 0 : Number(g);
|
|
1168
1187
|
if (!Number.isInteger(_) || _ < 0) throw new r(`voltro db branch: --pr must be a non-negative integer, got "${String(g)}"`);
|
|
1169
|
-
let v =
|
|
1188
|
+
let v = ye(h, _), y = await l(u), b = y.makeSqlLayer(f), x = y.makeSqlLayer({
|
|
1170
1189
|
...f,
|
|
1171
1190
|
schema: v
|
|
1172
|
-
}),
|
|
1191
|
+
}), S = await Y(b), C = P({
|
|
1173
1192
|
declared: d,
|
|
1174
|
-
live:
|
|
1193
|
+
live: S,
|
|
1175
1194
|
dialect: u,
|
|
1176
|
-
...
|
|
1195
|
+
...M(),
|
|
1177
1196
|
...c === void 0 ? {} : { onlineAfter: c }
|
|
1178
|
-
}),
|
|
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({
|
|
1179
1198
|
declared: d,
|
|
1180
|
-
live: await Y(
|
|
1199
|
+
live: await Y(x),
|
|
1181
1200
|
dialect: u,
|
|
1182
|
-
...
|
|
1201
|
+
...M(),
|
|
1183
1202
|
...c === void 0 ? {} : { onlineAfter: c }
|
|
1184
|
-
}),
|
|
1203
|
+
}), j = await fe({
|
|
1185
1204
|
branchId: v,
|
|
1186
1205
|
mechanism: p,
|
|
1187
|
-
branchedTables:
|
|
1188
|
-
replayedForeignKeys:
|
|
1206
|
+
branchedTables: w.length,
|
|
1207
|
+
replayedForeignKeys: T.length,
|
|
1189
1208
|
keep: a,
|
|
1190
1209
|
log: (e) => {
|
|
1191
1210
|
o || B.info(`db branch: ${e}`);
|
|
1192
1211
|
},
|
|
1193
1212
|
provision: async () => {
|
|
1194
|
-
await
|
|
1213
|
+
await Ee({
|
|
1195
1214
|
appSlug: h,
|
|
1196
1215
|
prNumber: _,
|
|
1197
1216
|
seed: n,
|
|
1198
|
-
tableNames:
|
|
1217
|
+
tableNames: w,
|
|
1199
1218
|
parentNamespace: m,
|
|
1200
|
-
foreignKeys:
|
|
1201
|
-
indexNames:
|
|
1219
|
+
foreignKeys: T,
|
|
1220
|
+
indexNames: E,
|
|
1202
1221
|
prefer: "namespace",
|
|
1203
1222
|
...f.url === void 0 ? {} : { dbUrl: f.url }
|
|
1204
|
-
},
|
|
1223
|
+
}, D);
|
|
1205
1224
|
},
|
|
1206
|
-
fidelityPlan: async () =>
|
|
1207
|
-
plan:
|
|
1225
|
+
fidelityPlan: async () => en(C, await O()),
|
|
1226
|
+
plan: O,
|
|
1208
1227
|
apply: async (e) => {
|
|
1209
|
-
await J(
|
|
1228
|
+
await J(x, A.SqlClient.pipe(k.flatMap((t) => ne(t, e, {
|
|
1210
1229
|
declared: d,
|
|
1211
1230
|
appliedBy: "cli:db-branch",
|
|
1212
1231
|
environment: $(),
|
|
1213
1232
|
source: "auto-diff",
|
|
1214
1233
|
notes: `migration rehearsal on branch ${v}`,
|
|
1215
|
-
replan: () =>
|
|
1234
|
+
replan: () => k.promise(O)
|
|
1216
1235
|
}))));
|
|
1217
1236
|
},
|
|
1218
|
-
replan: async () => await
|
|
1237
|
+
replan: async () => await O(),
|
|
1219
1238
|
teardown: async () => {
|
|
1220
|
-
await
|
|
1239
|
+
await Ae(v, "namespace", D);
|
|
1221
1240
|
}
|
|
1222
1241
|
});
|
|
1223
|
-
return o ?
|
|
1224
|
-
},
|
|
1225
|
-
let t = Math.max(1, Number(s(e, "--limit") ?? "20")), n = await J(await q(),
|
|
1242
|
+
return o ? te(1, `${JSON.stringify(j, null, 2)}\n`) : console.log(`\n${le(j)}\n`), ae(j);
|
|
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`
|
|
1226
1245
|
SELECT ${e("id")}, ${e("fingerprint")}, ${e("operations")},
|
|
1227
1246
|
${e("appliedBy")}, ${e("environment")}, ${e("source")},
|
|
1228
1247
|
${e("durationMs")}, ${e("notes")}, ${e("appliedAt")}
|
|
@@ -1235,20 +1254,20 @@ var Ne = (e) => typeof e != "string", Pe = (e, t, n, r) => {
|
|
|
1235
1254
|
for (let e of n) {
|
|
1236
1255
|
let t = 0;
|
|
1237
1256
|
try {
|
|
1238
|
-
t = JSON.parse(
|
|
1257
|
+
t = JSON.parse(un(e.operations)).length;
|
|
1239
1258
|
} catch {}
|
|
1240
|
-
console.log(` ${e.id} fp=${
|
|
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`);
|
|
1241
1260
|
}
|
|
1242
1261
|
return console.log(), 0;
|
|
1243
|
-
},
|
|
1262
|
+
}, on = async (e) => {
|
|
1244
1263
|
let t = e[0];
|
|
1245
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;
|
|
1246
|
-
let n = await q(), r = await J(n,
|
|
1265
|
+
let n = await q(), r = await J(n, A.SqlClient.pipe(k.flatMap((e) => e`SELECT ${e("id")}, ${e("operations")}
|
|
1247
1266
|
FROM ${e("_voltro_migration_plans")} WHERE ${e("id")} = ${t}`)));
|
|
1248
1267
|
if (r.length === 0) return console.error(`restore-snapshot: plan '${t}' not found`), 1;
|
|
1249
1268
|
let i;
|
|
1250
1269
|
try {
|
|
1251
|
-
i = JSON.parse(
|
|
1270
|
+
i = JSON.parse(un(r[0].operations));
|
|
1252
1271
|
} catch {
|
|
1253
1272
|
return console.error(`restore-snapshot: plan '${t}' has corrupted operations JSON`), 1;
|
|
1254
1273
|
}
|
|
@@ -1262,7 +1281,7 @@ var Ne = (e) => typeof e != "string", Pe = (e, t, n, r) => {
|
|
|
1262
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;
|
|
1263
1282
|
let s = 0;
|
|
1264
1283
|
for (let e of a) {
|
|
1265
|
-
let t = await J(n,
|
|
1284
|
+
let t = await J(n, A.SqlClient.pipe(k.flatMap((t) => t`
|
|
1266
1285
|
SELECT column_name FROM information_schema.columns
|
|
1267
1286
|
WHERE ${t.unsafe(K(W()))}
|
|
1268
1287
|
AND table_name = ${e.table}
|
|
@@ -1274,11 +1293,11 @@ var Ne = (e) => typeof e != "string", Pe = (e, t, n, r) => {
|
|
|
1274
1293
|
continue;
|
|
1275
1294
|
}
|
|
1276
1295
|
let r = t[0].column_name;
|
|
1277
|
-
await J(n,
|
|
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})`);
|
|
1278
1297
|
}
|
|
1279
1298
|
let c = 0;
|
|
1280
1299
|
for (let e of o) {
|
|
1281
|
-
let t = await J(n,
|
|
1300
|
+
let t = await J(n, A.SqlClient.pipe(k.flatMap((t) => t`
|
|
1282
1301
|
SELECT table_name FROM information_schema.tables
|
|
1283
1302
|
WHERE ${t.unsafe(K(W()))}
|
|
1284
1303
|
AND table_name LIKE ${e.table + "__dropped_%"}
|
|
@@ -1289,18 +1308,18 @@ var Ne = (e) => typeof e != "string", Pe = (e, t, n, r) => {
|
|
|
1289
1308
|
continue;
|
|
1290
1309
|
}
|
|
1291
1310
|
let r = t[0].table_name;
|
|
1292
|
-
await J(n,
|
|
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})`);
|
|
1293
1312
|
}
|
|
1294
1313
|
return console.log(`\n✓ restored ${s} column(s) + ${c} table(s) from plan '${t}'\n`), 0;
|
|
1295
|
-
},
|
|
1314
|
+
}, sn = async (e) => {
|
|
1296
1315
|
let t = s(e, "--before");
|
|
1297
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;
|
|
1298
1317
|
let n = t.replace(/[^0-9]/g, "");
|
|
1299
1318
|
if (n.length < 8) return console.error(`gc-snapshots: --before must be at least a full date (YYYY-MM-DD), got "${t}"`), 2;
|
|
1300
|
-
let r = (n + "00000000000000").slice(0, 14), i = e.includes("--dry-run"), a = await q(), o = await J(a,
|
|
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`
|
|
1301
1320
|
SELECT table_name, column_name FROM information_schema.columns
|
|
1302
1321
|
WHERE ${e.unsafe(K(W()))} AND column_name LIKE ${"%__dropped_%"}
|
|
1303
|
-
`))), c = await J(a,
|
|
1322
|
+
`))), c = await J(a, A.SqlClient.pipe(k.flatMap((e) => e`
|
|
1304
1323
|
SELECT table_name FROM information_schema.tables
|
|
1305
1324
|
WHERE ${e.unsafe(K(W()))} AND table_name LIKE ${"%__dropped_%"}
|
|
1306
1325
|
`))), l = (e) => {
|
|
@@ -1309,37 +1328,37 @@ var Ne = (e) => typeof e != "string", Pe = (e, t, n, r) => {
|
|
|
1309
1328
|
}, u = 0;
|
|
1310
1329
|
for (let e of o) {
|
|
1311
1330
|
let t = l(e.column_name);
|
|
1312
|
-
t === null || t >= r || (console.log(` ${i ? "[dry-run] would drop column" : "dropping column"} ${e.table_name}.${e.column_name}`), i || await J(a,
|
|
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++);
|
|
1313
1332
|
}
|
|
1314
1333
|
for (let e of c) {
|
|
1315
1334
|
let t = l(e.table_name);
|
|
1316
|
-
t === null || t >= r || (console.log(` ${i ? "[dry-run] would drop table" : "dropping table"} ${e.table_name}`), i || await J(a,
|
|
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++);
|
|
1317
1336
|
}
|
|
1318
1337
|
return console.log(`\n${i ? `[dry-run] ${u} snapshot(s) would be dropped` : `✓ dropped ${u} snapshot(s)`} (older than ${r}).\n`), 0;
|
|
1319
|
-
},
|
|
1338
|
+
}, cn = async (e) => {
|
|
1320
1339
|
let t = s(e, "--before");
|
|
1321
1340
|
if (!t) return console.error("voltro db squash --before <iso-date> [--note \"<text>\"]"), 2;
|
|
1322
1341
|
let n = t;
|
|
1323
1342
|
if (Number.isNaN(new Date(n).getTime())) return console.error(`voltro db squash: --before '${n}' is not a valid ISO date`), 2;
|
|
1324
1343
|
let r = s(e, "--note"), i = H(e), a = await Z(i);
|
|
1325
1344
|
if (a === void 0) return B.warn("db squash: no schema files found", { root: i }), 1;
|
|
1326
|
-
let o =
|
|
1345
|
+
let o = ce(oe(a)), c = await q();
|
|
1327
1346
|
try {
|
|
1328
|
-
let e = await J(c,
|
|
1347
|
+
let e = await J(c, ge({
|
|
1329
1348
|
before: n,
|
|
1330
1349
|
fingerprint: o,
|
|
1331
1350
|
appliedBy: process.env.USER ?? "cli",
|
|
1332
1351
|
environment: $(),
|
|
1333
1352
|
...r === void 0 ? {} : { note: r }
|
|
1334
1353
|
}));
|
|
1335
|
-
return console.log(`\n✓ squashed ${e.squashedCount} migration plan(s)\n snapshot id: ${e.snapshotId}\n fingerprint: ${
|
|
1354
|
+
return console.log(`\n✓ squashed ${e.squashedCount} migration plan(s)\n snapshot id: ${e.snapshotId}\n fingerprint: ${F(e.snapshotFingerprint)}\n`), 0;
|
|
1336
1355
|
} catch (e) {
|
|
1337
1356
|
return console.error(`squash refused: ${e.message}`), 1;
|
|
1338
1357
|
}
|
|
1339
|
-
},
|
|
1358
|
+
}, ln = async (e) => {
|
|
1340
1359
|
try {
|
|
1341
|
-
let t = await Y(e), n =
|
|
1342
|
-
await J(e,
|
|
1360
|
+
let t = await Y(e), n = ce(t);
|
|
1361
|
+
await J(e, A.SqlClient.pipe(k.flatMap((e) => e`
|
|
1343
1362
|
UPDATE ${e("_voltro_migration_plans")}
|
|
1344
1363
|
SET ${e("liveFingerprint")} = ${n}
|
|
1345
1364
|
WHERE ${e("id")} = (
|
|
@@ -1351,7 +1370,7 @@ var Ne = (e) => typeof e != "string", Pe = (e, t, n, r) => {
|
|
|
1351
1370
|
AND ${e("liveFingerprint")} IS NULL
|
|
1352
1371
|
`)));
|
|
1353
1372
|
} catch {}
|
|
1354
|
-
},
|
|
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 ? {
|
|
1355
1374
|
accept: !1,
|
|
1356
1375
|
reason: "no-declared-schema"
|
|
1357
1376
|
} : e > 0 ? {
|
|
@@ -1360,38 +1379,38 @@ var Ne = (e) => typeof e != "string", Pe = (e, t, n, r) => {
|
|
|
1360
1379
|
} : {
|
|
1361
1380
|
accept: !0,
|
|
1362
1381
|
reason: "converged"
|
|
1363
|
-
},
|
|
1364
|
-
let t = e.includes("--accept"), n = await q(), r = await J(n,
|
|
1382
|
+
}, pn = async (e) => {
|
|
1383
|
+
let t = e.includes("--accept"), n = await q(), r = await J(n, A.SqlClient.pipe(k.flatMap((e) => e`
|
|
1365
1384
|
SELECT * FROM ${e("_voltro_migration_plans")}
|
|
1366
1385
|
ORDER BY ${e("appliedAt")} DESC
|
|
1367
1386
|
LIMIT 1
|
|
1368
|
-
`))), i = await Y(n), a =
|
|
1369
|
-
if (r.length === 0) return B.info("db drift: no _voltro_migration_plans rows yet"), console.log(`live user-schema fingerprint: ${
|
|
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;
|
|
1370
1389
|
let o = r[0];
|
|
1371
|
-
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 ${
|
|
1372
|
-
if (o.liveFingerprint === a) return B.info(`db drift: live matches last applied (${
|
|
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;
|
|
1373
1392
|
let s = await (async () => {
|
|
1374
1393
|
try {
|
|
1375
1394
|
let t = await Z(H(e));
|
|
1376
|
-
return t === void 0 ? void 0 :
|
|
1395
|
+
return t === void 0 ? void 0 : P({
|
|
1377
1396
|
declared: t,
|
|
1378
1397
|
live: i,
|
|
1379
1398
|
dialect: W(),
|
|
1380
|
-
...
|
|
1399
|
+
...M()
|
|
1381
1400
|
}).operations;
|
|
1382
1401
|
} catch {
|
|
1383
1402
|
return;
|
|
1384
1403
|
}
|
|
1385
1404
|
})();
|
|
1386
1405
|
if (t) {
|
|
1387
|
-
let e =
|
|
1406
|
+
let e = fn(s?.length);
|
|
1388
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;
|
|
1389
1408
|
if (!e.accept && s !== void 0) {
|
|
1390
1409
|
B.error(`db drift --accept: refusing — ${s.length} operation(s) still pending against your declared schema.`), console.log();
|
|
1391
1410
|
for (let e of s.slice(0, 10)) console.log(` - ${e.op.kind} ${"table" in e.op ? `[${e.op.table}]` : ""}`);
|
|
1392
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;
|
|
1393
1412
|
}
|
|
1394
|
-
return await J(n,
|
|
1413
|
+
return await J(n, A.SqlClient.pipe(k.flatMap((e) => e`
|
|
1395
1414
|
UPDATE ${e("_voltro_migration_plans")}
|
|
1396
1415
|
SET ${e("liveFingerprint")} = ${a}
|
|
1397
1416
|
WHERE ${e("id")} = (
|
|
@@ -1400,13 +1419,13 @@ var Ne = (e) => typeof e != "string", Pe = (e, t, n, r) => {
|
|
|
1400
1419
|
ORDER BY ${e("appliedAt")} DESC LIMIT 1
|
|
1401
1420
|
) AS ${e("newest")}
|
|
1402
1421
|
)
|
|
1403
|
-
`))), B.info(`db drift: accepted the live schema as the baseline (${
|
|
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;
|
|
1404
1423
|
}
|
|
1405
|
-
return B.error("db drift: live schema DIVERGED from last applied state"), console.log(), console.log(` baseline: ${
|
|
1406
|
-
},
|
|
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) => {
|
|
1407
1426
|
let n = $();
|
|
1408
1427
|
try {
|
|
1409
|
-
let r = await J(t,
|
|
1428
|
+
let r = await J(t, A.SqlClient.pipe(k.flatMap((t) => he(t, {
|
|
1410
1429
|
projectRoot: e,
|
|
1411
1430
|
env: n,
|
|
1412
1431
|
appliedBy: process.env.USER ? `cli:${process.env.USER}` : "cli:user"
|
|
@@ -1415,10 +1434,10 @@ var Ne = (e) => typeof e != "string", Pe = (e, t, n, r) => {
|
|
|
1415
1434
|
} catch (e) {
|
|
1416
1435
|
return { failed: e };
|
|
1417
1436
|
}
|
|
1418
|
-
},
|
|
1437
|
+
}, hn = async (e) => {
|
|
1419
1438
|
let t = H(e), n = await q(), r = $();
|
|
1420
|
-
await J(n,
|
|
1421
|
-
let i = await J(n,
|
|
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, {
|
|
1422
1441
|
projectRoot: t,
|
|
1423
1442
|
env: r,
|
|
1424
1443
|
appliedBy: process.env.USER ? `cli:${process.env.USER}` : "cli:user"
|
|
@@ -1427,16 +1446,16 @@ var Ne = (e) => typeof e != "string", Pe = (e, t, n, r) => {
|
|
|
1427
1446
|
applied: i.applied.map((e) => `${e.id} (${e.durationMs}ms)`),
|
|
1428
1447
|
skipped: i.skipped.length
|
|
1429
1448
|
}), 0);
|
|
1430
|
-
},
|
|
1431
|
-
let n = H(e), r = c(e,
|
|
1449
|
+
}, gn = async (e) => {
|
|
1450
|
+
let n = H(e), r = c(e, Dt);
|
|
1432
1451
|
if (!r) return B.error("voltro db rollback-file <migration-id>"), 2;
|
|
1433
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;
|
|
1434
|
-
let i = await J(await q(),
|
|
1453
|
+
let i = await J(await q(), A.SqlClient.pipe(k.flatMap((e) => pe(e, {
|
|
1435
1454
|
projectRoot: n,
|
|
1436
1455
|
id: r
|
|
1437
1456
|
}))));
|
|
1438
1457
|
return B.info(`db rollback-file: rolled back ${i.id} in ${i.durationMs}ms`), 0;
|
|
1439
|
-
},
|
|
1458
|
+
}, _n = () => {
|
|
1440
1459
|
let e = /* @__PURE__ */ new Date();
|
|
1441
1460
|
return [
|
|
1442
1461
|
e.getUTCFullYear(),
|
|
@@ -1446,7 +1465,7 @@ var Ne = (e) => typeof e != "string", Pe = (e, t, n, r) => {
|
|
|
1446
1465
|
String(e.getUTCMinutes()).padStart(2, "0"),
|
|
1447
1466
|
String(e.getUTCSeconds()).padStart(2, "0")
|
|
1448
1467
|
].join("");
|
|
1449
|
-
},
|
|
1468
|
+
}, vn = (e) => e.trim().toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "") || "migration", yn = (e, t) => `import { defineMigration, SqlClient } from '@voltro/database'
|
|
1450
1469
|
import { Effect } from 'effect'
|
|
1451
1470
|
|
|
1452
1471
|
// A hand-written migration. Reach for this when the DECLARATIVE differ can't
|
|
@@ -1478,50 +1497,50 @@ export default defineMigration({
|
|
|
1478
1497
|
}),
|
|
1479
1498
|
],
|
|
1480
1499
|
})
|
|
1481
|
-
`,
|
|
1482
|
-
plan:
|
|
1483
|
-
apply:
|
|
1484
|
-
branch:
|
|
1485
|
-
plans:
|
|
1486
|
-
drift:
|
|
1487
|
-
files:
|
|
1488
|
-
"rollback-file":
|
|
1489
|
-
migrate:
|
|
1490
|
-
rollback:
|
|
1491
|
-
status:
|
|
1492
|
-
seed:
|
|
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,
|
|
1493
1512
|
generate: async (e) => {
|
|
1494
|
-
let { value: t, rest: n } = a(e, "--root"), { value: r, rest: i } = a(n, "--name"), o = t ?
|
|
1495
|
-
return await
|
|
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;
|
|
1496
1515
|
},
|
|
1497
|
-
squash:
|
|
1498
|
-
"restore-snapshot":
|
|
1499
|
-
"gc-snapshots":
|
|
1516
|
+
squash: cn,
|
|
1517
|
+
"restore-snapshot": on,
|
|
1518
|
+
"gc-snapshots": sn,
|
|
1500
1519
|
adopt: async (e) => {
|
|
1501
1520
|
let t = (t) => {
|
|
1502
1521
|
let n = e.indexOf(`--${t}`);
|
|
1503
1522
|
return n === -1 ? void 0 : e[n + 1];
|
|
1504
1523
|
}, n = t("from"), r = t("into"), a = t("map");
|
|
1505
1524
|
if (n === void 0 || r === void 0 || a === void 0) return console.error("voltro db adopt --from <table> --into <table> --map <file.ts> [--apply] [--keep-source]"), console.error(" Dry run unless --apply. The map file default-exports { map, leaveUnset? }."), 1;
|
|
1506
|
-
let o = (await i(
|
|
1525
|
+
let o = (await i(T(process.cwd(), a))).default;
|
|
1507
1526
|
if (o?.map === void 0) return console.error(`voltro db adopt: ${a} must default-export { map: { <targetColumn>: <source> } }`), 1;
|
|
1508
1527
|
let s = {
|
|
1509
1528
|
from: n,
|
|
1510
1529
|
into: r,
|
|
1511
1530
|
map: o.map,
|
|
1512
1531
|
...o.leaveUnset ? { leaveUnset: o.leaveUnset } : {}
|
|
1513
|
-
}, c = W(), l = await q(), u = await J(l,
|
|
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) => ({
|
|
1514
1533
|
name: e.name,
|
|
1515
1534
|
nullable: e.nullable,
|
|
1516
1535
|
hasDefault: e.defaultValue !== void 0 && e.defaultValue !== null
|
|
1517
1536
|
})), f = d(n), p = d(r);
|
|
1518
1537
|
if (f === void 0) return console.error(`voltro db adopt: '${n}' does not exist in the database`), 1;
|
|
1519
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;
|
|
1520
|
-
let m = async (e) => await J(l,
|
|
1521
|
-
for (let e of
|
|
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);
|
|
1522
1541
|
if (g.fatal) return 1;
|
|
1523
1542
|
if (!e.includes("--apply")) return console.log(""), console.log(" (dry run — nothing written. Re-run with --apply.)"), 0;
|
|
1524
|
-
let _ = await
|
|
1543
|
+
let _ = await He(s, g, c, "id", void 0, m, { keepSource: e.includes("--keep-source") });
|
|
1525
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);
|
|
1526
1545
|
},
|
|
1527
1546
|
"scan-credentials": async (e) => {
|
|
@@ -1536,8 +1555,8 @@ export default defineMigration({
|
|
|
1536
1555
|
column: o
|
|
1537
1556
|
});
|
|
1538
1557
|
}
|
|
1539
|
-
let i = [...
|
|
1540
|
-
return console.log(
|
|
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);
|
|
1541
1560
|
},
|
|
1542
1561
|
"encrypt-column": async (e) => {
|
|
1543
1562
|
let t = W(), n = e.includes("--dry-run"), i = e.includes("--yes"), a = (t) => {
|
|
@@ -1545,73 +1564,81 @@ export default defineMigration({
|
|
|
1545
1564
|
return n >= 0 ? e[n + 1] : void 0;
|
|
1546
1565
|
}, s = Math.max(1, Number(a("--batch") ?? 500)), c = a("--key-env") ?? "FIELD_ENCRYPTION_KEY", l = process.env[c];
|
|
1547
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.`);
|
|
1548
|
-
let u =
|
|
1567
|
+
let u = Me(l), d = o(e, Dt).filter((e) => e.includes(".")).map(ft);
|
|
1549
1568
|
if (d.length === 0) throw new r("voltro db encrypt-column: name at least one <table>.<column>");
|
|
1550
1569
|
let f = await q(), p = [];
|
|
1551
1570
|
for (let e of d) {
|
|
1552
|
-
let a = G(e.table), o = G(e.column), l = await J(f,
|
|
1553
|
-
let i = await
|
|
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))));
|
|
1554
1573
|
if (i.length === 0) throw new r(`voltro db encrypt-column: ${e.table}.${e.column} does not exist on this database`);
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
if (
|
|
1561
|
-
|
|
1562
|
-
let g = d.filter((t) => mt(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;
|
|
1563
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;
|
|
1564
|
-
let _ = 0, v = 0, y = 0, b = [];
|
|
1582
|
+
let _ = 0, v = 0, y = 0, b = 0, x = [];
|
|
1565
1583
|
for (let t of d) {
|
|
1566
1584
|
if (t.v === null || t.v === void 0 || t.v === "") {
|
|
1567
|
-
|
|
1585
|
+
y += 1;
|
|
1568
1586
|
continue;
|
|
1569
1587
|
}
|
|
1570
|
-
if (typeof t.v == "string" &&
|
|
1571
|
-
|
|
1588
|
+
if (typeof t.v == "string" && I(t.v)) {
|
|
1589
|
+
let n = Ct(t.v, u, e);
|
|
1590
|
+
if (n === void 0) {
|
|
1591
|
+
_ += 1;
|
|
1592
|
+
continue;
|
|
1593
|
+
}
|
|
1594
|
+
x.push({
|
|
1595
|
+
id: t.id,
|
|
1596
|
+
value: n
|
|
1597
|
+
}), v += 1;
|
|
1572
1598
|
continue;
|
|
1573
1599
|
}
|
|
1574
|
-
let n =
|
|
1600
|
+
let n = _t(t.v, u, e);
|
|
1575
1601
|
if (n === void 0) {
|
|
1576
|
-
|
|
1602
|
+
y += 1;
|
|
1577
1603
|
continue;
|
|
1578
1604
|
}
|
|
1579
|
-
|
|
1605
|
+
x.push({
|
|
1580
1606
|
id: t.id,
|
|
1581
1607
|
value: n
|
|
1582
|
-
}),
|
|
1608
|
+
}), b += 1;
|
|
1583
1609
|
}
|
|
1584
|
-
if (!n &&
|
|
1585
|
-
let n =
|
|
1586
|
-
await J(f,
|
|
1587
|
-
for (let r of n) await
|
|
1588
|
-
})))), B.info(`encrypt-column ${e.table}.${e.column}: ${Math.min(t + n.length,
|
|
1610
|
+
if (!n && x.length > 0) for (let t = 0; t < x.length; t += s) {
|
|
1611
|
+
let n = x.slice(t, t + s);
|
|
1612
|
+
await J(f, A.SqlClient.pipe(k.flatMap((t) => k.promise(async () => {
|
|
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
|
+
})))), B.info(`encrypt-column ${e.table}.${e.column}: ${Math.min(t + n.length, x.length)}/${x.length}`);
|
|
1589
1615
|
}
|
|
1590
1616
|
p.push({
|
|
1591
1617
|
table: e.table,
|
|
1592
1618
|
column: e.column,
|
|
1593
1619
|
scanned: d.length,
|
|
1594
1620
|
alreadyEncrypted: _,
|
|
1595
|
-
|
|
1596
|
-
|
|
1621
|
+
recoded: v,
|
|
1622
|
+
empty: y,
|
|
1623
|
+
encrypted: b
|
|
1597
1624
|
});
|
|
1598
1625
|
}
|
|
1599
1626
|
console.log(`field encryption · dialect ${t}${n ? " · DRY RUN, nothing written" : ""}`), console.log("");
|
|
1600
|
-
for (let e of p) console.log(
|
|
1601
|
-
return n || console.log(
|
|
1627
|
+
for (let e of p) console.log(gt(e, n));
|
|
1628
|
+
return n || console.log(St(d)), 0;
|
|
1602
1629
|
}
|
|
1603
|
-
},
|
|
1630
|
+
}, xn = (e) => Object.prototype.hasOwnProperty.call(bn, e), Sn = async (t) => {
|
|
1604
1631
|
let [n, ...r] = t;
|
|
1605
1632
|
if (!n) {
|
|
1606
1633
|
console.error("voltro db <subcommand> [args]"), console.error("subcommands:");
|
|
1607
|
-
for (let e of Object.keys(
|
|
1634
|
+
for (let e of Object.keys(bn)) console.error(` ${e}`);
|
|
1608
1635
|
return 1;
|
|
1609
1636
|
}
|
|
1610
|
-
if (!
|
|
1611
|
-
let i =
|
|
1637
|
+
if (!xn(n)) return console.error(`voltro db: unknown subcommand '${n}'`), console.error(` known: ${e.join(", ")}`), 2;
|
|
1638
|
+
let i = bn[n];
|
|
1612
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)");
|
|
1613
1640
|
let a = (e) => {
|
|
1614
|
-
|
|
1641
|
+
Ot(e) ? B.error(kt) : console.error(e), process.exit(1);
|
|
1615
1642
|
};
|
|
1616
1643
|
process.on("uncaughtException", a);
|
|
1617
1644
|
try {
|
|
@@ -1621,4 +1648,4 @@ export default defineMigration({
|
|
|
1621
1648
|
}
|
|
1622
1649
|
};
|
|
1623
1650
|
//#endregion
|
|
1624
|
-
export {
|
|
1651
|
+
export { Lt as a, fn as i, U as n, Ot as o, It as r, Sn as s, kt as t };
|