@voltro/cli 0.39.1 → 0.41.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 +232 -0
- package/dist/agentsMd-Bu_XQgVf.js +2 -0
- package/dist/{agentsMd-7zI2h5l9.js → agentsMd-D6yD7IQv.js} +31 -14
- package/dist/{apiBuild-D9FB13_2.js → apiBuild-B_iH24qf.js} +2 -2
- package/dist/apiBuild-RM5W5YXk.js +2 -0
- package/dist/bin.js +1 -1
- package/dist/{build-DORV5mLM.js → build-DUdi6F_Q.js} +100 -97
- package/dist/{checkCommand-D9qK_gtA.js → checkCommand-B2RWrpWi.js} +1 -1
- package/dist/{checkCommand-Bf6oMao4.js → checkCommand-DWL2_PPR.js} +2 -2
- package/dist/{cloudCmd-C42gaO8s.js → cloudCmd-F4YJeqM3.js} +1 -1
- package/dist/{codegenCommand-CxOyKmc1.js → codegenCommand-DkjoJ30Q.js} +2 -2
- package/dist/{codemodRunner-D-jTyvWo.js → codemodRunner-sFuWDETH.js} +520 -357
- package/dist/{commands-D6aW_6AR.js → commands-D0VR1yBB.js} +32 -32
- package/dist/{dashboardCommand-CwTZh-XZ.js → dashboardCommand-Bro7Jwts.js} +3 -3
- package/dist/{dataCommand-Cc9RiLQZ.js → dataCommand-OKC5FscP.js} +183 -172
- package/dist/{dbCommand-DSwGv9wS.js → dbCommand-BHRamDsy.js} +441 -414
- package/dist/dbCommand-C9iE1pd9.js +2 -0
- package/dist/{dev-3mgc8c-H.js → dev-D4l_YOzI.js} +1570 -1570
- package/dist/{dev-CjJAasDs.js → dev-DuqBJC7g.js} +1 -1
- package/dist/doctorCommand-Bw3V4L1j.js +2 -0
- package/dist/{doctorCommand-oLuzc-aC.js → doctorCommand-TmZTAepc.js} +386 -280
- package/dist/{dormancyCommand-Bxe4WtHU.js → dormancyCommand-CUKhRmGG.js} +1 -1
- package/dist/{embeddingsCommand-CyNQkFIc.js → embeddingsCommand-Db-iQM3l.js} +1 -1
- package/dist/{envCommand-CAkSgBbh.js → envCommand-DQ_URZq9.js} +14 -14
- package/dist/{evolveCommand-CWhBoe_P.js → evolveCommand-CghRPrGO.js} +2 -2
- package/dist/index.js +1 -1
- package/dist/{infoCommand-CTo8Jnhq.js → infoCommand-BCs_ZFnl.js} +1 -1
- package/dist/{metaCommands-DUYR--Ts.js → metaCommands-CfRLra0s.js} +1 -1
- package/dist/{migrate-BnPw2zC8.js → migrate-DLtPv2_D.js} +1 -1
- package/dist/{projectScaffold-BEhhHjPr.js → projectScaffold-BIl97_E6.js} +1 -1
- package/dist/{projectScaffold-BvhLOrLq.js → projectScaffold-mIX_DpSe.js} +1 -1
- package/dist/{runtimeTrace-gNXeLf6H.js → runtimeTrace-jFKvOPBz.js} +1 -1
- package/dist/{sdkgen-C8zz10-X.js → sdkgen-COQqHB9V.js} +1 -1
- package/dist/{serveCommand-BpK8-m1N.js → serveCommand-Cba_M2Su.js} +656 -656
- package/dist/serveCommand-DRbYK646.js +2 -0
- package/dist/serveEntry.js +1 -1
- package/dist/{start-ft_KzFTd.js → start-BjcuFME_.js} +421 -361
- package/dist/{start-BNuTWdRd.js → start-fifc0xpW.js} +1 -1
- package/dist/startEntry.js +1 -1
- package/dist/updateCommand-B2alql9k.js +2 -0
- package/dist/{updateCommand-CHBmCB17.js → updateCommand-HZQVBU3T.js} +1 -1
- package/dist/webDev-D6QeXw3P.js +2 -0
- package/dist/{webDev-CTpSY-e_.js → webDev-Dk8lFUzf.js} +672 -501
- package/dist/{webhooksCommand-EccPZQZ4.js → webhooksCommand-D7ZpH7w0.js} +1 -1
- package/package.json +35 -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 +6 -0
- package/templates/agent-docs/data.md +43 -0
- package/templates/agent-docs/plugins/governance.md +8 -0
- package/templates/agent-docs/routing.md +153 -0
- package/templates/agent-docs/security.md +24 -0
- package/templates/agent-docs/whats-new.md +49 -27
- 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-durable/tests/orders.place.test.ts +17 -4
- 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/changelog/src/pages/[slug]/page.test.tsx +8 -1
- 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/agentsMd-BFCXh2gl.js +0 -2
- package/dist/apiBuild-BmR_bIxN.js +0 -2
- package/dist/dbCommand-DcqEyxju.js +0 -2
- package/dist/doctorCommand-Cghssndo.js +0 -2
- package/dist/serveCommand-CW-goXvh.js +0 -2
- package/dist/updateCommand-6FMU2klq.js +0 -2
- package/dist/webDev-id3I5PvG.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 ue, pendingFileMigrationIds as de, planMigrations as N, recordUpToDate as fe, rehearseMigrationOnBranch as pe, rollbackFileBasedMigration as me, rollingDeployUnsafeOps as he, runFileBasedMigrations as ge, shortFingerprint as P, squashMigrationPlans as _e, unblockLossy as ve } from "@voltro/database/sql";
|
|
19
|
+
import { actorsTable as ye, branchNamespaceName as be, decodeFieldValue as xe, encodeFieldValue as Se, frameworkTables as Ce, isEncrypted as F, isMigrationDefinition as we, isRawEncoding as Te, makeNamespaceBranchExecutor as Ee, provisionBranch as De, quoteIdent as Oe, registerCoreTables as ke, resolveBranchMechanism as Ae, teardownBranch as je } from "@voltro/database";
|
|
20
|
+
import { InMemoryDataStore as Me, makeFieldCipher as Ne } from "@voltro/runtime";
|
|
21
|
+
import { createHash as Pe } from "node:crypto";
|
|
22
22
|
//#region src/adoptPlan.ts
|
|
23
|
-
var
|
|
23
|
+
var Fe = (e) => typeof e != "string", Ie = (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 (Fe(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
|
+
}, Le = (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
|
+
], Re = (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 Le(e, t).entries()) r.push(` ${n + 1}. ${i}`);
|
|
97
97
|
return r;
|
|
98
|
-
},
|
|
99
|
-
let a =
|
|
98
|
+
}, ze = (e) => e === "mysql" || e === "mariadb" ? (e) => `\`${e}\`` : e === "mssql" ? (e) => `[${e}]` : (e) => `"${e}"`, Be = (e) => `${e}__adopt_snapshot`, Ve = (e, t, n, r, i) => {
|
|
99
|
+
let a = ze(n), o = Be(e.from), s = t.assignments.map((e) => e.target), c = t.assignments.map((e) => e.raw ? e.source : a(e.source));
|
|
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
|
+
}, He = (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
|
+
}, Ue = 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 = Ve(e, t, n, r, i), c = Be(e.from), l = He(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 = He(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
|
+
}, I = [
|
|
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
|
+
], We = [
|
|
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
|
+
], Ge = (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
|
+
}, Ke = (e, t, n = I) => n.map((n) => `${Ge(e, t)} LIKE '%${n}%'`).join("\n OR "), qe = ["_omitted", "__redacted"], Je = (e, t) => {
|
|
204
204
|
let n = e.toLowerCase();
|
|
205
205
|
return t.some((e) => n.includes(e));
|
|
206
|
-
},
|
|
206
|
+
}, Ye = (e, t = []) => {
|
|
207
207
|
if (Array.isArray(e)) {
|
|
208
|
-
for (let n of e)
|
|
208
|
+
for (let n of e) Ye(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), Ye(r, t);
|
|
212
212
|
return t;
|
|
213
|
-
},
|
|
213
|
+
}, Xe = (e) => Array.isArray(e) ? e.map(Xe) : typeof e == "object" && e ? Object.fromEntries(Object.entries(e).map(([e, t]) => [e, qe.includes(e) ? null : Xe(t)])) : e, Ze = (e, t = I) => {
|
|
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: Ye(n).some((e) => Je(e, t)),
|
|
226
|
+
redactionMarkerOnly: !Je(JSON.stringify(Xe(n)) ?? "", t),
|
|
227
227
|
undecidable: !1
|
|
228
228
|
};
|
|
229
|
-
},
|
|
229
|
+
}, Qe = (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
|
+
}), L = (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
|
+
}, $e = (e, t, n, r) => {
|
|
238
|
+
let i = `WHERE ${Ke(t, n)}`, a = Ge(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
|
+
}, et = async (e, t, n, r, i) => (await k.runPromise(e.unsafe($e(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
|
+
}), tt = 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
|
+
}, nt = 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 tt(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 tt(e, `SELECT COUNT(*) AS n FROM ${n}\n WHERE ${Ke(r(a.column), t)}`), c = [];
|
|
264
|
+
if (s > 0) for (let i of I) try {
|
|
265
|
+
let o = await tt(e, `SELECT COUNT(*) AS n FROM ${n}\n WHERE ${Ke(r(a.column), t, [i])}`);
|
|
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 = Qe((await et(e, n, r(a.column), t, 500)).map((e) => Ze(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
|
+
}, rt = (e, t) => {
|
|
295
|
+
let n = I.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,34 +306,34 @@ 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 = L(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 \`${qe.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 + (L(t) ? 0 : t.hits ?? 0), 0), o = e.reduce((e, t) => e + (L(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
|
+
}, it = (e) => e.some((e) => (e.hits ?? 0) > 0 && !L(e)) ? 1 : e.every((e) => e.unavailable !== void 0 || e.scanned === void 0 || e.scanned === 0) ? 2 : 0, at = /\.migration\.ts$/, ot = async (e, t) => {
|
|
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;
|
|
325
325
|
}
|
|
326
|
-
let i = (e.default &&
|
|
326
|
+
let i = (e.default && we(e.default) ? e.default : void 0) ?? Object.values(e).find(we);
|
|
327
327
|
if (!i) {
|
|
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 = Pe("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
|
+
}, st = 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(Ce, r, void 0, i === void 0 ? {} : { retryFilter: i }).pipe(k.provide(e)));
|
|
347
|
+
}, ct = (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))), R = (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))), lt = 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 st(t);
|
|
373
|
+
let r = await ct(t), i = [], a = [], o = null;
|
|
374
374
|
for (let s of e) {
|
|
375
375
|
let e = r.get(s.definition.id);
|
|
376
376
|
if (e && e.status === "applied") {
|
|
@@ -391,7 +391,7 @@ var Ne = (e) => typeof e != "string", Pe = (e, t, n, r) => {
|
|
|
391
391
|
name: s.definition.name
|
|
392
392
|
});
|
|
393
393
|
let c = Date.now(), l = [];
|
|
394
|
-
await
|
|
394
|
+
await R(t, {
|
|
395
395
|
id: s.definition.id,
|
|
396
396
|
name: s.definition.name,
|
|
397
397
|
hash: s.hash,
|
|
@@ -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
|
|
@@ -432,7 +432,7 @@ var Ne = (e) => typeof e != "string", Pe = (e, t, n, r) => {
|
|
|
432
432
|
...a.stack ? { stack: a.stack } : {}
|
|
433
433
|
}
|
|
434
434
|
};
|
|
435
|
-
o = f, i.push(f), await
|
|
435
|
+
o = f, i.push(f), await R(t, {
|
|
436
436
|
id: s.definition.id,
|
|
437
437
|
name: s.definition.name,
|
|
438
438
|
hash: s.hash,
|
|
@@ -451,7 +451,7 @@ var Ne = (e) => typeof e != "string", Pe = (e, t, n, r) => {
|
|
|
451
451
|
status: "applied",
|
|
452
452
|
durationMs: Date.now() - c,
|
|
453
453
|
steps: l
|
|
454
|
-
}), await
|
|
454
|
+
}), await R(t, {
|
|
455
455
|
id: s.definition.id,
|
|
456
456
|
name: s.definition.name,
|
|
457
457
|
hash: s.hash,
|
|
@@ -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
|
+
}, ut = async (e, t, n, r = {}) => {
|
|
475
|
+
await st(t);
|
|
476
|
+
let i = await ct(t), a = e.filter((e) => i.get(e.definition.id)?.status === "applied");
|
|
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
|
|
@@ -526,7 +526,7 @@ var Ne = (e) => typeof e != "string", Pe = (e, t, n, r) => {
|
|
|
526
526
|
status: "applied",
|
|
527
527
|
durationMs: Date.now() - r,
|
|
528
528
|
steps: i
|
|
529
|
-
}), await
|
|
529
|
+
}), await R(t, {
|
|
530
530
|
id: e.definition.id,
|
|
531
531
|
name: e.definition.name,
|
|
532
532
|
hash: e.hash,
|
|
@@ -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
|
+
}, dt = async (e, t) => {
|
|
546
|
+
await st(t);
|
|
547
|
+
let n = await ct(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
|
+
}, ft = (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
|
+
}, pt = (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
|
+
}, mt = (e) => 49 + 4 * Math.ceil(e / 3), ht = (e, t) => {
|
|
585
|
+
let n = mt(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
|
+
}, gt = (e, t) => `${e.table}.${e.column} is too narrow: its longest value encodes to ${t.longestPlaintextBytes} byte(s), which encrypts to ${t.longestCiphertext} characters, and the column is declared as ${t.declaredMaxLength}. Widen it first (\`.maxLength(${t.longestCiphertext})\` or more, then \`voltro db apply\`) and run this again. Nothing was written.`, _t = (e, t) => {
|
|
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
|
+
}, vt = (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 === "" || F(r)) return;
|
|
606
|
+
let i = Se(t, r), a;
|
|
606
607
|
try {
|
|
607
|
-
a = t
|
|
608
|
+
a = xe(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
|
+
}, yt = (e) => Buffer.byteLength(e, "utf8"), bt = (e) => yt(JSON.stringify(typeof e == "string" ? e : String(e))), xt = (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
|
+
}, St = (e, t) => `${e.table}.${e.column} already holds values encrypted with a DIFFERENT key than ${t} — the active key cannot decrypt them. Continuing would encrypt the remaining rows under a second key, and the column would then be readable with neither key alone. Nothing was written. Point ${t} at the key the existing rows were written with.`, Ct = (e) => [
|
|
620
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"), wt = (e, t, n) => {
|
|
631
|
+
if (typeof e != "string" || !F(e)) return;
|
|
632
|
+
let r;
|
|
633
|
+
try {
|
|
634
|
+
r = Te(t, e);
|
|
635
|
+
} catch {
|
|
636
|
+
return;
|
|
637
|
+
}
|
|
638
|
+
if (r !== !0) return;
|
|
639
|
+
let i = xe(t, e);
|
|
640
|
+
if (typeof i != "string") return;
|
|
641
|
+
let a = Se(t, i);
|
|
642
|
+
if (xe(t, a) !== i) throw Error(`${n.table}.${n.column}: re-encoding did not round-trip. Nothing was written.`);
|
|
643
|
+
return a;
|
|
644
|
+
}, Tt = (e, t, n) => e === "sqlite" ? `SELECT NULL AS n FROM pragma_table_info('${t.table}') WHERE name = '${t.column}'` : `SELECT character_maximum_length AS n FROM information_schema.columns\n WHERE ${n} AND table_name = '${t.table}' AND column_name = '${t.column}'`, Et = (e) => {
|
|
645
|
+
if (e == null) return;
|
|
646
|
+
let t = Number(e);
|
|
647
|
+
return Number.isFinite(t) && t >= 0 ? t : void 0;
|
|
648
|
+
}, z = O({ scope: "voltro:db" }), Dt = /* @__PURE__ */ new Set([
|
|
630
649
|
"node_modules",
|
|
631
650
|
"dist",
|
|
632
651
|
"build",
|
|
@@ -634,17 +653,17 @@ var Ne = (e) => typeof e != "string", Pe = (e, t, n, r) => {
|
|
|
634
653
|
".vite",
|
|
635
654
|
".next",
|
|
636
655
|
".git"
|
|
637
|
-
]),
|
|
656
|
+
]), B = 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 (Dt.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
|
+
}, Ot = [
|
|
648
667
|
"--against",
|
|
649
668
|
"--batch",
|
|
650
669
|
"--before",
|
|
@@ -663,63 +682,63 @@ var Ne = (e) => typeof e != "string", Pe = (e, t, n, r) => {
|
|
|
663
682
|
"--store",
|
|
664
683
|
"--to",
|
|
665
684
|
"--token"
|
|
666
|
-
],
|
|
685
|
+
], V = (e) => T(c(e, Ot) ?? process.cwd()), H = () => u("migration"), kt = (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
|
+
}, At = "Live-DB introspection got a corrupt / misaligned response from the database. This happens when `voltro db plan` / `apply` / `drift` / `migrate` runs through a connection POOLER (Supabase Supavisor / PgBouncer) on a LARGE schema — the pooler mis-frames a big catalog response. The introspection already batches by table to keep responses small; if a batch still trips it:\n 1. Lower the batch: set `VOLTRO_INTROSPECT_BATCH` to a smaller number of tables (default 20 — try 5 or 1). This keeps `db plan` on the normal pooler, no direct connection needed.\n 2. Or use a DIRECT (non-pooler) connection: set `DB_DIRECT_URL` (or `DB_MIGRATE_URL`) to the direct database URL — the runtime keeps `DB_URL`, so only the migration path is affected. (Supabase: direct = `db.<project-ref>.supabase.co` [IPv6-only on newer projects]; pooler = `aws-0-<region>.pooler.supabase.com`.)", U = () => {
|
|
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
|
-
},
|
|
677
|
-
let t =
|
|
678
|
-
if (r.length === 0) return
|
|
695
|
+
}, W = (e) => Oe(e, U()), G = (e) => e === "mysql" || e === "mariadb" ? "table_schema = DATABASE()" : e === "mssql" ? "table_schema = SCHEMA_NAME()" : "table_schema = 'public'", K = async () => (await l(U())).makeSqlLayer(H()), jt = async (e) => {
|
|
696
|
+
let t = V(e), n = e.includes("--dry-run"), r = await ot(await B(t, at), z);
|
|
697
|
+
if (r.length === 0) return z.info("no migrations found", { root: t }), 0;
|
|
679
698
|
if (n) {
|
|
680
699
|
let e = /* @__PURE__ */ new Set();
|
|
681
700
|
try {
|
|
682
|
-
let t = await
|
|
701
|
+
let t = await dt(r, await K());
|
|
683
702
|
e = new Set(t.filter((e) => e.status === "applied").map((e) => e.id));
|
|
684
703
|
} catch {
|
|
685
|
-
|
|
704
|
+
z.warn("migrate --dry-run: could not read the migration ledger — showing ALL as pending");
|
|
686
705
|
}
|
|
687
706
|
let t = r.filter((t) => !e.has(t.definition.id));
|
|
688
|
-
if (t.length === 0) return
|
|
689
|
-
|
|
707
|
+
if (t.length === 0) return z.info("migrate --dry-run: nothing pending — every migration is applied"), 0;
|
|
708
|
+
z.info(`migrate --dry-run: ${t.length} pending (nothing applied)`);
|
|
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 lt(r, await K(), z);
|
|
713
|
+
return i.failed ? (process.stderr.write(ft(i) + "\n"), 1) : (z.info("migrate complete", {
|
|
695
714
|
applied: i.applied.length,
|
|
696
715
|
skipped: i.skipped.length
|
|
697
716
|
}), 0);
|
|
698
|
-
},
|
|
699
|
-
let t =
|
|
700
|
-
if (r.length === 0) return
|
|
701
|
-
let i = await
|
|
702
|
-
return i.failed ? (process.stderr.write(
|
|
703
|
-
},
|
|
704
|
-
let t = await
|
|
717
|
+
}, Mt = async (e) => {
|
|
718
|
+
let t = V(e), n = s(e, "--to"), r = await ot(await B(t, at), z);
|
|
719
|
+
if (r.length === 0) return z.info("no migrations found", { root: t }), 0;
|
|
720
|
+
let i = await ut(r, await K(), z, n ? { to: n } : {});
|
|
721
|
+
return i.failed ? (process.stderr.write(ft(i) + "\n"), 1) : (z.info("rollback complete", { reverted: i.applied.length }), 0);
|
|
722
|
+
}, Nt = async (e) => {
|
|
723
|
+
let t = await ot(await B(V(e), at), z);
|
|
705
724
|
if (t.length === 0) return console.log("no migrations found"), 0;
|
|
706
|
-
let n = await
|
|
725
|
+
let n = await dt(t, await K());
|
|
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
|
+
}, Pt = async (e) => {
|
|
713
732
|
let t = (s(e, "--store") ?? process.env.DB_DIALECT ?? "postgres").toLowerCase();
|
|
714
|
-
if (t === "memory") return
|
|
715
|
-
store: new
|
|
733
|
+
if (t === "memory") return z.warn("voltro db seed: using in-memory store (explicit opt-in via --store memory / DB_DIALECT=memory)"), z.warn(" rows written by this run will NOT persist beyond the process. set DB_DIALECT=postgres or unset to seed the real DB."), {
|
|
734
|
+
store: new Me(),
|
|
716
735
|
dispose: async () => {},
|
|
717
736
|
dialectId: "memory"
|
|
718
737
|
};
|
|
719
738
|
let n = await l(t);
|
|
720
|
-
|
|
739
|
+
z.info(`voltro db seed: target store=${n.id} — rows will persist`);
|
|
721
740
|
let r = await n.makeStore({
|
|
722
|
-
sqlLayer: n.makeSqlLayer(
|
|
741
|
+
sqlLayer: n.makeSqlLayer(H()),
|
|
723
742
|
changeStrategy: "inline"
|
|
724
743
|
}), i = r;
|
|
725
744
|
return {
|
|
@@ -729,12 +748,12 @@ var Ne = (e) => typeof e != "string", Pe = (e, t, n, r) => {
|
|
|
729
748
|
},
|
|
730
749
|
dialectId: n.id
|
|
731
750
|
};
|
|
732
|
-
},
|
|
733
|
-
let t =
|
|
734
|
-
if (a.length === 0) return
|
|
735
|
-
let { store: o, dispose: c, dialectId: l } = await
|
|
751
|
+
}, Ft = async (e) => {
|
|
752
|
+
let t = V(e), n = s(e, "--id"), r = s(e, "--lifecycle"), i = await B(t, b), a = await f(i, z);
|
|
753
|
+
if (a.length === 0) return z.info("no seeds found", { root: t }), 0;
|
|
754
|
+
let { store: o, dispose: c, dialectId: l } = await Pt(e);
|
|
736
755
|
try {
|
|
737
|
-
if (n) return +((await d(a, n, o,
|
|
756
|
+
if (n) return +((await d(a, n, o, z)).status === "failed");
|
|
738
757
|
let e = r ? a.filter((e) => e.definition.lifecycle === r) : a.filter((e) => e.definition.lifecycle === "boot");
|
|
739
758
|
return +((await p(e.map((e) => ({
|
|
740
759
|
...e,
|
|
@@ -742,66 +761,66 @@ var Ne = (e) => typeof e != "string", Pe = (e, t, n, r) => {
|
|
|
742
761
|
...e.definition,
|
|
743
762
|
lifecycle: "boot"
|
|
744
763
|
}
|
|
745
|
-
})), o,
|
|
764
|
+
})), o, z, { force: !0 })).filter((e) => e.status === "failed").length > 0);
|
|
746
765
|
} finally {
|
|
747
766
|
await c().catch((e) => {
|
|
748
|
-
|
|
767
|
+
z.warn("voltro db seed: store dispose failed", { error: String(e) });
|
|
749
768
|
});
|
|
750
769
|
}
|
|
751
|
-
},
|
|
752
|
-
let t = await
|
|
770
|
+
}, It = (e) => typeof e == "object" && !!e && "tableName" in e && "fields" in e && typeof e.tableName == "string", Lt = async (e) => {
|
|
771
|
+
let t = await B(e, y), n = [];
|
|
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
|
-
|
|
759
|
-
file:
|
|
777
|
+
z.warn("db: failed to import schema 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)) It(e) && n.push(e);
|
|
765
784
|
}
|
|
766
785
|
return n;
|
|
767
|
-
},
|
|
786
|
+
}, Rt = (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", ye);
|
|
770
789
|
let n = t.get("actors"), r = t.get("tenants");
|
|
771
|
-
return
|
|
790
|
+
return ke({
|
|
772
791
|
actors: () => n,
|
|
773
792
|
...r === void 0 ? {} : { tenants: () => r }
|
|
774
793
|
}), [...t.values()];
|
|
775
|
-
},
|
|
794
|
+
}, zt = (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
|
+
}, Bt = (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 = ve(e, t);
|
|
789
808
|
return {
|
|
790
809
|
plan: n,
|
|
791
810
|
acknowledged: !n.operations.some((e) => e.blocked)
|
|
792
811
|
};
|
|
793
|
-
},
|
|
812
|
+
}, q = async (e, t) => k.runPromise(t.pipe(k.provide(e))), J = async (e) => {
|
|
794
813
|
try {
|
|
795
|
-
return await
|
|
814
|
+
return await q(e, A.SqlClient.pipe(k.flatMap(ue)));
|
|
796
815
|
} catch (e) {
|
|
797
816
|
let t = String(e?.message ?? e);
|
|
798
|
-
if (
|
|
799
|
-
let n = /* @__PURE__ */ Error(`${
|
|
817
|
+
if (kt(e) || /connection error/i.test(t)) {
|
|
818
|
+
let n = /* @__PURE__ */ Error(`${At}\n\nOriginal error: ${t}`);
|
|
800
819
|
throw n.cause = e, n;
|
|
801
820
|
}
|
|
802
821
|
throw e;
|
|
803
822
|
}
|
|
804
|
-
},
|
|
823
|
+
}, Vt = {
|
|
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
|
+
}, Ht = (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 = Vt[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
|
+
}, Ut = 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
|
|
904
|
+
let e = await q(t, A.SqlClient.pipe(k.flatMap((e) => e.unsafe(`SELECT COUNT(*) AS n FROM ${Oe(i, U())}`))));
|
|
886
905
|
o = Number(Object.values(e[0] ?? { n: 0 })[0] ?? 0);
|
|
887
906
|
} catch {
|
|
888
907
|
continue;
|
|
@@ -894,86 +913,86 @@ 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
|
-
},
|
|
898
|
-
if (
|
|
899
|
-
let n =
|
|
916
|
+
}, Wt = async (e, t) => {
|
|
917
|
+
if (U() !== "postgres") return;
|
|
918
|
+
let n = j, r;
|
|
900
919
|
try {
|
|
901
|
-
r = await
|
|
920
|
+
r = await q(t, A.SqlClient.pipe(k.flatMap((t) => m(t, e, n))));
|
|
902
921
|
} catch {
|
|
903
922
|
return;
|
|
904
923
|
}
|
|
905
924
|
let { drift: i, statements: a } = r;
|
|
906
925
|
if (a.length === 0) return;
|
|
907
|
-
|
|
926
|
+
z.info(i.missing.length + i.stale.length > 0 ? `db apply: installing change triggers on ${i.missing.length} table(s)` + (i.stale.length > 0 ? `, removing ${i.stale.length} stale one(s)` : "") + (i.functionOutdated ? ", replacing an outdated notify function" : "") : "db apply: replacing an outdated change-notify function (no table drift)");
|
|
908
927
|
let o = 0;
|
|
909
|
-
for (let e of a) await
|
|
910
|
-
|
|
928
|
+
for (let e of a) await q(t, A.SqlClient.pipe(k.flatMap((t) => t.unsafe(e)))), o += 1;
|
|
929
|
+
z.info(`db apply: change triggers converged (${o} statement(s))`, {
|
|
911
930
|
installed: i.missing.length,
|
|
912
931
|
removed: i.stale.length,
|
|
913
932
|
functionReplaced: i.functionOutdated
|
|
914
933
|
});
|
|
915
|
-
},
|
|
934
|
+
}, Y = (e) => {
|
|
916
935
|
let t = e.summary, n = e.operations.length;
|
|
917
936
|
if (console.log(`\nschema diff: ${n} operation${n === 1 ? "" : "s"}, ${t.blocked} blocked\n`), n === 0) {
|
|
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(Ht(t));
|
|
941
|
+
console.log(), console.log(` safe: ${t.safe} needs-default: ${t.needsDefault} needs-backfill: ${t.needsBackfill}`), console.log(` rename: ${t.needsRenameAnnotation} lossy: ${t.lossy} blocked: ${t.blocked}`), console.log(` fingerprint: ${e.fromFingerprint.slice(0, 16)} → ${e.toFingerprint.slice(0, 16)}\n`), Gt(e);
|
|
942
|
+
}, Gt = (e) => {
|
|
943
|
+
let t = he(e.operations);
|
|
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
|
+
}, Kt = (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: he(e.operations).length
|
|
935
954
|
});
|
|
936
|
-
return n.refuse ? (
|
|
937
|
-
},
|
|
955
|
+
return n.refuse ? (z.error(`db apply: ${n.message}`), !0) : (n.warnForced && z.warn(`db apply: ${n.message}`), !1);
|
|
956
|
+
}, qt = (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
|
-
},
|
|
944
|
-
let t = await
|
|
962
|
+
}, X = async (e) => {
|
|
963
|
+
let t = await Lt(e);
|
|
945
964
|
if (t.length === 0) return;
|
|
946
965
|
let n = await g({ root: e });
|
|
947
|
-
return
|
|
966
|
+
return Rt(zt([
|
|
948
967
|
...t,
|
|
949
|
-
...
|
|
968
|
+
...Ce,
|
|
950
969
|
...n
|
|
951
970
|
]));
|
|
952
|
-
},
|
|
971
|
+
}, Z = async (e, t, n) => {
|
|
953
972
|
let r;
|
|
954
973
|
try {
|
|
955
974
|
let t = await _(e);
|
|
956
|
-
await
|
|
957
|
-
|
|
975
|
+
await q(n, v(t, (e, t) => {
|
|
976
|
+
z.info(`db apply: ${e}`, t ?? {});
|
|
958
977
|
}));
|
|
959
978
|
} catch (e) {
|
|
960
979
|
r = e;
|
|
961
980
|
}
|
|
962
|
-
return await
|
|
963
|
-
},
|
|
964
|
-
let n = { close: async () => {} }, r = await
|
|
981
|
+
return await Wt(t, n), r === void 0 ? 0 : (z.error("db apply: a plugin migration FAILED — the schema was applied, the plugin steps were not", { error: r instanceof Error ? r.message : String(r) }), 1);
|
|
982
|
+
}, Jt = async (e, t) => {
|
|
983
|
+
let n = { close: async () => {} }, r = await B(e, b);
|
|
965
984
|
if (r.length === 0) return n;
|
|
966
|
-
let i = await f(r,
|
|
985
|
+
let i = await f(r, z), a = i.filter((e) => e.definition.lifecycle === "onSchemaChange");
|
|
967
986
|
if (a.length === 0) return n;
|
|
968
|
-
let { store: o, dispose: s } = await
|
|
969
|
-
return
|
|
987
|
+
let { store: o, dispose: s } = await Pt(t), c = h(i, o, z.child("seeds"));
|
|
988
|
+
return z.info(`db apply: ${a.length} onSchemaChange seed(s) armed for this apply`, { ids: a.map((e) => e.definition.id) }), { close: async () => {
|
|
970
989
|
c(), await s().catch((e) => {
|
|
971
|
-
|
|
990
|
+
z.warn("db apply: seed store dispose failed", { error: String(e) });
|
|
972
991
|
});
|
|
973
992
|
} };
|
|
974
|
-
},
|
|
975
|
-
let t =
|
|
976
|
-
if (r === void 0) return
|
|
993
|
+
}, Yt = async (e) => {
|
|
994
|
+
let t = qt(e), n = V(e), r = await X(n);
|
|
995
|
+
if (r === void 0) return z.warn("db plan: no schema files found", {
|
|
977
996
|
root: n,
|
|
978
997
|
hint: "looked for *.entity.ts / *.schema.ts / schema.ts"
|
|
979
998
|
}), 1;
|
|
@@ -983,133 +1002,133 @@ 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
|
|
1005
|
+
if (!i.ok) return z.error(`db plan --against: remote returned ${i.status}`, { url: e }), x(i.status) && console.error(` ${S(i.status)}`), 1;
|
|
987
1006
|
let a = (await i.json()).drift?.liveSnapshot;
|
|
988
|
-
if (!a) return
|
|
989
|
-
let s =
|
|
1007
|
+
if (!a) return z.error("db plan --against: remote inspect payload missing drift.liveSnapshot", { url: e }), 1;
|
|
1008
|
+
let s = N({
|
|
990
1009
|
declared: r,
|
|
991
1010
|
live: a,
|
|
992
|
-
dialect:
|
|
993
|
-
...
|
|
1011
|
+
dialect: U(),
|
|
1012
|
+
...M(),
|
|
994
1013
|
...t === void 0 ? {} : { onlineAfter: t }
|
|
995
1014
|
});
|
|
996
|
-
return console.log(`\n[--against ${e}] — diff vs remote live schema:\n`),
|
|
1015
|
+
return console.log(`\n[--against ${e}] — diff vs remote live schema:\n`), Y(s), s.summary.blocked > 0 ? 2 : 0;
|
|
997
1016
|
} catch (e) {
|
|
998
|
-
return
|
|
1017
|
+
return z.error(`db plan --against: ${e.message}`), 1;
|
|
999
1018
|
}
|
|
1000
1019
|
}
|
|
1001
|
-
let a = await
|
|
1020
|
+
let a = await J(await K()), o = N({
|
|
1002
1021
|
declared: r,
|
|
1003
1022
|
live: a,
|
|
1004
|
-
dialect:
|
|
1005
|
-
...
|
|
1023
|
+
dialect: U(),
|
|
1024
|
+
...M(),
|
|
1006
1025
|
...t === void 0 ? {} : { onlineAfter: t }
|
|
1007
1026
|
});
|
|
1008
|
-
return e.includes("--json") ? (
|
|
1009
|
-
},
|
|
1027
|
+
return e.includes("--json") ? (te(1, `${JSON.stringify(o, null, 2)}\n`), o.summary.blocked > 0 ? 2 : 0) : (Y(o), o.summary.blocked > 0 ? 2 : 0);
|
|
1028
|
+
}, Q = n, Xt = async (e, t, n) => {
|
|
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
|
-
return
|
|
1034
|
+
return z.error(`db apply --plan: cannot read/parse plan file '${e}': ${t.message}`), 1;
|
|
1016
1035
|
}
|
|
1017
|
-
if (!Array.isArray(r?.operations) || typeof r?.fromFingerprint != "string" || typeof r?.toFingerprint != "string") return
|
|
1018
|
-
let i = await
|
|
1019
|
-
if (i === void 0) return
|
|
1020
|
-
let a = await
|
|
1021
|
-
if (o.length > 0) return
|
|
1022
|
-
let c = await
|
|
1036
|
+
if (!Array.isArray(r?.operations) || typeof r?.fromFingerprint != "string" || typeof r?.toFingerprint != "string") return z.error(`db apply --plan: '${e}' is not a valid plan file (expected the output of \`voltro db plan --json\`).`), 1;
|
|
1037
|
+
let i = await X(n);
|
|
1038
|
+
if (i === void 0) return z.warn("db apply --plan: no schema files found", { root: n }), 1;
|
|
1039
|
+
let a = await K(), o = await q(a, A.SqlClient.pipe(k.flatMap((e) => de(e, n)))).catch(() => []);
|
|
1040
|
+
if (o.length > 0) return z.error(`db apply --plan: refusing — ${o.length} pending file-based migration(s).`), console.error(` ${o.join("\n ")}`), console.error(""), console.error(" These perform the changes a state diff cannot infer, so they change the shape"), console.error(" this plan was computed against. Apply them and regenerate the plan:"), console.error(""), console.error(" voltro db files ."), console.error(" voltro db plan --json > plan.json"), console.error(" voltro db apply --plan plan.json"), 1;
|
|
1041
|
+
let c = await J(a), l = N({
|
|
1023
1042
|
declared: i,
|
|
1024
1043
|
live: c,
|
|
1025
|
-
dialect:
|
|
1026
|
-
...
|
|
1044
|
+
dialect: U(),
|
|
1045
|
+
...M()
|
|
1027
1046
|
});
|
|
1028
|
-
if (l.fromFingerprint !== r.fromFingerprint) return
|
|
1029
|
-
if (l.toFingerprint !== r.toFingerprint) return
|
|
1030
|
-
let u =
|
|
1031
|
-
if (d.summary.blocked > 0 && !u.acknowledged) return
|
|
1032
|
-
if (u.acknowledged &&
|
|
1047
|
+
if (l.fromFingerprint !== r.fromFingerprint) return z.error("db apply --plan: refusing — the live schema has drifted since this plan was generated."), console.error(` plan.from=${r.fromFingerprint.slice(0, 16)} live=${l.fromFingerprint.slice(0, 16)}`), console.error(" Regenerate against the current live schema: `voltro db plan --json > plan.json`"), 2;
|
|
1048
|
+
if (l.toFingerprint !== r.toFingerprint) return z.error("db apply --plan: refusing — the declared schema differs from what this plan targets."), console.error(` plan.to=${r.toFingerprint.slice(0, 16)} declared=${l.toFingerprint.slice(0, 16)}`), console.error(" The schema files changed since the plan was generated. Regenerate the plan."), 2;
|
|
1049
|
+
let u = Bt(l), d = u.plan;
|
|
1050
|
+
if (d.summary.blocked > 0 && !u.acknowledged) return Y(d), z.error(`db apply --plan: refusing — ${l.summary.blocked} blocked operation(s). See the fix hints above.`), process.env.VOLTRO_DESTRUCTIVE_OK !== void 0 && (z.error(" VOLTRO_DESTRUCTIVE_OK is set but did not cover this plan — it only relaxes"), z.error(" `lossy` operations, and only the tables it names. Anything else stays refused.")), 2;
|
|
1051
|
+
if (u.acknowledged && z.warn("db apply --plan: proceeding with acknowledged lossy operation(s) (VOLTRO_DESTRUCTIVE_OK)"), Kt(d, t)) return 2;
|
|
1033
1052
|
if (d.operations.length === 0) {
|
|
1034
|
-
let e = await
|
|
1053
|
+
let e = await q(a, A.SqlClient.pipe(k.flatMap((e) => fe(e, d, {
|
|
1035
1054
|
appliedBy: process.env.USER ? `cli:${process.env.USER}` : "cli:plan",
|
|
1036
|
-
environment:
|
|
1055
|
+
environment: Q(),
|
|
1037
1056
|
source: "file"
|
|
1038
1057
|
}))));
|
|
1039
|
-
return
|
|
1058
|
+
return z.info(e === "recorded" ? `db apply --plan: schema is up to date — no DDL to apply, recorded fingerprint=${d.toFingerprint.slice(0, 16)} (change triggers are reconciled separately below)` : "db apply --plan: schema is up to date — no DDL to apply (change triggers are reconciled separately below)"), Z(n, i, a);
|
|
1040
1059
|
}
|
|
1041
|
-
|
|
1042
|
-
let f = s(t, "--note"), p = await
|
|
1060
|
+
Y(d);
|
|
1061
|
+
let f = s(t, "--note"), p = await q(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
|
-
environment:
|
|
1064
|
+
environment: Q(),
|
|
1046
1065
|
source: "file",
|
|
1047
1066
|
...f ? { notes: f } : {},
|
|
1048
|
-
replan: () =>
|
|
1067
|
+
replan: () => k.promise(() => J(a)).pipe(k.map((e) => N({
|
|
1049
1068
|
declared: i,
|
|
1050
1069
|
live: e,
|
|
1051
|
-
dialect:
|
|
1052
|
-
...
|
|
1070
|
+
dialect: U(),
|
|
1071
|
+
...M()
|
|
1053
1072
|
})))
|
|
1054
1073
|
}))));
|
|
1055
|
-
return
|
|
1074
|
+
return z.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
|
-
}),
|
|
1059
|
-
},
|
|
1060
|
-
let t =
|
|
1077
|
+
}), Z(n, i, a);
|
|
1078
|
+
}, Zt = async (e) => {
|
|
1079
|
+
let t = V(e), n = await Jt(t, e);
|
|
1061
1080
|
try {
|
|
1062
|
-
return await
|
|
1081
|
+
return await Qt(e, t);
|
|
1063
1082
|
} finally {
|
|
1064
1083
|
await n.close();
|
|
1065
1084
|
}
|
|
1066
|
-
},
|
|
1067
|
-
let r =
|
|
1068
|
-
if (i) return
|
|
1069
|
-
if ((process.env.NODE_ENV ?? "").toLowerCase() === "production") return
|
|
1070
|
-
let a = await
|
|
1071
|
-
if (a === void 0) return
|
|
1072
|
-
let o = await
|
|
1073
|
-
if ("failed" in c) return
|
|
1074
|
-
let l = await
|
|
1085
|
+
}, Qt = async (e, n) => {
|
|
1086
|
+
let r = qt(e), i = s(e, "--plan");
|
|
1087
|
+
if (i) return Xt(i, e, n);
|
|
1088
|
+
if ((process.env.NODE_ENV ?? "").toLowerCase() === "production") return z.error(`voltro db apply: refusing — auto-apply on prod is not allowed.${t()}`), console.error("In production, schema changes go through `voltro db plan --json > plan.json`"), console.error("then `voltro db apply --plan plan.json` as an explicit step in your deploy pipeline."), 3;
|
|
1089
|
+
let a = await X(n);
|
|
1090
|
+
if (a === void 0) return z.warn("db apply: no schema files found", { root: n }), 1;
|
|
1091
|
+
let o = await K(), c = await hn(n, o);
|
|
1092
|
+
if ("failed" in c) return z.error("db apply: a file-based migration FAILED — the schema diff was NOT run"), console.error(c.failed), console.error("Fix the migration and re-run. `voltro db files` runs them alone."), 1;
|
|
1093
|
+
let l = await J(o), u = N({
|
|
1075
1094
|
declared: a,
|
|
1076
1095
|
live: l,
|
|
1077
|
-
dialect:
|
|
1078
|
-
...
|
|
1096
|
+
dialect: U(),
|
|
1097
|
+
...M(),
|
|
1079
1098
|
...r === void 0 ? {} : { onlineAfter: r }
|
|
1080
1099
|
});
|
|
1081
|
-
|
|
1082
|
-
let d =
|
|
1083
|
-
if (f.summary.blocked > 0 && !d.acknowledged) return
|
|
1084
|
-
if (d.acknowledged &&
|
|
1100
|
+
Y(u), await Ut(u, o);
|
|
1101
|
+
let d = Bt(u), f = d.plan;
|
|
1102
|
+
if (f.summary.blocked > 0 && !d.acknowledged) return z.error(`db apply: refusing — ${f.summary.blocked} blocked operation(s). See the fix hints above.`), process.env.VOLTRO_DESTRUCTIVE_OK !== void 0 && (z.error(" VOLTRO_DESTRUCTIVE_OK is set but did not cover this plan — it only relaxes"), z.error(" `lossy` operations, and only the tables it names. Anything else stays refused.")), 2;
|
|
1103
|
+
if (d.acknowledged && z.warn(`db apply: proceeding with ${u.summary.blocked} acknowledged lossy operation(s) (VOLTRO_DESTRUCTIVE_OK)`), Kt(f, e)) return 2;
|
|
1085
1104
|
if (f.operations.length === 0) {
|
|
1086
|
-
|
|
1087
|
-
let t = await
|
|
1105
|
+
z.info("db apply: schema is up to date — no DDL to apply (change triggers are reconciled separately below)");
|
|
1106
|
+
let t = await q(o, A.SqlClient.pipe(k.flatMap((e) => fe(e, f, {
|
|
1088
1107
|
appliedBy: process.env.USER ? `cli:${process.env.USER}` : "cli:apply",
|
|
1089
|
-
environment:
|
|
1108
|
+
environment: Q(),
|
|
1090
1109
|
source: "auto-diff"
|
|
1091
1110
|
}))));
|
|
1092
|
-
return t === "recorded" &&
|
|
1111
|
+
return t === "recorded" && z.info(`db apply: recorded fingerprint=${f.toFingerprint.slice(0, 16)} (0 operations)`), await un(o), s(e, "--note") !== void 0 && t !== "recorded" && (z.warn("db apply: --note was ignored — this schema is already the latest recorded one, so there is no new history row to attach it to."), console.error("To record that the CURRENT live schema is the accepted baseline, use `voltro db drift --accept`.")), Z(n, a, o);
|
|
1093
1112
|
}
|
|
1094
|
-
let p = s(e, "--note"), m = await
|
|
1113
|
+
let p = s(e, "--note"), m = await q(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
|
-
environment:
|
|
1116
|
+
environment: Q(),
|
|
1098
1117
|
source: "auto-diff",
|
|
1099
1118
|
...p ? { notes: p } : {},
|
|
1100
|
-
replan: () =>
|
|
1119
|
+
replan: () => k.promise(() => J(o)).pipe(k.map((e) => N({
|
|
1101
1120
|
declared: a,
|
|
1102
1121
|
live: e,
|
|
1103
|
-
dialect:
|
|
1104
|
-
...
|
|
1122
|
+
dialect: U(),
|
|
1123
|
+
...M(),
|
|
1105
1124
|
...r === void 0 ? {} : { onlineAfter: r }
|
|
1106
1125
|
})))
|
|
1107
1126
|
}))));
|
|
1108
|
-
return
|
|
1127
|
+
return z.info(`db apply: applied ${m.appliedOps} op(s) in ${m.durationMs}ms`, {
|
|
1109
1128
|
id: m.id,
|
|
1110
1129
|
fingerprint: m.fingerprint.slice(0, 16)
|
|
1111
|
-
}),
|
|
1112
|
-
},
|
|
1130
|
+
}), Z(n, a, o);
|
|
1131
|
+
}, $t = (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
|
+
}, en = (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
|
+
}, tn = (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
|
+
}, nn = (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
|
+
}, rn = (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 =
|
|
1155
|
-
if (u !== "postgres") return
|
|
1156
|
-
let d = await
|
|
1157
|
-
if (d === void 0) return
|
|
1172
|
+
}, an = async (e) => {
|
|
1173
|
+
let t = V(e), n = nn(s(e, "--seed")), i = rn(s(e, "--prefer")), a = e.includes("--keep"), o = e.includes("--json"), c = qt(e), u = U();
|
|
1174
|
+
if (u !== "postgres") return z.error(`voltro db branch: not supported on '${u}'.`), console.error(" The branch PLAN is dialect-agnostic; the shipped namespace EXECUTOR is Postgres-only"), console.error(" (CREATE SCHEMA / CREATE TABLE … LIKE … INCLUDING ALL / \"-quoted identifiers)."), console.error(" MySQL, MariaDB, SQLite and SQL Server need their own BranchExecutor — see"), console.error(" makeNamespaceBranchExecutor in @voltro/database."), 1;
|
|
1175
|
+
let d = await X(t);
|
|
1176
|
+
if (d === void 0) return z.warn("db branch: no schema files found", {
|
|
1158
1177
|
root: t,
|
|
1159
1178
|
hint: "looked for *.entity.ts / *.schema.ts / schema.ts"
|
|
1160
1179
|
}), 1;
|
|
1161
|
-
let f =
|
|
1180
|
+
let f = H(), p = Ae({
|
|
1162
1181
|
seed: n,
|
|
1163
1182
|
...f.url === void 0 ? {} : { dbUrl: f.url },
|
|
1164
1183
|
...i === void 0 ? {} : { prefer: i }
|
|
1165
1184
|
});
|
|
1166
|
-
if (p === "neon-cow") return
|
|
1167
|
-
let m = f.schema ?? "public", h = s(e, "--name") ??
|
|
1185
|
+
if (p === "neon-cow") return z.error("voltro db branch: this connection resolves to the Neon copy-on-write mechanism, which the CLI cannot execute."), console.error(" A Neon CoW branch is a single call to Neon's branch REST API and needs a Neon API token;"), console.error(" the framework ships the PLAN, and the cloud control plane executes it."), console.error(" Re-run with `--prefer namespace` to rehearse on a schema-per-branch copy instead"), console.error(` (portable, no vendor API — it copies ${n === "copy" ? "every row" : "the schema only"}).`), 1;
|
|
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 = be(h, _), y = await l(u), b = y.makeSqlLayer(f), x = y.makeSqlLayer({
|
|
1170
1189
|
...f,
|
|
1171
1190
|
schema: v
|
|
1172
|
-
}),
|
|
1191
|
+
}), S = await J(b), C = N({
|
|
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 = $t(S), E = en(S), D = Ee({ run: (e) => q(b, A.SqlClient.pipe(k.flatMap((t) => t.unsafe(e)), k.asVoid)) }), O = async () => N({
|
|
1179
1198
|
declared: d,
|
|
1180
|
-
live: await
|
|
1199
|
+
live: await J(x),
|
|
1181
1200
|
dialect: u,
|
|
1182
|
-
...
|
|
1201
|
+
...M(),
|
|
1183
1202
|
...c === void 0 ? {} : { onlineAfter: c }
|
|
1184
|
-
}),
|
|
1203
|
+
}), j = await pe({
|
|
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
|
-
o ||
|
|
1210
|
+
o || z.info(`db branch: ${e}`);
|
|
1192
1211
|
},
|
|
1193
1212
|
provision: async () => {
|
|
1194
|
-
await
|
|
1213
|
+
await De({
|
|
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 () => tn(C, await O()),
|
|
1226
|
+
plan: O,
|
|
1208
1227
|
apply: async (e) => {
|
|
1209
|
-
await
|
|
1228
|
+
await q(x, A.SqlClient.pipe(k.flatMap((t) => ne(t, e, {
|
|
1210
1229
|
declared: d,
|
|
1211
1230
|
appliedBy: "cli:db-branch",
|
|
1212
|
-
environment:
|
|
1231
|
+
environment: Q(),
|
|
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 je(v, "namespace", D);
|
|
1221
1240
|
}
|
|
1222
1241
|
});
|
|
1223
|
-
return o ?
|
|
1224
|
-
},
|
|
1225
|
-
let t = Math.max(1, Number(s(e, "--limit") ?? "20")), n = await
|
|
1242
|
+
return o ? te(1, `${JSON.stringify(j, null, 2)}\n`) : console.log(`\n${le(j)}\n`), ae(j);
|
|
1243
|
+
}, on = async (e) => {
|
|
1244
|
+
let t = Math.max(1, Number(s(e, "--limit") ?? "20")), n = await q(await K(), A.SqlClient.pipe(k.flatMap((e) => e`
|
|
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")}
|
|
@@ -1230,25 +1249,25 @@ var Ne = (e) => typeof e != "string", Pe = (e, t, n, r) => {
|
|
|
1230
1249
|
ORDER BY ${e("appliedAt")} DESC
|
|
1231
1250
|
LIMIT ${t}
|
|
1232
1251
|
`)));
|
|
1233
|
-
if (n.length === 0) return
|
|
1252
|
+
if (n.length === 0) return z.info("db plans: no planner-based migrations applied yet"), console.log("Run `voltro db apply` after a schema change to start a plan history."), 0;
|
|
1234
1253
|
console.log(`\n${n.length} plan${n.length === 1 ? "" : "s"} (newest first):\n`);
|
|
1235
1254
|
for (let e of n) {
|
|
1236
1255
|
let t = 0;
|
|
1237
1256
|
try {
|
|
1238
|
-
t = JSON.parse(
|
|
1257
|
+
t = JSON.parse(dn(e.operations)).length;
|
|
1239
1258
|
} catch {}
|
|
1240
|
-
console.log(` ${e.id} fp=${
|
|
1259
|
+
console.log(` ${e.id} fp=${P(e.fingerprint)} env=${e.environment} src=${e.source} ${t} op(s) ${e.durationMs}ms ${fn(e.appliedAt)} by=${e.appliedBy}`), e.notes && console.log(` [2mnote: ${e.notes}[0m`);
|
|
1241
1260
|
}
|
|
1242
1261
|
return console.log(), 0;
|
|
1243
|
-
},
|
|
1262
|
+
}, sn = 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
|
|
1265
|
+
let n = await K(), r = await q(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(dn(r[0].operations));
|
|
1252
1271
|
} catch {
|
|
1253
1272
|
return console.error(`restore-snapshot: plan '${t}' has corrupted operations JSON`), 1;
|
|
1254
1273
|
}
|
|
@@ -1262,9 +1281,9 @@ 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
|
|
1284
|
+
let t = await q(n, A.SqlClient.pipe(k.flatMap((t) => t`
|
|
1266
1285
|
SELECT column_name FROM information_schema.columns
|
|
1267
|
-
WHERE ${t.unsafe(
|
|
1286
|
+
WHERE ${t.unsafe(G(U()))}
|
|
1268
1287
|
AND table_name = ${e.table}
|
|
1269
1288
|
AND column_name LIKE ${e.column + "__dropped_%"}
|
|
1270
1289
|
ORDER BY column_name DESC LIMIT 1
|
|
@@ -1274,13 +1293,13 @@ 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
|
|
1296
|
+
await q(n, A.SqlClient.pipe(k.flatMap((t) => t.unsafe(`ALTER TABLE ${W(e.table)} RENAME COLUMN ${W(r)} TO ${W(e.column)}`)))), s++, console.log(` ↩ restored ${e.table}.${e.column} (from ${r})`);
|
|
1278
1297
|
}
|
|
1279
1298
|
let c = 0;
|
|
1280
1299
|
for (let e of o) {
|
|
1281
|
-
let t = await
|
|
1300
|
+
let t = await q(n, A.SqlClient.pipe(k.flatMap((t) => t`
|
|
1282
1301
|
SELECT table_name FROM information_schema.tables
|
|
1283
|
-
WHERE ${t.unsafe(
|
|
1302
|
+
WHERE ${t.unsafe(G(U()))}
|
|
1284
1303
|
AND table_name LIKE ${e.table + "__dropped_%"}
|
|
1285
1304
|
ORDER BY table_name DESC LIMIT 1
|
|
1286
1305
|
`)));
|
|
@@ -1289,57 +1308,57 @@ 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
|
|
1311
|
+
await q(n, A.SqlClient.pipe(k.flatMap((t) => t.unsafe(`ALTER TABLE ${W(r)} RENAME TO ${W(e.table)}`)))), c++, console.log(` ↩ restored table ${e.table} (from ${r})`);
|
|
1293
1312
|
}
|
|
1294
1313
|
return console.log(`\n✓ restored ${s} column(s) + ${c} table(s) from plan '${t}'\n`), 0;
|
|
1295
|
-
},
|
|
1314
|
+
}, cn = 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
|
|
1319
|
+
let r = (n + "00000000000000").slice(0, 14), i = e.includes("--dry-run"), a = await K(), o = await q(a, A.SqlClient.pipe(k.flatMap((e) => e`
|
|
1301
1320
|
SELECT table_name, column_name FROM information_schema.columns
|
|
1302
|
-
WHERE ${e.unsafe(
|
|
1303
|
-
`))), c = await
|
|
1321
|
+
WHERE ${e.unsafe(G(U()))} AND column_name LIKE ${"%__dropped_%"}
|
|
1322
|
+
`))), c = await q(a, A.SqlClient.pipe(k.flatMap((e) => e`
|
|
1304
1323
|
SELECT table_name FROM information_schema.tables
|
|
1305
|
-
WHERE ${e.unsafe(
|
|
1324
|
+
WHERE ${e.unsafe(G(U()))} AND table_name LIKE ${"%__dropped_%"}
|
|
1306
1325
|
`))), l = (e) => {
|
|
1307
1326
|
let t = /__dropped_(\d{14})$/.exec(e);
|
|
1308
1327
|
return t ? t[1] : null;
|
|
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
|
|
1331
|
+
t === null || t >= r || (console.log(` ${i ? "[dry-run] would drop column" : "dropping column"} ${e.table_name}.${e.column_name}`), i || await q(a, A.SqlClient.pipe(k.flatMap((t) => t.unsafe(`ALTER TABLE ${W(e.table_name)} DROP COLUMN ${W(e.column_name)}`)))), u++);
|
|
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
|
|
1335
|
+
t === null || t >= r || (console.log(` ${i ? "[dry-run] would drop table" : "dropping table"} ${e.table_name}`), i || await q(a, A.SqlClient.pipe(k.flatMap((t) => t.unsafe(`DROP TABLE ${W(e.table_name)}`)))), u++);
|
|
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
|
+
}, ln = 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
|
-
let r = s(e, "--note"), i =
|
|
1325
|
-
if (a === void 0) return
|
|
1326
|
-
let o =
|
|
1343
|
+
let r = s(e, "--note"), i = V(e), a = await X(i);
|
|
1344
|
+
if (a === void 0) return z.warn("db squash: no schema files found", { root: i }), 1;
|
|
1345
|
+
let o = ce(oe(a)), c = await K();
|
|
1327
1346
|
try {
|
|
1328
|
-
let e = await
|
|
1347
|
+
let e = await q(c, _e({
|
|
1329
1348
|
before: n,
|
|
1330
1349
|
fingerprint: o,
|
|
1331
1350
|
appliedBy: process.env.USER ?? "cli",
|
|
1332
|
-
environment:
|
|
1351
|
+
environment: Q(),
|
|
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: ${P(e.snapshotFingerprint)}\n`), 0;
|
|
1336
1355
|
} catch (e) {
|
|
1337
1356
|
return console.error(`squash refused: ${e.message}`), 1;
|
|
1338
1357
|
}
|
|
1339
|
-
},
|
|
1358
|
+
}, un = async (e) => {
|
|
1340
1359
|
try {
|
|
1341
|
-
let t = await
|
|
1342
|
-
await
|
|
1360
|
+
let t = await J(e), n = ce(t);
|
|
1361
|
+
await q(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
|
+
}, dn = (e) => typeof e == "string" ? e : e == null ? "" : JSON.stringify(e), fn = (e) => e instanceof Date ? e.toISOString() : String(e ?? ""), pn = (e) => e === void 0 ? {
|
|
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
|
|
1382
|
+
}, mn = async (e) => {
|
|
1383
|
+
let t = e.includes("--accept"), n = await K(), r = await q(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
|
|
1369
|
-
if (r.length === 0) return
|
|
1387
|
+
`))), i = await J(n), a = ce(i);
|
|
1388
|
+
if (r.length === 0) return z.info("db drift: no _voltro_migration_plans rows yet"), console.log(`live user-schema fingerprint: ${P(a)}`), console.log("No baseline to compare against. Run `voltro db apply` to lock in the current state."), 0;
|
|
1370
1389
|
let o = r[0];
|
|
1371
|
-
if (o.liveFingerprint === null || o.liveFingerprint === void 0) return
|
|
1372
|
-
if (o.liveFingerprint === a) return
|
|
1390
|
+
if (o.liveFingerprint === null || o.liveFingerprint === void 0) return z.warn("db drift: no drift baseline recorded yet — cannot compare"), console.log(), console.log(` last applied: ${o.id} at ${fn(o.appliedAt)}`), console.log(` live now: ${P(a)}`), console.log(), console.log("That row was written before the framework recorded a live-schema baseline,"), console.log("and the value it does carry is the DECLARED snapshot's hash — not comparable"), console.log("with a live one. Run `voltro db apply` once to establish the baseline (a no-op"), console.log("apply backfills it too); use `voltro db plan` meanwhile, which compares declared"), console.log("against live directly."), console.log(), console.log("Exit code 3 — NOT 0. \"Did not compare\" is not \"clean\", and a gate on the exit"), console.log("code has to be able to tell them apart."), 3;
|
|
1391
|
+
if (o.liveFingerprint === a) return z.info(`db drift: live matches last applied (${P(a)})`), 0;
|
|
1373
1392
|
let s = await (async () => {
|
|
1374
1393
|
try {
|
|
1375
|
-
let t = await
|
|
1376
|
-
return t === void 0 ? void 0 :
|
|
1394
|
+
let t = await X(V(e));
|
|
1395
|
+
return t === void 0 ? void 0 : N({
|
|
1377
1396
|
declared: t,
|
|
1378
1397
|
live: i,
|
|
1379
|
-
dialect:
|
|
1380
|
-
...
|
|
1398
|
+
dialect: U(),
|
|
1399
|
+
...M()
|
|
1381
1400
|
}).operations;
|
|
1382
1401
|
} catch {
|
|
1383
1402
|
return;
|
|
1384
1403
|
}
|
|
1385
1404
|
})();
|
|
1386
1405
|
if (t) {
|
|
1387
|
-
let e =
|
|
1388
|
-
if (e.reason === "no-declared-schema") return
|
|
1406
|
+
let e = pn(s?.length);
|
|
1407
|
+
if (e.reason === "no-declared-schema") return z.error("db drift --accept: no schema files found — cannot verify the live schema is current."), 1;
|
|
1389
1408
|
if (!e.accept && s !== void 0) {
|
|
1390
|
-
|
|
1409
|
+
z.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
|
|
1413
|
+
return await q(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,43 +1419,43 @@ 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
|
-
`))),
|
|
1422
|
+
`))), z.info(`db drift: accepted the live schema as the baseline (${P(a)})`), console.log(), console.log("`voltro db plan` reports 0 operations against this schema, so the live state already"), console.log("matches your declaration — only the ledger did not know. It does now."), console.log(), console.log("No history entry was invented: the latest row's baseline was updated in place,"), console.log("because no migration ran."), 0;
|
|
1404
1423
|
}
|
|
1405
|
-
return
|
|
1406
|
-
},
|
|
1407
|
-
let n =
|
|
1424
|
+
return z.error("db drift: live schema DIVERGED from last applied state"), console.log(), console.log(` baseline: ${P(o.liveFingerprint)} at ${fn(o.appliedAt)} (${o.id})`), console.log(` live now: ${P(a)}`), console.log(), console.log("Something changed the live schema after the last apply. This command can see"), console.log("THAT it changed, not what or who — the fingerprints are hashes, not a diff."), console.log(), s === void 0 ? (console.log("No schema files found here, so the declared side could not be compared."), console.log("Run `voltro db plan` from your project root for the actual difference."), 4) : s.length === 0 ? (console.log("Your DECLARED schema is already satisfied — `voltro db plan` reports 0 operations"), console.log("against this database. So the live schema is not wrong, only unrecorded: something"), console.log("applied a change without going through the planner (a hand-run ALTER, a DBA"), console.log("window, a restored dump), or it touched a table your code does not declare."), console.log(), console.log("If that was deliberate and the schema is right, record it:"), console.log(), console.log(" voltro db drift --accept"), console.log(), console.log("It updates the latest ledger row's baseline to the live schema and invents no"), console.log("history entry. Drift then measures from here."), 4) : (console.log(`\`voltro db plan\` reports ${s.length} operation(s) still pending against your`), console.log("declared schema, so this is not merely an unrecorded change — run it for the diff,"), console.log("then `voltro db apply`, which writes a fresh baseline of its own."), 4);
|
|
1425
|
+
}, hn = async (e, t) => {
|
|
1426
|
+
let n = Q();
|
|
1408
1427
|
try {
|
|
1409
|
-
let r = await
|
|
1428
|
+
let r = await q(t, A.SqlClient.pipe(k.flatMap((t) => ge(t, {
|
|
1410
1429
|
projectRoot: e,
|
|
1411
1430
|
env: n,
|
|
1412
1431
|
appliedBy: process.env.USER ? `cli:${process.env.USER}` : "cli:user"
|
|
1413
1432
|
}))));
|
|
1414
|
-
return r.applied.length > 0 &&
|
|
1433
|
+
return r.applied.length > 0 && z.info(`db apply: applied ${r.applied.length} pending file-based migration(s) first`, { applied: r.applied.map((e) => `${e.id} (${e.durationMs}ms)`) }), { applied: r.applied.length };
|
|
1415
1434
|
} catch (e) {
|
|
1416
1435
|
return { failed: e };
|
|
1417
1436
|
}
|
|
1418
|
-
},
|
|
1419
|
-
let t =
|
|
1420
|
-
await
|
|
1421
|
-
let i = await
|
|
1437
|
+
}, gn = async (e) => {
|
|
1438
|
+
let t = V(e), n = await K(), r = Q();
|
|
1439
|
+
await q(n, re(Ce, U(), void 0, { retryFilter: (await l(U())).retryFilter }));
|
|
1440
|
+
let i = await q(n, A.SqlClient.pipe(k.flatMap((e) => ge(e, {
|
|
1422
1441
|
projectRoot: t,
|
|
1423
1442
|
env: r,
|
|
1424
1443
|
appliedBy: process.env.USER ? `cli:${process.env.USER}` : "cli:user"
|
|
1425
1444
|
}))));
|
|
1426
|
-
return i.applied.length === 0 ? (
|
|
1445
|
+
return i.applied.length === 0 ? (z.info(`db files: no pending file-based migrations (${i.skipped.length} already applied)`), 0) : (z.info(`db files: applied ${i.applied.length} migration(s)`, {
|
|
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 =
|
|
1432
|
-
if (!r) return
|
|
1433
|
-
if ((process.env.NODE_ENV ?? "").toLowerCase() === "production") return
|
|
1434
|
-
let i = await
|
|
1449
|
+
}, _n = async (e) => {
|
|
1450
|
+
let n = V(e), r = c(e, Ot);
|
|
1451
|
+
if (!r) return z.error("voltro db rollback-file <migration-id>"), 2;
|
|
1452
|
+
if ((process.env.NODE_ENV ?? "").toLowerCase() === "production") return z.error("voltro db rollback-file: refusing on prod — schema rollback runs as an explicit deploy step." + t()), 3;
|
|
1453
|
+
let i = await q(await K(), A.SqlClient.pipe(k.flatMap((e) => me(e, {
|
|
1435
1454
|
projectRoot: n,
|
|
1436
1455
|
id: r
|
|
1437
1456
|
}))));
|
|
1438
|
-
return
|
|
1439
|
-
},
|
|
1457
|
+
return z.info(`db rollback-file: rolled back ${i.id} in ${i.durationMs}ms`), 0;
|
|
1458
|
+
}, vn = () => {
|
|
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
|
+
}, yn = (e) => e.trim().toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "") || "migration", bn = (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,54 +1497,54 @@ 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
|
+
`, $ = {
|
|
1501
|
+
plan: Yt,
|
|
1502
|
+
apply: Zt,
|
|
1503
|
+
branch: an,
|
|
1504
|
+
plans: on,
|
|
1505
|
+
drift: mn,
|
|
1506
|
+
files: gn,
|
|
1507
|
+
"rollback-file": _n,
|
|
1508
|
+
migrate: jt,
|
|
1509
|
+
rollback: Mt,
|
|
1510
|
+
status: Nt,
|
|
1511
|
+
seed: Ft,
|
|
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 = yn(r ?? c(i, []) ?? "migration"), l = `${vn()}_${s}`, u = C(o, "migrations"), d = C(u, `${l}.migration.ts`);
|
|
1514
|
+
return await E.mkdir(u, { recursive: !0 }), await E.writeFile(d, bn(l, s), "utf8"), z.info(`created ${w(o, d)}`), console.error("Fill in the apply/undo steps, then run `voltro db migrate` (rollback with `voltro db rollback`)."), console.error("For a plain schema shape change you may not need this — `voltro db apply` diffs declared vs live."), 0;
|
|
1496
1515
|
},
|
|
1497
|
-
squash:
|
|
1498
|
-
"restore-snapshot":
|
|
1499
|
-
"gc-snapshots":
|
|
1516
|
+
squash: ln,
|
|
1517
|
+
"restore-snapshot": sn,
|
|
1518
|
+
"gc-snapshots": cn,
|
|
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 =
|
|
1532
|
+
}, c = U(), l = await K(), u = await q(l, A.SqlClient.pipe(k.flatMap(ue))), d = (e) => u.tables.find((t) => t.name === e)?.columns.map((e) => ({
|
|
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
|
|
1521
|
-
for (let e of
|
|
1539
|
+
let m = async (e) => await q(l, A.SqlClient.pipe(k.flatMap((t) => t.unsafe(e)))), h = async (e) => Number(Object.values((await m(`SELECT COUNT(*) AS n FROM "${e}"`))[0] ?? { n: 0 })[0] ?? 0), g = Ie(s, f, p, await h(r));
|
|
1540
|
+
for (let e of Re(s, g, await h(n))) console.log(e);
|
|
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 Ue(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) => {
|
|
1528
|
-
let t =
|
|
1547
|
+
let t = U(), n = [];
|
|
1529
1548
|
for (let t = 0; t < e.length; t += 1) {
|
|
1530
1549
|
if (e[t] !== "--table") continue;
|
|
1531
1550
|
let i = e[t + 1];
|
|
@@ -1536,82 +1555,90 @@ export default defineMigration({
|
|
|
1536
1555
|
column: o
|
|
1537
1556
|
});
|
|
1538
1557
|
}
|
|
1539
|
-
let i = [...
|
|
1540
|
-
return console.log(
|
|
1558
|
+
let i = [...We, ...n], a = await q(await K(), A.SqlClient.pipe(k.flatMap((e) => k.promise(() => nt(e, t, i, W)))));
|
|
1559
|
+
return console.log(rt(a, t)), it(a);
|
|
1541
1560
|
},
|
|
1542
1561
|
"encrypt-column": async (e) => {
|
|
1543
|
-
let t =
|
|
1562
|
+
let t = U(), n = e.includes("--dry-run"), i = e.includes("--yes"), a = (t) => {
|
|
1544
1563
|
let n = e.indexOf(t);
|
|
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 = Ne(l), d = o(e, Ot).filter((e) => e.includes(".")).map(pt);
|
|
1549
1568
|
if (d.length === 0) throw new r("voltro db encrypt-column: name at least one <table>.<column>");
|
|
1550
|
-
let f = await
|
|
1569
|
+
let f = await K(), p = [];
|
|
1551
1570
|
for (let e of d) {
|
|
1552
|
-
let a =
|
|
1553
|
-
let i = await
|
|
1571
|
+
let a = W(e.table), o = W(e.column), l = await q(f, A.SqlClient.pipe(k.flatMap((n) => k.promise(async () => {
|
|
1572
|
+
let i = await k.runPromise(n.unsafe(Tt(t, e, G(t))));
|
|
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 Et(Object.values(i[0])[0]);
|
|
1575
|
+
})))), d = await q(f, A.SqlClient.pipe(k.flatMap((e) => k.promise(async () => await k.runPromise(e.unsafe(`SELECT ${W("id")} AS id, ${o} AS v FROM ${a}`)))))), m = 0;
|
|
1576
|
+
for (let e of d) typeof e.v != "string" || F(e.v) || (m = Math.max(m, bt(e.v)));
|
|
1577
|
+
let h = ht(m, l);
|
|
1578
|
+
if (!h.fits) return console.error(` ✗ ${gt(e, h)}`), 1;
|
|
1579
|
+
if (xt(d.map((e) => e.v).find((e) => typeof e == "string" && F(e)), u) === !1) return console.error(` ✗ ${St(e, c)}`), 1;
|
|
1580
|
+
let g = d.filter((t) => vt(t.v, u, e) !== void 0 || wt(t.v, u, e) !== void 0).length;
|
|
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" && F(t.v)) {
|
|
1589
|
+
let n = wt(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 = vt(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
|
|
1587
|
-
for (let r of n) await
|
|
1588
|
-
})))),
|
|
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 q(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
|
+
})))), z.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(_t(e, n));
|
|
1628
|
+
return n || console.log(Ct(d)), 0;
|
|
1602
1629
|
}
|
|
1603
|
-
},
|
|
1630
|
+
}, xn = (e) => Object.prototype.hasOwnProperty.call($, 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($)) console.error(` ${e}`);
|
|
1608
1635
|
return 1;
|
|
1609
1636
|
}
|
|
1610
|
-
if (!
|
|
1611
|
-
let i =
|
|
1612
|
-
(process.env.DB_DIRECT_URL !== void 0 || process.env.DB_MIGRATE_URL !== void 0) &&
|
|
1637
|
+
if (!xn(n)) return console.error(`voltro db: unknown subcommand '${n}'`), console.error(` known: ${e.join(", ")}`), 2;
|
|
1638
|
+
let i = $[n];
|
|
1639
|
+
(process.env.DB_DIRECT_URL !== void 0 || process.env.DB_MIGRATE_URL !== void 0) && z.info("using a DIRECT (non-pooler) connection for the db-command path (DB_DIRECT_URL/DB_MIGRATE_URL set)");
|
|
1613
1640
|
let a = (e) => {
|
|
1614
|
-
|
|
1641
|
+
kt(e) ? z.error(At) : 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 { Rt as a, pn as i, H as n, kt as o, Lt as r, Sn as s, At as t };
|