@voltro/cli 0.52.0 → 0.53.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 +229 -0
- package/THIRD-PARTY-NOTICES.md +8311 -3318
- package/dist/{apiBuild-CSFI8QGq.js → apiBuild-CaPfoWku.js} +11 -5
- package/dist/apiBuild-DHtLXYx9.js +2 -0
- package/dist/bin.js +1 -1
- package/dist/build-D-OnvNMf.js +843 -0
- package/dist/{checkCommand-COmqc2cB.js → checkCommand-C5elt0tW.js} +6 -6
- package/dist/{checkCommand-2SbqzukH.js → checkCommand-D2ZduVlh.js} +1 -1
- package/dist/codegen-BWpt3VgF.js +2 -0
- package/dist/{codegen-VF479Cnb.js → codegen-FEk8AZHb.js} +2 -2
- package/dist/{codegenCommand-DCdG2JN-.js → codegenCommand-BOiWQ5hz.js} +4 -4
- package/dist/{codemodRunner-r7J9lIa7.js → codemodRunner-BjtB2lq6.js} +109 -11
- package/dist/{commands-Cc_nV8WI.js → commands-DyxAmhP0.js} +30 -30
- package/dist/{dashboardCommand-C-gKvwqh.js → dashboardCommand-BdKTyT13.js} +5 -5
- package/dist/{dataCommand-BgpBHnlB.js → dataCommand-Bab9X7s8.js} +2 -2
- package/dist/{dbCommand-sHedr-NJ.js → dbCommand-06O2finM.js} +277 -236
- package/dist/dbCommand-B1EXBC6f.js +2 -0
- package/dist/{dev-CRHoCEiy.js → dev-C6LGF4iY.js} +3006 -2426
- package/dist/{dev--A3nsxA3.js → dev-GjJWAYo2.js} +1 -1
- package/dist/doctorCommand-B0hX0tdz.js +2 -0
- package/dist/{doctorCommand-DtfJ3FA6.js → doctorCommand-etMkflRc.js} +101 -69
- package/dist/{dormancyCommand-Drn7o0No.js → dormancyCommand-UwZ1AZzB.js} +1 -1
- package/dist/{embeddingsCommand-Z-jO1fWN.js → embeddingsCommand-C70zWHwo.js} +1 -1
- package/dist/{envCommand-D4gCrrTZ.js → envCommand-dSyKvRkM.js} +18 -18
- package/dist/{evolveCommand-CMROeKeA.js → evolveCommand-CG0_ebO5.js} +2 -2
- package/dist/fileConventions-DASGEmj-.js +35 -0
- package/dist/{fileTaxonomy-DvDUV9wq.js → fileTaxonomy-B7uxipWS.js} +55 -55
- package/dist/fontPipeline-LxIHa1vo.js +2 -0
- package/dist/fontPipeline-Tsh8kZfA.js +152 -0
- package/dist/frameworkTableAssembly-C_7Z-rMs.js +2 -0
- package/dist/{frameworkTableAssembly-w-XnLa3q.js → frameworkTableAssembly-DKx3ba3S.js} +5 -5
- package/dist/imagePipeline-B_GVJgm6.js +2 -0
- package/dist/imagePipeline-CBZmjT4i.js +127 -0
- package/dist/index.js +1 -1
- package/dist/{infoCommand-DXM868o_.js → infoCommand-_53iOc_j.js} +1 -1
- package/dist/{inspect-CtL_xTbu.js → inspect-Bd8-9wsi.js} +1 -1
- package/dist/inspect-CuoDInfZ.js +2 -0
- package/dist/{inspectGateHint-BjnFubmH.js → inspectGateHint-4LxkNtrz.js} +1 -1
- package/dist/manifestBuild-C4-J1-m_.js +2 -0
- package/dist/{manifestBuild-CuU1VrSm.js → manifestBuild-Cqgsx2bM.js} +1 -1
- package/dist/{metaCommands-C6RFmF1r.js → metaCommands-Cn2oboG4.js} +8 -2
- package/dist/{migrate-D0F-eTlK.js → migrate-Cko9rswM.js} +2 -2
- package/dist/{pageConvention-CzUiSbtU.js → pageConvention-C938S8oC.js} +1 -1
- package/dist/{privacyCommand-DGdopOI6.js → privacyCommand-DWTQMC6R.js} +2 -2
- package/dist/{probeCommand-C9gazU0H.js → probeCommand-DkGGLknv.js} +83 -24
- package/dist/{renderModeScan-CcH2X1_D.js → renderModeScan-CUbOeOAg.js} +3 -1
- package/dist/{renderProfile-Ck32Fzxr.js → renderProfile-CskIgAfn.js} +2 -2
- package/dist/{runtimeTrace-BPQyCmC5.js → runtimeTrace-c0APJz7E.js} +1 -1
- package/dist/{sdkgen-Se88ifTd.js → sdkgen-BiQCgIEr.js} +1 -1
- package/dist/{serveCommand-DkP3OT0W.js → serveCommand-CueKQgzl.js} +869 -805
- package/dist/serveCommand-DsnrVN3U.js +2 -0
- package/dist/serveEntry.js +1 -1
- package/dist/start-BJzZLbt8.js +3 -0
- package/dist/start-ekPan8BT.js +1510 -0
- package/dist/startEntry.js +1 -1
- package/dist/{staticCommand-BwNEDlSU.js → staticCommand-xlSL-IWk.js} +1 -1
- package/dist/{test-f3amja6a.js → test-BWPQcRoB.js} +1 -1
- package/dist/updateCommand-Bqql_rsQ.js +2 -0
- package/dist/{updateCommand-BMk2e4ky.js → updateCommand-C_8I8Rzo.js} +139 -115
- package/dist/webDev-C7jWJ5dX.js +2 -0
- package/dist/{webDev-BgWL9gKV.js → webDev-oczpugbx.js} +1455 -922
- package/dist/{webhooksCommand-CoIO3jbj.js → webhooksCommand-4SVPDjKg.js} +1 -1
- package/package.json +60 -19
- package/templates/AGENTS.md +5 -3
- package/templates/agent-docs/_index.md +5 -3
- package/templates/agent-docs/_manifest.json +20 -4
- package/templates/agent-docs/ai.md +2 -2
- package/templates/agent-docs/authentication.md +1 -1
- package/templates/agent-docs/cli.md +2 -2
- package/templates/agent-docs/configuration.md +17 -0
- package/templates/agent-docs/data.md +470 -26
- package/templates/agent-docs/database/advancedqueries.md +7 -7
- package/templates/agent-docs/database/columntypes.md +2 -2
- package/templates/agent-docs/database/querying.md +1 -1
- package/templates/agent-docs/database/schema.md +1 -1
- package/templates/agent-docs/database/seedsdialects.md +1 -1
- package/templates/agent-docs/database/transactions.md +3 -3
- package/templates/agent-docs/deployment.md +8 -0
- package/templates/agent-docs/internationalization.md +2 -2
- package/templates/agent-docs/introduction.md +7 -1
- package/templates/agent-docs/local-first-mobile.md +102 -4
- package/templates/agent-docs/observability.md +2 -0
- package/templates/agent-docs/plugins/auth.md +1 -1
- package/templates/agent-docs/plugins/comments.md +142 -0
- package/templates/agent-docs/plugins/notifications.md +47 -4
- package/templates/agent-docs/plugins/presence.md +16 -3
- package/templates/agent-docs/plugins/prometheus.md +1 -1
- package/templates/agent-docs/plugins/queue.md +129 -0
- package/templates/agent-docs/plugins.md +11 -7
- package/templates/agent-docs/reference.md +16 -4
- package/templates/agent-docs/routing.md +527 -3
- package/templates/agent-docs/schema-driven-ui.md +214 -3
- package/templates/agent-docs/security.md +3 -3
- package/templates/agent-docs/whats-new.md +160 -66
- package/templates/apps/api-ai/package.json +6 -6
- 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 +9 -9
- package/templates/apps/api-collab/package.json +8 -8
- package/templates/apps/api-data-advanced/package.json +8 -8
- package/templates/apps/api-durable/package.json +8 -8
- package/templates/apps/api-feature-flags/package.json +9 -9
- package/templates/apps/api-governance/package.json +8 -8
- package/templates/apps/api-kv/package.json +8 -8
- package/templates/apps/api-moderation/package.json +8 -8
- package/templates/apps/api-observability/package.json +8 -8
- package/templates/apps/api-ratelimit/package.json +8 -8
- package/templates/apps/api-rbac/package.json +8 -8
- package/templates/apps/api-rest/package.json +7 -7
- package/templates/apps/api-row-history/package.json +8 -8
- package/templates/apps/api-saas/package.json +10 -10
- 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-webhooks/package.json +9 -9
- package/templates/apps/changelog/app.config.ts +26 -2
- package/templates/apps/changelog/content/releases/{0.1.0.mdx → v0-1-0.mdx} +0 -1
- package/templates/apps/changelog/content/releases/{0.2.0.mdx → v0-2-0.mdx} +0 -1
- package/templates/apps/changelog/package.json +8 -8
- package/templates/apps/changelog/src/collections/releases.collection.ts +48 -0
- package/templates/apps/changelog/src/globals.d.ts +1 -1
- package/templates/apps/changelog/src/locales/de.ts +1 -1
- package/templates/apps/changelog/src/locales/en.ts +1 -1
- package/templates/apps/changelog/src/pages/[locale]/[slug]/page.tsx +7 -4
- package/templates/apps/changelog/src/pages/[locale]/mirrors.test.tsx +13 -41
- package/templates/apps/changelog/src/pages/[slug]/page.test.tsx +26 -51
- package/templates/apps/changelog/src/pages/[slug]/page.tsx +21 -19
- package/templates/apps/changelog/src/pages/page.test.tsx +14 -37
- package/templates/apps/changelog/src/pages/page.tsx +18 -12
- 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/content/docs/de/guides/first-page.md +4 -0
- package/templates/apps/frontend-docs/content/docs/de/intro/getting-started.md +4 -0
- package/templates/apps/frontend-docs/content/docs/en/guides/first-page.md +4 -0
- package/templates/apps/frontend-docs/content/docs/en/intro/getting-started.md +4 -0
- package/templates/apps/frontend-docs/package.json +8 -6
- package/templates/apps/frontend-docs/src/collections/docs.collection.ts +21 -0
- package/templates/apps/frontend-docs/src/locales/de.ts +0 -5
- package/templates/apps/frontend-docs/src/locales/en.ts +0 -5
- package/templates/apps/frontend-docs/src/pages/[locale]/docs/[...slug]/page.tsx +17 -9
- package/templates/apps/frontend-docs/src/pages/[locale]/mirrors.test.tsx +10 -5
- package/templates/apps/frontend-docs/src/pages/[locale]/page.tsx +8 -0
- package/templates/apps/frontend-docs/src/pages/docs/[...slug]/page.test.tsx +53 -15
- package/templates/apps/frontend-docs/src/pages/docs/[...slug]/page.tsx +27 -33
- package/templates/apps/frontend-docs/src/pages/page.test.tsx +17 -3
- package/templates/apps/frontend-docs/src/pages/page.tsx +16 -12
- package/templates/apps/frontend-i18n/package.json +6 -6
- package/templates/apps/frontend-landing/package.json +6 -6
- 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/content/posts/cms-to-ssg.md +12 -0
- package/templates/apps/frontend-static-blog/content/posts/hello-static.md +12 -0
- package/templates/apps/frontend-static-blog/content/posts/islands-not-hydration.md +14 -0
- package/templates/apps/frontend-static-blog/package.json +8 -6
- package/templates/apps/frontend-static-blog/src/collections/posts.collection.ts +27 -0
- package/templates/apps/frontend-static-blog/src/pages/[locale]/blog/[slug]/page.tsx +7 -4
- package/templates/apps/frontend-static-blog/src/pages/[locale]/mirrors.test.tsx +7 -1
- package/templates/apps/frontend-static-blog/src/pages/blog/[slug]/page.test.tsx +19 -9
- package/templates/apps/frontend-static-blog/src/pages/blog/[slug]/page.tsx +19 -21
- package/templates/apps/frontend-static-blog/src/pages/page.test.tsx +18 -5
- package/templates/apps/frontend-static-blog/src/pages/page.tsx +21 -14
- package/templates/apps/frontend-status/package.json +8 -8
- package/templates/apps/mobile-app/package.json +4 -4
- package/dist/apiBuild-BYBpL7Pz.js +0 -2
- package/dist/build-CPgcMQug.js +0 -793
- package/dist/codegen-CctkDO-1.js +0 -2
- package/dist/dbCommand-DNb6yeOG.js +0 -2
- package/dist/doctorCommand-CqoWA2p5.js +0 -2
- package/dist/fileConventions-DOqD3lPS.js +0 -34
- package/dist/frameworkTableAssembly-C6ETawPR.js +0 -2
- package/dist/inspect-CuGDYES0.js +0 -2
- package/dist/manifestBuild-CPjhvM62.js +0 -2
- package/dist/serveCommand-DLc-BznW.js +0 -2
- package/dist/start-DfL3fOiN.js +0 -3
- package/dist/start-jw89Xbqy.js +0 -1339
- package/dist/updateCommand-5gFVfK5q.js +0 -2
- package/dist/webDev-CZbTsDcH.js +0 -2
- package/templates/apps/changelog/scripts/generate-rss.mjs +0 -38
- package/templates/apps/changelog/src/lib/releases.ts +0 -21
- package/templates/apps/frontend-static-blog/src/content/posts.ts +0 -64
|
@@ -6,21 +6,21 @@ import { a, i as o, n as s, t as c } from "./cliArgs-D4p8n7EE.js";
|
|
|
6
6
|
import { r as l } from "./dialectDriver-czCHYpeH.js";
|
|
7
7
|
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-Dgsiwk_e.js";
|
|
9
|
-
import { g, n as _, s as v } from "./frameworkTableAssembly-
|
|
10
|
-
import {
|
|
11
|
-
import { r as x, t as S } from "./inspectGateHint-
|
|
9
|
+
import { g, n as _, s as v } from "./frameworkTableAssembly-DKx3ba3S.js";
|
|
10
|
+
import { S as y, x as b } from "./fileConventions-DASGEmj-.js";
|
|
11
|
+
import { r as x, t as S } from "./inspectGateHint-4LxkNtrz.js";
|
|
12
12
|
import { basename as ee, join as C, relative as w, resolve as T } from "node:path";
|
|
13
13
|
import { promises as E, writeSync as te } from "node:fs";
|
|
14
14
|
import { pathToFileURL as D } from "node:url";
|
|
15
|
-
import { createLogger as O } from "@voltro/logger";
|
|
16
|
-
import { actorsTable as
|
|
15
|
+
import { createLogger as O, logFormat as k } from "@voltro/logger";
|
|
16
|
+
import { actorsTable as ne, branchNamespaceName as re, decodeFieldValue as ie, encodeFieldValue as ae, frameworkTables as oe, isEncrypted as A, isMigrationDefinition as se, isRawEncoding as ce, makeNamespaceBranchExecutor as le, provisionBranch as ue, quoteIdent as de, registerCoreTables as fe, resolveBranchMechanism as pe, teardownBranch as me } from "@voltro/database";
|
|
17
17
|
import { Effect as j } from "effect";
|
|
18
18
|
import { SqlClient as M } from "@effect/sql";
|
|
19
|
-
import { DEFAULT_CDC_CHANNEL as
|
|
20
|
-
import { InMemoryDataStore as
|
|
21
|
-
import { createHash as
|
|
19
|
+
import { DEFAULT_CDC_CHANNEL as he, applyPlan as ge, applySchema as _e, assessRollingDeployGate as ve, branchRehearsalExitCode as ye, declaredSnapshot as be, destructiveScope as xe, fingerprintSchema as Se, formatBranchRehearsal as Ce, ignoreTablesFromEnv as N, introspectSchema as P, pendingFileMigrationIds as we, planMigrations as F, recordUpToDate as Te, rehearseMigrationOnBranch as Ee, rollbackFileBasedMigration as De, rollingDeployUnsafeOps as Oe, runFileBasedMigrations as ke, shortFingerprint as I, squashMigrationPlans as Ae, unblockLossy as je } from "@voltro/database/sql";
|
|
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 Pe = (e) => typeof e != "string", Fe = (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 Pe = (e) => typeof e != "string", Fe = (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 Pe = (e) => typeof e != "string", Fe = (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,
|
|
@@ -146,7 +146,7 @@ var Pe = (e) => typeof e != "string", Fe = (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 Pe = (e) => typeof e != "string", Fe = (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 Pe = (e) => typeof e != "string", Fe = (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 = L) => 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 = L) => {
|
|
214
214
|
let n;
|
|
215
215
|
try {
|
|
216
216
|
n = JSON.parse(e);
|
|
@@ -222,11 +222,11 @@ var Pe = (e) => typeof e != "string", Fe = (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,
|
|
@@ -234,21 +234,21 @@ var Pe = (e) => typeof e != "string", Fe = (e, t, n, r) => {
|
|
|
234
234
|
}), R = (e) => {
|
|
235
235
|
let t = e.classification;
|
|
236
236
|
return t === void 0 || e.hits === void 0 || e.hits === 0 ? !1 : t.examined === e.hits && t.undecidable === 0 && t.asKey === 0 && t.redactionMarkerOnly === e.hits;
|
|
237
|
-
},
|
|
238
|
-
let i = `WHERE ${
|
|
237
|
+
}, $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 j.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
|
-
}),
|
|
243
|
+
}), tt = async (e, t) => {
|
|
244
244
|
let n = await j.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 Pe = (e) => typeof e != "string", Fe = (e, t, n, r) => {
|
|
|
260
260
|
continue;
|
|
261
261
|
}
|
|
262
262
|
try {
|
|
263
|
-
let s = await
|
|
263
|
+
let s = await tt(e, `SELECT COUNT(*) AS n FROM ${n}\n WHERE ${Ke(r(a.column), t)}`), c = [];
|
|
264
264
|
if (s > 0) for (let i of L) try {
|
|
265
|
-
let o = await
|
|
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 Pe = (e) => typeof e != "string", Fe = (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,7 +291,7 @@ var Pe = (e) => typeof e != "string", Fe = (e, t, n, r) => {
|
|
|
291
291
|
}
|
|
292
292
|
}
|
|
293
293
|
return i;
|
|
294
|
-
},
|
|
294
|
+
}, rt = (e, t) => {
|
|
295
295
|
let n = L.length, r = [`credential scan · dialect ${t}`, ""], i = /* @__PURE__ */ new Set();
|
|
296
296
|
for (let t of e) {
|
|
297
297
|
if (t.unavailable === "column") {
|
|
@@ -309,11 +309,11 @@ var Pe = (e) => typeof e != "string", Fe = (e, t, n, r) => {
|
|
|
309
309
|
let e = R(t), n = (t.hits ?? 0) === 0 ? "✓" : e ? "~" : "✗";
|
|
310
310
|
r.push(` ${n} ${t.table}.${t.column} — ${t.hits} of ${t.scanned} row(s) contain a credential-shaped NAME (anywhere in the value)`), (t.matchedNeedles?.length ?? 0) > 0 && r.push(` matched (rows per needle, may overlap): ${t.matchedNeedles.map((e) => `${e.needle} (${e.rows})`).join(", ")}`);
|
|
311
311
|
let a = t.classification;
|
|
312
|
-
a !== void 0 && (r.push(` examined ${a.examined} of ${t.hits} matched row(s)${a.examined < (t.hits ?? 0) ? " (capped at 500)" : ""}: ${a.asKey} as a JSON KEY, ${a.redactionMarkerOnly} only inside a redaction marker${a.undecidable > 0 ? `, ${a.undecidable} not parseable as JSON` : ""}`), e && r.push(` EXPLAINED — every match is \`${
|
|
312
|
+
a !== void 0 && (r.push(` examined ${a.examined} of ${t.hits} matched row(s)${a.examined < (t.hits ?? 0) ? " (capped at 500)" : ""}: ${a.asKey} as a JSON KEY, ${a.redactionMarkerOnly} only inside a redaction marker${a.undecidable > 0 ? `, ${a.undecidable} not parseable as JSON` : ""}`), e && r.push(` EXPLAINED — every match is \`${qe.join("` / `")}\`, the framework's own`, " record that a `.sensitive()` column was left OUT. Nothing to purge, nothing to rotate."));
|
|
313
313
|
}
|
|
314
314
|
let a = e.reduce((e, t) => e + (R(t) ? 0 : t.hits ?? 0), 0), o = e.reduce((e, t) => e + (R(t) ? t.hits ?? 0 : 0), 0);
|
|
315
315
|
return r.push(""), o > 0 && r.push(` ${o} row(s) matched only the framework's own redaction markers and are NOT findings.`), a > 0 ? r.push(` ${a} row(s) carry something credential-shaped.`, " Purge them AND rotate the credentials — assume anything written to a log", " table has been read. Then stop putting the credential on the Subject:", " `connectionCredentials(...)` keeps it in the framework vault.") : e.every((e) => e.scanned === void 0 || e.scanned === 0 || e.unavailable !== void 0) ? r.push(" NOTHING WAS SCANNED. This run proves nothing about your data.") : r.push(" No credential-shaped keys found in the rows that exist."), r.push("", ` These are NAME heuristics (${n} of them), not proof. A credential in a`, " column whose key is not credential-shaped — `keyValue`, `pat`, `authz` —", " is invisible here. A clean run means \"no credential-shaped NAME found\",", " which is not the same as \"no credential\".", "", " Run this on EVERY environment. A dev database is not a sample of production."), r.join("\n");
|
|
316
|
-
},
|
|
316
|
+
}, it = (e) => e.some((e) => (e.hits ?? 0) > 0 && !R(e)) ? 1 : e.every((e) => e.unavailable !== void 0 || e.scanned === void 0 || e.scanned === 0) ? 2 : 0, at = /\.migration\.ts$/, ot = async (e, t) => {
|
|
317
317
|
let n = [];
|
|
318
318
|
for (let r of e) {
|
|
319
319
|
let e;
|
|
@@ -323,7 +323,7 @@ var Pe = (e) => typeof e != "string", Fe = (e, t, n, r) => {
|
|
|
323
323
|
t.warn("migration: failed to import", { file: r }, e);
|
|
324
324
|
continue;
|
|
325
325
|
}
|
|
326
|
-
let i = (e.default &&
|
|
326
|
+
let i = (e.default && se(e.default) ? e.default : void 0) ?? Object.values(e).find(se);
|
|
327
327
|
if (!i) {
|
|
328
328
|
t.warn("migration: no defineMigration export", { file: r });
|
|
329
329
|
continue;
|
|
@@ -333,7 +333,7 @@ var Pe = (e) => typeof e != "string", Fe = (e, t, n, r) => {
|
|
|
333
333
|
idInFile: i.id,
|
|
334
334
|
idFromFile: ee(r).replace(/\.migration\.ts$/, "")
|
|
335
335
|
});
|
|
336
|
-
let a = await E.readFile(r, "utf8").catch(() => ""), o =
|
|
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,10 +341,10 @@ var Pe = (e) => typeof e != "string", Fe = (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 j.runPromise(
|
|
347
|
-
},
|
|
346
|
+
return j.runPromise(_e(oe, r, void 0, i === void 0 ? {} : { retryFilter: i }).pipe(j.provide(e)));
|
|
347
|
+
}, ct = (e) => j.runPromise(j.gen(function* () {
|
|
348
348
|
let e = yield* (yield* M.SqlClient)`SELECT id, status, hash, "appliedAt" FROM "_voltro_migrations"`.pipe(j.orElseSucceed(() => []));
|
|
349
349
|
return new Map(e.map((e) => [e.id, e]));
|
|
350
350
|
}).pipe(j.provide(e))), z = (e, t) => j.runPromise(j.gen(function* () {
|
|
@@ -363,14 +363,14 @@ var Pe = (e) => typeof e != "string", Fe = (e, t, n, r) => {
|
|
|
363
363
|
"errorStack" = EXCLUDED."errorStack",
|
|
364
364
|
"updatedAt" = now()
|
|
365
365
|
`;
|
|
366
|
-
}).pipe(j.provide(e))),
|
|
366
|
+
}).pipe(j.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") {
|
|
@@ -471,9 +471,9 @@ var Pe = (e) => typeof e != "string", Fe = (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,
|
|
@@ -542,9 +542,9 @@ var Pe = (e) => typeof e != "string", Fe = (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 Pe = (e) => typeof e != "string", Fe = (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,22 +574,22 @@ var Pe = (e) => typeof e != "string", Fe = (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}`,
|
|
@@ -599,25 +599,25 @@ var Pe = (e) => typeof e != "string", Fe = (e, t, n, r) => {
|
|
|
599
599
|
` null / empty ${e.empty}`,
|
|
600
600
|
` ${n.padEnd(18)} ${e.encrypted}`
|
|
601
601
|
].join("\n");
|
|
602
|
-
},
|
|
602
|
+
}, vt = (e, t, n) => {
|
|
603
603
|
if (e == null) return;
|
|
604
604
|
let r = typeof e == "string" ? e : String(e);
|
|
605
605
|
if (r === "" || A(r)) return;
|
|
606
|
-
let i =
|
|
606
|
+
let i = ae(t, r), a;
|
|
607
607
|
try {
|
|
608
|
-
a =
|
|
608
|
+
a = ie(t, i);
|
|
609
609
|
} catch (e) {
|
|
610
610
|
throw Error(`${n.table}.${n.column}: the value could not be read back the way the app reads it (${e.message ?? String(e)}). Nothing was written.`);
|
|
611
611
|
}
|
|
612
612
|
if (a !== r) throw Error(`${n.table}.${n.column}: round-trip mismatch — reading the encrypted value back did not return what it was given. Nothing was written.`);
|
|
613
613
|
return i;
|
|
614
|
-
},
|
|
614
|
+
}, yt = (e) => Buffer.byteLength(e, "utf8"), bt = (e) => yt(JSON.stringify(typeof e == "string" ? e : String(e))), xt = (e, t) => {
|
|
615
615
|
if (e !== void 0) try {
|
|
616
616
|
return t.decrypt(e), !0;
|
|
617
617
|
} catch {
|
|
618
618
|
return !1;
|
|
619
619
|
}
|
|
620
|
-
},
|
|
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) => [
|
|
621
621
|
"",
|
|
622
622
|
" NEXT — this converted the rows that exist. New writes are still plaintext",
|
|
623
623
|
" until the column carries the modifier:",
|
|
@@ -627,25 +627,25 @@ var Pe = (e) => typeof e != "string", Fe = (e, t, n, r) => {
|
|
|
627
627
|
" Order does not matter: a read returns a non-ciphertext value unchanged, so",
|
|
628
628
|
" the column may hold a mix while you deploy. Run this again afterwards to",
|
|
629
629
|
" catch anything written in between — it skips what is already encrypted."
|
|
630
|
-
].join("\n"),
|
|
630
|
+
].join("\n"), wt = (e, t, n) => {
|
|
631
631
|
if (typeof e != "string" || !A(e)) return;
|
|
632
632
|
let r;
|
|
633
633
|
try {
|
|
634
|
-
r =
|
|
634
|
+
r = ce(t, e);
|
|
635
635
|
} catch {
|
|
636
636
|
return;
|
|
637
637
|
}
|
|
638
638
|
if (r !== !0) return;
|
|
639
|
-
let i =
|
|
639
|
+
let i = ie(t, e);
|
|
640
640
|
if (typeof i != "string") return;
|
|
641
|
-
let a =
|
|
642
|
-
if (
|
|
641
|
+
let a = ae(t, i);
|
|
642
|
+
if (ie(t, a) !== i) throw Error(`${n.table}.${n.column}: re-encoding did not round-trip. Nothing was written.`);
|
|
643
643
|
return a;
|
|
644
|
-
},
|
|
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
645
|
if (e == null) return;
|
|
646
646
|
let t = Number(e);
|
|
647
647
|
return Number.isFinite(t) && t >= 0 ? t : void 0;
|
|
648
|
-
}, B = O({ scope: "voltro:db" }),
|
|
648
|
+
}, B = O({ scope: "voltro:db" }), Dt = /* @__PURE__ */ new Set([
|
|
649
649
|
"node_modules",
|
|
650
650
|
"dist",
|
|
651
651
|
"build",
|
|
@@ -657,13 +657,13 @@ var Pe = (e) => typeof e != "string", Fe = (e, t, n, r) => {
|
|
|
657
657
|
let n = [], r = async (e) => {
|
|
658
658
|
let i = await E.readdir(e, { withFileTypes: !0 }).catch(() => []);
|
|
659
659
|
for (let a of i) {
|
|
660
|
-
if (
|
|
660
|
+
if (Dt.has(a.name)) continue;
|
|
661
661
|
let i = C(e, a.name);
|
|
662
662
|
a.isDirectory() ? await r(i) : a.isFile() && t.test(a.name) && n.push(i);
|
|
663
663
|
}
|
|
664
664
|
};
|
|
665
665
|
return await r(e), n;
|
|
666
|
-
},
|
|
666
|
+
}, Ot = [
|
|
667
667
|
"--against",
|
|
668
668
|
"--batch",
|
|
669
669
|
"--before",
|
|
@@ -682,23 +682,23 @@ var Pe = (e) => typeof e != "string", Fe = (e, t, n, r) => {
|
|
|
682
682
|
"--store",
|
|
683
683
|
"--to",
|
|
684
684
|
"--token"
|
|
685
|
-
], H = (e) => T(c(e,
|
|
685
|
+
], H = (e) => T(c(e, Ot) ?? process.cwd()), U = () => u("migration"), kt = (e) => {
|
|
686
686
|
let t = e;
|
|
687
687
|
if (typeof t != "object" || !t) return !1;
|
|
688
688
|
if (t.code === "ERR_OUT_OF_RANGE" || t.cause?.code === "ERR_OUT_OF_RANGE") return !0;
|
|
689
689
|
let n = `${t.message ?? ""} ${t.cause?.message ?? ""} ${t.stack ?? ""}`;
|
|
690
690
|
return /ERR_OUT_OF_RANGE|out of range/i.test(n) && /pg-protocol|parseDataRow|buffer-reader|BufferReader/i.test(n);
|
|
691
|
-
},
|
|
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`.)", W = () => {
|
|
692
692
|
let e = (process.env.DB_DIALECT ?? "postgres").toLowerCase();
|
|
693
693
|
if (e === "memory") throw new r("voltro db: subcommands require a real dialect, not DB_DIALECT=memory.");
|
|
694
694
|
return e;
|
|
695
|
-
}, G = (e) =>
|
|
696
|
-
let t = H(e), n = e.includes("--dry-run"), r = await
|
|
695
|
+
}, G = (e) => de(e, W()), K = (e) => e === "mysql" || e === "mariadb" ? "table_schema = DATABASE()" : e === "mssql" ? "table_schema = SCHEMA_NAME()" : "table_schema = 'public'", q = async () => (await l(W())).makeSqlLayer(U()), jt = async (e) => {
|
|
696
|
+
let t = H(e), n = e.includes("--dry-run"), r = await ot(await V(t, at), B);
|
|
697
697
|
if (r.length === 0) return B.info("no migrations found", { root: t }), 0;
|
|
698
698
|
if (n) {
|
|
699
699
|
let e = /* @__PURE__ */ new Set();
|
|
700
700
|
try {
|
|
701
|
-
let t = await
|
|
701
|
+
let t = await dt(r, await q());
|
|
702
702
|
e = new Set(t.filter((e) => e.status === "applied").map((e) => e.id));
|
|
703
703
|
} catch {
|
|
704
704
|
B.warn("migrate --dry-run: could not read the migration ledger — showing ALL as pending");
|
|
@@ -709,29 +709,29 @@ var Pe = (e) => typeof e != "string", Fe = (e, t, n, r) => {
|
|
|
709
709
|
for (let e of t) console.log(` pending ${e.definition.id}`);
|
|
710
710
|
return 0;
|
|
711
711
|
}
|
|
712
|
-
let i = await
|
|
713
|
-
return i.failed ? (process.stderr.write(
|
|
712
|
+
let i = await lt(r, await q(), B);
|
|
713
|
+
return i.failed ? (process.stderr.write(ft(i) + "\n"), 1) : (B.info("migrate complete", {
|
|
714
714
|
applied: i.applied.length,
|
|
715
715
|
skipped: i.skipped.length
|
|
716
716
|
}), 0);
|
|
717
|
-
}, jt = async (e) => {
|
|
718
|
-
let t = H(e), n = s(e, "--to"), r = await at(await V(t, it), B);
|
|
719
|
-
if (r.length === 0) return B.info("no migrations found", { root: t }), 0;
|
|
720
|
-
let i = await lt(r, await q(), B, n ? { to: n } : {});
|
|
721
|
-
return i.failed ? (process.stderr.write(dt(i) + "\n"), 1) : (B.info("rollback complete", { reverted: i.applied.length }), 0);
|
|
722
717
|
}, Mt = async (e) => {
|
|
723
|
-
let t = await
|
|
718
|
+
let t = H(e), n = s(e, "--to"), r = await ot(await V(t, at), B);
|
|
719
|
+
if (r.length === 0) return B.info("no migrations found", { root: t }), 0;
|
|
720
|
+
let i = await ut(r, await q(), B, n ? { to: n } : {});
|
|
721
|
+
return i.failed ? (process.stderr.write(ft(i) + "\n"), 1) : (B.info("rollback complete", { reverted: i.applied.length }), 0);
|
|
722
|
+
}, Nt = async (e) => {
|
|
723
|
+
let t = await ot(await V(H(e), at), B);
|
|
724
724
|
if (t.length === 0) return console.log("no migrations found"), 0;
|
|
725
|
-
let n = await
|
|
725
|
+
let n = await dt(t, await q());
|
|
726
726
|
for (let e of n) {
|
|
727
727
|
let t = e.status === "applied" ? "✓" : e.status === "failed" ? "✗" : e.status === "reverted" ? "↩" : "·", n = e.hashMatches ? "" : " (hash drift!)", r = e.appliedAt ? ` @ ${e.appliedAt.toISOString()}` : "";
|
|
728
728
|
console.log(` ${t} ${e.id} [${e.status}] ${e.name}${r}${n}`);
|
|
729
729
|
}
|
|
730
730
|
return 0;
|
|
731
|
-
},
|
|
731
|
+
}, Pt = async (e) => {
|
|
732
732
|
let t = (s(e, "--store") ?? process.env.DB_DIALECT ?? "postgres").toLowerCase();
|
|
733
733
|
if (t === "memory") return B.warn("voltro db seed: using in-memory store (explicit opt-in via --store memory / DB_DIALECT=memory)"), B.warn(" rows written by this run will NOT persist beyond the process. set DB_DIALECT=postgres or unset to seed the real DB."), {
|
|
734
|
-
store: new
|
|
734
|
+
store: new Me(),
|
|
735
735
|
dispose: async () => {},
|
|
736
736
|
dialectId: "memory"
|
|
737
737
|
};
|
|
@@ -748,10 +748,10 @@ var Pe = (e) => typeof e != "string", Fe = (e, t, n, r) => {
|
|
|
748
748
|
},
|
|
749
749
|
dialectId: n.id
|
|
750
750
|
};
|
|
751
|
-
},
|
|
752
|
-
let t = H(e), n = s(e, "--id"), r = s(e, "--lifecycle"), i = await V(t,
|
|
751
|
+
}, Ft = async (e) => {
|
|
752
|
+
let t = H(e), n = s(e, "--id"), r = s(e, "--lifecycle"), i = await V(t, y), a = await f(i, B);
|
|
753
753
|
if (a.length === 0) return B.info("no seeds found", { root: t }), 0;
|
|
754
|
-
let { store: o, dispose: c, dialectId: l } = await
|
|
754
|
+
let { store: o, dispose: c, dialectId: l } = await Pt(e);
|
|
755
755
|
try {
|
|
756
756
|
if (n) return +((await d(a, n, o, B)).status === "failed");
|
|
757
757
|
let e = r ? a.filter((e) => e.definition.lifecycle === r) : a.filter((e) => e.definition.lifecycle === "boot");
|
|
@@ -767,8 +767,8 @@ var Pe = (e) => typeof e != "string", Fe = (e, t, n, r) => {
|
|
|
767
767
|
B.warn("voltro db seed: store dispose failed", { error: String(e) });
|
|
768
768
|
});
|
|
769
769
|
}
|
|
770
|
-
},
|
|
771
|
-
let t = await V(e,
|
|
770
|
+
}, It = (e) => typeof e == "object" && !!e && "tableName" in e && "fields" in e && typeof e.tableName == "string", Lt = async (e) => {
|
|
771
|
+
let t = await V(e, b), n = [];
|
|
772
772
|
for (let r of t) {
|
|
773
773
|
let t;
|
|
774
774
|
try {
|
|
@@ -780,31 +780,31 @@ var Pe = (e) => typeof e != "string", Fe = (e, t, n, r) => {
|
|
|
780
780
|
});
|
|
781
781
|
continue;
|
|
782
782
|
}
|
|
783
|
-
for (let e of Object.values(t))
|
|
783
|
+
for (let e of Object.values(t)) It(e) && n.push(e);
|
|
784
784
|
}
|
|
785
785
|
return n;
|
|
786
|
-
},
|
|
786
|
+
}, Rt = (e) => {
|
|
787
787
|
let t = new Map(e.map((e) => [e.tableName, e]));
|
|
788
|
-
t.has("actors") || t.set("actors",
|
|
788
|
+
t.has("actors") || t.set("actors", ne);
|
|
789
789
|
let n = t.get("actors"), r = t.get("tenants");
|
|
790
|
-
return
|
|
790
|
+
return fe({
|
|
791
791
|
actors: () => n,
|
|
792
792
|
...r === void 0 ? {} : { tenants: () => r }
|
|
793
793
|
}), [...t.values()];
|
|
794
|
-
},
|
|
794
|
+
}, zt = (e) => {
|
|
795
795
|
let t = /* @__PURE__ */ new Map();
|
|
796
796
|
for (let n of e) {
|
|
797
797
|
let e = n.tableName;
|
|
798
798
|
e !== void 0 && !t.has(e) && t.set(e, n);
|
|
799
799
|
}
|
|
800
800
|
return [...t.values()];
|
|
801
|
-
},
|
|
802
|
-
let t =
|
|
801
|
+
}, Bt = (e) => {
|
|
802
|
+
let t = xe(process.env.VOLTRO_DESTRUCTIVE_OK);
|
|
803
803
|
if (t === void 0 || !e.operations.filter((e) => e.blocked).every((e) => e.classification === "lossy")) return {
|
|
804
804
|
plan: e,
|
|
805
805
|
acknowledged: !1
|
|
806
806
|
};
|
|
807
|
-
let n =
|
|
807
|
+
let n = je(e, t);
|
|
808
808
|
return {
|
|
809
809
|
plan: n,
|
|
810
810
|
acknowledged: !n.operations.some((e) => e.blocked)
|
|
@@ -814,13 +814,13 @@ var Pe = (e) => typeof e != "string", Fe = (e, t, n, r) => {
|
|
|
814
814
|
return await J(e, M.SqlClient.pipe(j.flatMap(P)));
|
|
815
815
|
} catch (e) {
|
|
816
816
|
let t = String(e?.message ?? e);
|
|
817
|
-
if (
|
|
818
|
-
let n = /* @__PURE__ */ Error(`${
|
|
817
|
+
if (kt(e) || /connection error/i.test(t)) {
|
|
818
|
+
let n = /* @__PURE__ */ Error(`${At}\n\nOriginal error: ${t}`);
|
|
819
819
|
throw n.cause = e, n;
|
|
820
820
|
}
|
|
821
821
|
throw e;
|
|
822
822
|
}
|
|
823
|
-
},
|
|
823
|
+
}, Vt = {
|
|
824
824
|
safe: "\x1B[32m✓\x1B[0m",
|
|
825
825
|
"needs-default": "\x1B[32m⊕\x1B[0m",
|
|
826
826
|
"needs-backfill": "\x1B[33m⊕\x1B[0m",
|
|
@@ -828,7 +828,7 @@ var Pe = (e) => typeof e != "string", Fe = (e, t, n, r) => {
|
|
|
828
828
|
lossy: "\x1B[31m✗\x1B[0m",
|
|
829
829
|
"online-required": "\x1B[36m◷\x1B[0m",
|
|
830
830
|
"multi-step": "\x1B[35m⇉\x1B[0m"
|
|
831
|
-
},
|
|
831
|
+
}, Ht = (e) => {
|
|
832
832
|
let t = e.op, n;
|
|
833
833
|
switch (t.kind) {
|
|
834
834
|
case "create-table":
|
|
@@ -890,9 +890,9 @@ var Pe = (e) => typeof e != "string", Fe = (e, t, n, r) => {
|
|
|
890
890
|
break;
|
|
891
891
|
case "drop-check": n = `ALTER TABLE ${t.table} DROP CHECK ${t.column}`;
|
|
892
892
|
}
|
|
893
|
-
let r =
|
|
893
|
+
let r = Vt[e.classification], i = e.reason ? ` [2m# ${e.reason}[0m` : "", a = e.blocked ? `\n [31m! ${e.blocked.fix}[0m` : "";
|
|
894
894
|
return ` ${r} ${n}${i}${a}`;
|
|
895
|
-
},
|
|
895
|
+
}, Ut = async (e, t) => {
|
|
896
896
|
let n = e.operations.filter((e) => e.classification === "needs-default" && e.op.kind === "add-column");
|
|
897
897
|
if (n.length === 0) return;
|
|
898
898
|
let r = [];
|
|
@@ -901,7 +901,7 @@ var Pe = (e) => typeof e != "string", Fe = (e, t, n, r) => {
|
|
|
901
901
|
if (i === void 0 || a === void 0) continue;
|
|
902
902
|
let o = 0;
|
|
903
903
|
try {
|
|
904
|
-
let e = await J(t, M.SqlClient.pipe(j.flatMap((e) => e.unsafe(`SELECT COUNT(*) AS n FROM ${
|
|
904
|
+
let e = await J(t, M.SqlClient.pipe(j.flatMap((e) => e.unsafe(`SELECT COUNT(*) AS n FROM ${de(i, W())}`))));
|
|
905
905
|
o = Number(Object.values(e[0] ?? { n: 0 })[0] ?? 0);
|
|
906
906
|
} catch {
|
|
907
907
|
continue;
|
|
@@ -913,9 +913,9 @@ var Pe = (e) => typeof e != "string", Fe = (e, t, n, r) => {
|
|
|
913
913
|
for (let e of r) console.log(e);
|
|
914
914
|
console.log(" (the shape is correct either way — this is the VALUE a state diff cannot know)");
|
|
915
915
|
}
|
|
916
|
-
},
|
|
916
|
+
}, Wt = async (e, t) => {
|
|
917
917
|
if (W() !== "postgres") return;
|
|
918
|
-
let n =
|
|
918
|
+
let n = he, r;
|
|
919
919
|
try {
|
|
920
920
|
r = await J(t, M.SqlClient.pipe(j.flatMap((t) => m(t, e, n))));
|
|
921
921
|
} catch {
|
|
@@ -933,39 +933,65 @@ var Pe = (e) => typeof e != "string", Fe = (e, t, n, r) => {
|
|
|
933
933
|
});
|
|
934
934
|
}, X = (e) => {
|
|
935
935
|
let t = e.summary, n = e.operations.length;
|
|
936
|
+
if (k() === "json") {
|
|
937
|
+
B.info(`schema diff: ${n} operation${n === 1 ? "" : "s"}, ${t.blocked} blocked${n === 0 ? " — schema is up to date" : ""}`, {
|
|
938
|
+
operations: n,
|
|
939
|
+
blocked: t.blocked,
|
|
940
|
+
safe: t.safe,
|
|
941
|
+
needsDefault: t.needsDefault,
|
|
942
|
+
needsBackfill: t.needsBackfill,
|
|
943
|
+
rename: t.needsRenameAnnotation,
|
|
944
|
+
lossy: t.lossy,
|
|
945
|
+
ops: e.operations.map((e) => Ht(e).trim()),
|
|
946
|
+
fingerprintLive: e.fromFingerprint.slice(0, 16),
|
|
947
|
+
fingerprintDeclared: e.toFingerprint.slice(0, 16)
|
|
948
|
+
}), Gt(e);
|
|
949
|
+
return;
|
|
950
|
+
}
|
|
936
951
|
if (console.log(`\nschema diff: ${n} operation${n === 1 ? "" : "s"}, ${t.blocked} blocked\n`), n === 0) {
|
|
937
952
|
console.log(" (schema is up to date)\n");
|
|
938
953
|
return;
|
|
939
954
|
}
|
|
940
|
-
for (let t of e.operations) console.log(
|
|
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: live ${e.fromFingerprint.slice(0, 16)} · declared ${e.toFingerprint.slice(0, 16)}`), console.log(" (measured differently — a live hash never equals a declared one. The plan above is"), console.log(" what says whether they agree; these two are not meant to match.)\n"),
|
|
942
|
-
},
|
|
943
|
-
let t =
|
|
955
|
+
for (let t of e.operations) console.log(Ht(t));
|
|
956
|
+
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: live ${e.fromFingerprint.slice(0, 16)} · declared ${e.toFingerprint.slice(0, 16)}`), console.log(" (measured differently — a live hash never equals a declared one. The plan above is"), console.log(" what says whether they agree; these two are not meant to match.)\n"), Gt(e);
|
|
957
|
+
}, Gt = (e) => {
|
|
958
|
+
let t = Oe(e.operations);
|
|
944
959
|
if (t.length !== 0) {
|
|
960
|
+
if (k() === "json") {
|
|
961
|
+
B.warn(`${t.length} operation(s) UNSAFE under a rolling deploy — old code breaks against the new schema`, {
|
|
962
|
+
unsafe: t.map((e) => ({
|
|
963
|
+
kind: e.op.op.kind,
|
|
964
|
+
reason: e.reason,
|
|
965
|
+
remedy: e.remedy
|
|
966
|
+
})),
|
|
967
|
+
hint: "deploy with a maintenance window / scale-to-zero, or split expand → deploy → contract (docs: deployment/production-hardening)"
|
|
968
|
+
});
|
|
969
|
+
return;
|
|
970
|
+
}
|
|
945
971
|
console.log(` ⚠ ${t.length} operation(s) UNSAFE under a rolling deploy`), console.log(" (old + new instances overlap → old code breaks against the new schema):");
|
|
946
972
|
for (let e of t) console.log(` • ${e.op.op.kind}: ${e.reason}`), console.log(` → ${e.remedy}`);
|
|
947
973
|
console.log(" Deploy with a maintenance window / scale-to-zero, or split into"), console.log(" expand → deploy → contract. See docs: deployment/production-hardening.\n");
|
|
948
974
|
}
|
|
949
|
-
},
|
|
950
|
-
let n =
|
|
975
|
+
}, Kt = (e, t) => {
|
|
976
|
+
let n = ve({
|
|
951
977
|
enabled: process.env.VOLTRO_ROLLING_DEPLOY === "1",
|
|
952
978
|
forced: t.includes("--force"),
|
|
953
|
-
unsafeCount:
|
|
979
|
+
unsafeCount: Oe(e.operations).length
|
|
954
980
|
});
|
|
955
981
|
return n.refuse ? (B.error(`db apply: ${n.message}`), !0) : (n.warnForced && B.warn(`db apply: ${n.message}`), !1);
|
|
956
|
-
},
|
|
982
|
+
}, qt = (e) => {
|
|
957
983
|
let t = s(e, "--online-after") ?? process.env.VOLTRO_ONLINE_THRESHOLD;
|
|
958
984
|
if (t === void 0) return;
|
|
959
985
|
let n = Number(t);
|
|
960
986
|
if (!Number.isInteger(n) || n < 0) throw Error(`--online-after / VOLTRO_ONLINE_THRESHOLD must be a non-negative integer, got "${t}"`);
|
|
961
987
|
return n;
|
|
962
988
|
}, Z = async (e) => {
|
|
963
|
-
let t = await
|
|
989
|
+
let t = await Lt(e);
|
|
964
990
|
if (t.length === 0) return;
|
|
965
991
|
let n = await _({ root: e });
|
|
966
|
-
return
|
|
992
|
+
return Rt(zt([
|
|
967
993
|
...t,
|
|
968
|
-
...
|
|
994
|
+
...oe,
|
|
969
995
|
...n
|
|
970
996
|
]));
|
|
971
997
|
}, Q = async (e, t, n) => {
|
|
@@ -978,20 +1004,20 @@ var Pe = (e) => typeof e != "string", Fe = (e, t, n, r) => {
|
|
|
978
1004
|
} catch (e) {
|
|
979
1005
|
r = e;
|
|
980
1006
|
}
|
|
981
|
-
return await
|
|
982
|
-
},
|
|
983
|
-
let n = { close: async () => {} }, r = await V(e,
|
|
1007
|
+
return await Wt(t, n), r === void 0 ? 0 : (B.error("db apply: a plugin migration FAILED — the schema was applied, the plugin steps were not", { error: r instanceof Error ? r.message : String(r) }), 1);
|
|
1008
|
+
}, Jt = async (e, t) => {
|
|
1009
|
+
let n = { close: async () => {} }, r = await V(e, y);
|
|
984
1010
|
if (r.length === 0) return n;
|
|
985
1011
|
let i = await f(r, B), a = i.filter((e) => e.definition.lifecycle === "onSchemaChange");
|
|
986
1012
|
if (a.length === 0) return n;
|
|
987
|
-
let { store: o, dispose: s } = await
|
|
1013
|
+
let { store: o, dispose: s } = await Pt(t), c = h(i, o, B.child("seeds"));
|
|
988
1014
|
return B.info(`db apply: ${a.length} onSchemaChange seed(s) armed for this apply`, { ids: a.map((e) => e.definition.id) }), { close: async () => {
|
|
989
1015
|
c(), await s().catch((e) => {
|
|
990
1016
|
B.warn("db apply: seed store dispose failed", { error: String(e) });
|
|
991
1017
|
});
|
|
992
1018
|
} };
|
|
993
|
-
},
|
|
994
|
-
let t =
|
|
1019
|
+
}, Yt = async (e) => {
|
|
1020
|
+
let t = qt(e), n = H(e), r = await Z(n);
|
|
995
1021
|
if (r === void 0) return B.warn("db plan: no schema files found", {
|
|
996
1022
|
root: n,
|
|
997
1023
|
hint: "looked for *.entity.ts / *.schema.ts / schema.ts"
|
|
@@ -1025,7 +1051,7 @@ var Pe = (e) => typeof e != "string", Fe = (e, t, n, r) => {
|
|
|
1025
1051
|
...t === void 0 ? {} : { onlineAfter: t }
|
|
1026
1052
|
});
|
|
1027
1053
|
return e.includes("--json") ? (te(1, `${JSON.stringify(o, null, 2)}\n`), o.summary.blocked > 0 ? 2 : 0) : (X(o), o.summary.blocked > 0 ? 2 : 0);
|
|
1028
|
-
}, $ = n,
|
|
1054
|
+
}, $ = n, Xt = async (e, t, n) => {
|
|
1029
1055
|
let r;
|
|
1030
1056
|
try {
|
|
1031
1057
|
let t = await E.readFile(T(e), "utf8");
|
|
@@ -1036,21 +1062,33 @@ var Pe = (e) => typeof e != "string", Fe = (e, t, n, r) => {
|
|
|
1036
1062
|
if (!Array.isArray(r?.operations) || typeof r?.fromFingerprint != "string" || typeof r?.toFingerprint != "string") return B.error(`db apply --plan: '${e}' is not a valid plan file (expected the output of \`voltro db plan --json\`).`), 1;
|
|
1037
1063
|
let i = await Z(n);
|
|
1038
1064
|
if (i === void 0) return B.warn("db apply --plan: no schema files found", { root: n }), 1;
|
|
1039
|
-
let a = await q(), o = await J(a, M.SqlClient.pipe(j.flatMap((e) =>
|
|
1040
|
-
if (o.length > 0) return B.error(`db apply --plan: refusing — ${o.length} pending file-based migration(s)
|
|
1065
|
+
let a = await q(), o = await J(a, M.SqlClient.pipe(j.flatMap((e) => we(e, n)))).catch(() => []);
|
|
1066
|
+
if (o.length > 0) return B.error(`db apply --plan: refusing — ${o.length} pending file-based migration(s).`, {
|
|
1067
|
+
pending: o,
|
|
1068
|
+
why: "file migrations perform changes a state diff cannot infer, so they change the shape this plan was computed against",
|
|
1069
|
+
fix: "voltro db files . && voltro db plan --json > plan.json && voltro db apply --plan plan.json"
|
|
1070
|
+
}), 1;
|
|
1041
1071
|
let c = await Y(a), l = F({
|
|
1042
1072
|
declared: i,
|
|
1043
1073
|
live: c,
|
|
1044
1074
|
dialect: W(),
|
|
1045
1075
|
...N()
|
|
1046
1076
|
});
|
|
1047
|
-
if (l.fromFingerprint !== r.fromFingerprint) return B.error("db apply --plan: refusing — the live schema has drifted since this plan was generated."
|
|
1048
|
-
|
|
1049
|
-
|
|
1077
|
+
if (l.fromFingerprint !== r.fromFingerprint) return B.error("db apply --plan: refusing — the live schema has drifted since this plan was generated.", {
|
|
1078
|
+
planFrom: r.fromFingerprint.slice(0, 16),
|
|
1079
|
+
live: l.fromFingerprint.slice(0, 16),
|
|
1080
|
+
fix: "regenerate against the current live schema: voltro db plan --json > plan.json"
|
|
1081
|
+
}), 2;
|
|
1082
|
+
if (l.toFingerprint !== r.toFingerprint) return B.error("db apply --plan: refusing — the declared schema differs from what this plan targets.", {
|
|
1083
|
+
planTo: r.toFingerprint.slice(0, 16),
|
|
1084
|
+
declared: l.toFingerprint.slice(0, 16),
|
|
1085
|
+
fix: "the schema files changed since the plan was generated — regenerate the plan"
|
|
1086
|
+
}), 2;
|
|
1087
|
+
let u = Bt(l), d = u.plan;
|
|
1050
1088
|
if (d.summary.blocked > 0 && !u.acknowledged) return X(d), B.error(`db apply --plan: refusing — ${l.summary.blocked} blocked operation(s). See the fix hints above.`), process.env.VOLTRO_DESTRUCTIVE_OK !== void 0 && (B.error(" VOLTRO_DESTRUCTIVE_OK is set but did not cover this plan — it only relaxes"), B.error(" `lossy` operations, and only the tables it names. Anything else stays refused.")), 2;
|
|
1051
|
-
if (u.acknowledged && B.warn("db apply --plan: proceeding with acknowledged lossy operation(s) (VOLTRO_DESTRUCTIVE_OK)"),
|
|
1089
|
+
if (u.acknowledged && B.warn("db apply --plan: proceeding with acknowledged lossy operation(s) (VOLTRO_DESTRUCTIVE_OK)"), Kt(d, t)) return 2;
|
|
1052
1090
|
if (d.operations.length === 0) {
|
|
1053
|
-
let e = await J(a, M.SqlClient.pipe(j.flatMap((e) =>
|
|
1091
|
+
let e = await J(a, M.SqlClient.pipe(j.flatMap((e) => Te(e, d, {
|
|
1054
1092
|
appliedBy: process.env.USER ? `cli:${process.env.USER}` : "cli:plan",
|
|
1055
1093
|
environment: $(),
|
|
1056
1094
|
source: "file"
|
|
@@ -1058,7 +1096,7 @@ var Pe = (e) => typeof e != "string", Fe = (e, t, n, r) => {
|
|
|
1058
1096
|
return B.info(e === "recorded" ? `db apply --plan: schema is up to date — no DDL to apply, recorded fingerprint=${d.toFingerprint.slice(0, 16)} (change triggers are reconciled separately below)` : "db apply --plan: schema is up to date — no DDL to apply (change triggers are reconciled separately below)"), Q(n, i, a);
|
|
1059
1097
|
}
|
|
1060
1098
|
X(d);
|
|
1061
|
-
let f = s(t, "--note"), p = await J(a, M.SqlClient.pipe(j.flatMap((e) =>
|
|
1099
|
+
let f = s(t, "--note"), p = await J(a, M.SqlClient.pipe(j.flatMap((e) => ge(e, d, {
|
|
1062
1100
|
declared: i,
|
|
1063
1101
|
appliedBy: process.env.USER ? `cli:${process.env.USER}` : "cli:plan",
|
|
1064
1102
|
environment: $(),
|
|
@@ -1075,21 +1113,24 @@ var Pe = (e) => typeof e != "string", Fe = (e, t, n, r) => {
|
|
|
1075
1113
|
id: p.id,
|
|
1076
1114
|
fingerprint: p.fingerprint.slice(0, 16)
|
|
1077
1115
|
}), Q(n, i, a);
|
|
1078
|
-
},
|
|
1079
|
-
let t = H(e), n = await
|
|
1116
|
+
}, Zt = async (e) => {
|
|
1117
|
+
let t = H(e), n = await Jt(t, e);
|
|
1080
1118
|
try {
|
|
1081
|
-
return await
|
|
1119
|
+
return await Qt(e, t);
|
|
1082
1120
|
} finally {
|
|
1083
1121
|
await n.close();
|
|
1084
1122
|
}
|
|
1085
|
-
},
|
|
1086
|
-
let r =
|
|
1087
|
-
if (i) return
|
|
1088
|
-
if ((process.env.NODE_ENV ?? "").toLowerCase() === "production") return B.error(`voltro db apply: refusing — auto-apply on prod is not allowed.${t()}
|
|
1123
|
+
}, Qt = async (e, n) => {
|
|
1124
|
+
let r = qt(e), i = s(e, "--plan");
|
|
1125
|
+
if (i) return Xt(i, e, n);
|
|
1126
|
+
if ((process.env.NODE_ENV ?? "").toLowerCase() === "production") return B.error(`voltro db apply: refusing — auto-apply on prod is not allowed.${t()}`, { fix: "in production, schema changes go through `voltro db plan --json > plan.json`, then `voltro db apply --plan plan.json` as an explicit deploy step" }), 3;
|
|
1089
1127
|
let a = await Z(n);
|
|
1090
1128
|
if (a === void 0) return B.warn("db apply: no schema files found", { root: n }), 1;
|
|
1091
|
-
let o = await q(), c = await
|
|
1092
|
-
if ("failed" in c) return B.error("db apply: a file-based migration FAILED — the schema diff was NOT run"
|
|
1129
|
+
let o = await q(), c = await hn(n, o);
|
|
1130
|
+
if ("failed" in c) return B.error("db apply: a file-based migration FAILED — the schema diff was NOT run", {
|
|
1131
|
+
failed: c.failed,
|
|
1132
|
+
fix: "fix the migration and re-run; `voltro db files` runs them alone"
|
|
1133
|
+
}), 1;
|
|
1093
1134
|
let l = await Y(o), u = F({
|
|
1094
1135
|
declared: a,
|
|
1095
1136
|
live: l,
|
|
@@ -1097,20 +1138,20 @@ var Pe = (e) => typeof e != "string", Fe = (e, t, n, r) => {
|
|
|
1097
1138
|
...N(),
|
|
1098
1139
|
...r === void 0 ? {} : { onlineAfter: r }
|
|
1099
1140
|
});
|
|
1100
|
-
X(u), await
|
|
1101
|
-
let d =
|
|
1141
|
+
X(u), await Ut(u, o);
|
|
1142
|
+
let d = Bt(u), f = d.plan;
|
|
1102
1143
|
if (f.summary.blocked > 0 && !d.acknowledged) return B.error(`db apply: refusing — ${f.summary.blocked} blocked operation(s). See the fix hints above.`), process.env.VOLTRO_DESTRUCTIVE_OK !== void 0 && (B.error(" VOLTRO_DESTRUCTIVE_OK is set but did not cover this plan — it only relaxes"), B.error(" `lossy` operations, and only the tables it names. Anything else stays refused.")), 2;
|
|
1103
|
-
if (d.acknowledged && B.warn(`db apply: proceeding with ${u.summary.blocked} acknowledged lossy operation(s) (VOLTRO_DESTRUCTIVE_OK)`),
|
|
1144
|
+
if (d.acknowledged && B.warn(`db apply: proceeding with ${u.summary.blocked} acknowledged lossy operation(s) (VOLTRO_DESTRUCTIVE_OK)`), Kt(f, e)) return 2;
|
|
1104
1145
|
if (f.operations.length === 0) {
|
|
1105
1146
|
B.info("db apply: schema is up to date — no DDL to apply (change triggers are reconciled separately below)");
|
|
1106
|
-
let t = await J(o, M.SqlClient.pipe(j.flatMap((e) =>
|
|
1147
|
+
let t = await J(o, M.SqlClient.pipe(j.flatMap((e) => Te(e, f, {
|
|
1107
1148
|
appliedBy: process.env.USER ? `cli:${process.env.USER}` : "cli:apply",
|
|
1108
1149
|
environment: $(),
|
|
1109
1150
|
source: "auto-diff"
|
|
1110
1151
|
}))));
|
|
1111
|
-
return t === "recorded" && B.info(`db apply: recorded fingerprint=${f.toFingerprint.slice(0, 16)} (0 operations)`), await
|
|
1152
|
+
return t === "recorded" && B.info(`db apply: recorded fingerprint=${f.toFingerprint.slice(0, 16)} (0 operations)`), await un(o), s(e, "--note") !== void 0 && t !== "recorded" && B.warn("db apply: --note was ignored — this schema is already the latest recorded one, so there is no new history row to attach it to.", { hint: "to record the CURRENT live schema as the accepted baseline, use `voltro db drift --accept`" }), Q(n, a, o);
|
|
1112
1153
|
}
|
|
1113
|
-
let p = s(e, "--note"), m = await J(o, M.SqlClient.pipe(j.flatMap((e) =>
|
|
1154
|
+
let p = s(e, "--note"), m = await J(o, M.SqlClient.pipe(j.flatMap((e) => ge(e, f, {
|
|
1114
1155
|
declared: a,
|
|
1115
1156
|
appliedBy: process.env.USER ? `cli:${process.env.USER}` : "cli:user",
|
|
1116
1157
|
environment: $(),
|
|
@@ -1128,7 +1169,7 @@ var Pe = (e) => typeof e != "string", Fe = (e, t, n, r) => {
|
|
|
1128
1169
|
id: m.id,
|
|
1129
1170
|
fingerprint: m.fingerprint.slice(0, 16)
|
|
1130
1171
|
}), Q(n, a, o);
|
|
1131
|
-
},
|
|
1172
|
+
}, $t = (e) => {
|
|
1132
1173
|
let t = [];
|
|
1133
1174
|
for (let n of e.tables) for (let e of n.columns) {
|
|
1134
1175
|
let r = e.references;
|
|
@@ -1141,7 +1182,7 @@ var Pe = (e) => typeof e != "string", Fe = (e, t, n, r) => {
|
|
|
1141
1182
|
});
|
|
1142
1183
|
}
|
|
1143
1184
|
return t;
|
|
1144
|
-
},
|
|
1185
|
+
}, en = (e) => {
|
|
1145
1186
|
let t = [];
|
|
1146
1187
|
for (let n of e.tables) for (let e of n.indexes) e.expression !== !0 && e.name !== `${n.name}_pkey` && e.columns.length !== 0 && t.push({
|
|
1147
1188
|
table: n.name,
|
|
@@ -1150,7 +1191,7 @@ var Pe = (e) => typeof e != "string", Fe = (e, t, n, r) => {
|
|
|
1150
1191
|
name: e.name
|
|
1151
1192
|
});
|
|
1152
1193
|
return t;
|
|
1153
|
-
},
|
|
1194
|
+
}, tn = (e, t) => {
|
|
1154
1195
|
let n = (e) => JSON.stringify(e.op), r = new Set(e.operations.map(n)), i = new Set(t.operations.map(n)), a = [...t.operations.filter((e) => !r.has(n(e))), ...e.operations.filter((e) => !i.has(n(e)))];
|
|
1155
1196
|
return {
|
|
1156
1197
|
...t,
|
|
@@ -1160,24 +1201,24 @@ var Pe = (e) => typeof e != "string", Fe = (e, t, n, r) => {
|
|
|
1160
1201
|
blocked: 0
|
|
1161
1202
|
}
|
|
1162
1203
|
};
|
|
1163
|
-
},
|
|
1204
|
+
}, nn = (e) => {
|
|
1164
1205
|
if (e === void 0) return "empty";
|
|
1165
1206
|
if (e === "empty" || e === "copy") return e;
|
|
1166
1207
|
throw e === "fresh" ? new r("voltro db branch: --seed fresh is not implemented — the branch lifecycle has no executor step that runs boot seeds, so the branch would come up EMPTY while this reported it as seeded. Use --seed copy (the parent's rows) or --seed empty (schema only).") : new r(`voltro db branch: --seed must be one of empty|copy, got "${e}"`);
|
|
1167
|
-
},
|
|
1208
|
+
}, rn = (e) => {
|
|
1168
1209
|
if (e !== void 0) {
|
|
1169
1210
|
if (e === "namespace" || e === "neon-cow") return e;
|
|
1170
1211
|
throw new r(`voltro db branch: --prefer must be one of namespace|neon-cow, got "${e}"`);
|
|
1171
1212
|
}
|
|
1172
|
-
},
|
|
1173
|
-
let t = H(e), n =
|
|
1213
|
+
}, an = async (e) => {
|
|
1214
|
+
let t = H(e), n = nn(s(e, "--seed")), i = rn(s(e, "--prefer")), a = e.includes("--keep"), o = e.includes("--json"), c = qt(e), u = W();
|
|
1174
1215
|
if (u !== "postgres") return B.error(`voltro db branch: not supported on '${u}'.`), console.error(" The branch PLAN is dialect-agnostic; the shipped namespace EXECUTOR is Postgres-only"), console.error(" (CREATE SCHEMA / CREATE TABLE … LIKE … INCLUDING ALL / \"-quoted identifiers)."), console.error(" MySQL, MariaDB, SQLite and SQL Server need their own BranchExecutor — see"), console.error(" makeNamespaceBranchExecutor in @voltro/database."), 1;
|
|
1175
1216
|
let d = await Z(t);
|
|
1176
1217
|
if (d === void 0) return B.warn("db branch: no schema files found", {
|
|
1177
1218
|
root: t,
|
|
1178
1219
|
hint: "looked for *.entity.ts / *.schema.ts / schema.ts"
|
|
1179
1220
|
}), 1;
|
|
1180
|
-
let f = U(), p =
|
|
1221
|
+
let f = U(), p = pe({
|
|
1181
1222
|
seed: n,
|
|
1182
1223
|
...f.url === void 0 ? {} : { dbUrl: f.url },
|
|
1183
1224
|
...i === void 0 ? {} : { prefer: i }
|
|
@@ -1185,7 +1226,7 @@ var Pe = (e) => typeof e != "string", Fe = (e, t, n, r) => {
|
|
|
1185
1226
|
if (p === "neon-cow") return B.error("voltro db branch: this connection resolves to the Neon copy-on-write mechanism, which the CLI cannot execute."), console.error(" A Neon CoW branch is a single call to Neon's branch REST API and needs a Neon API token;"), console.error(" the framework ships the PLAN, and the cloud control plane executes it."), console.error(" Re-run with `--prefer namespace` to rehearse on a schema-per-branch copy instead"), console.error(` (portable, no vendor API — it copies ${n === "copy" ? "every row" : "the schema only"}).`), 1;
|
|
1186
1227
|
let m = f.schema ?? "public", h = s(e, "--name") ?? ee(t), g = s(e, "--pr"), _ = g === void 0 ? 0 : Number(g);
|
|
1187
1228
|
if (!Number.isInteger(_) || _ < 0) throw new r(`voltro db branch: --pr must be a non-negative integer, got "${String(g)}"`);
|
|
1188
|
-
let v =
|
|
1229
|
+
let v = re(h, _), y = await l(u), b = y.makeSqlLayer(f), x = y.makeSqlLayer({
|
|
1189
1230
|
...f,
|
|
1190
1231
|
schema: v
|
|
1191
1232
|
}), S = await Y(b), C = F({
|
|
@@ -1194,13 +1235,13 @@ var Pe = (e) => typeof e != "string", Fe = (e, t, n, r) => {
|
|
|
1194
1235
|
dialect: u,
|
|
1195
1236
|
...N(),
|
|
1196
1237
|
...c === void 0 ? {} : { onlineAfter: c }
|
|
1197
|
-
}), w = S.tables.map((e) => e.name), T =
|
|
1238
|
+
}), w = S.tables.map((e) => e.name), T = $t(S), E = en(S), D = le({ run: (e) => J(b, M.SqlClient.pipe(j.flatMap((t) => t.unsafe(e)), j.asVoid)) }), O = async () => F({
|
|
1198
1239
|
declared: d,
|
|
1199
1240
|
live: await Y(x),
|
|
1200
1241
|
dialect: u,
|
|
1201
1242
|
...N(),
|
|
1202
1243
|
...c === void 0 ? {} : { onlineAfter: c }
|
|
1203
|
-
}), k = await
|
|
1244
|
+
}), k = await Ee({
|
|
1204
1245
|
branchId: v,
|
|
1205
1246
|
mechanism: p,
|
|
1206
1247
|
branchedTables: w.length,
|
|
@@ -1210,7 +1251,7 @@ var Pe = (e) => typeof e != "string", Fe = (e, t, n, r) => {
|
|
|
1210
1251
|
o || B.info(`db branch: ${e}`);
|
|
1211
1252
|
},
|
|
1212
1253
|
provision: async () => {
|
|
1213
|
-
await
|
|
1254
|
+
await ue({
|
|
1214
1255
|
appSlug: h,
|
|
1215
1256
|
prNumber: _,
|
|
1216
1257
|
seed: n,
|
|
@@ -1222,10 +1263,10 @@ var Pe = (e) => typeof e != "string", Fe = (e, t, n, r) => {
|
|
|
1222
1263
|
...f.url === void 0 ? {} : { dbUrl: f.url }
|
|
1223
1264
|
}, D);
|
|
1224
1265
|
},
|
|
1225
|
-
fidelityPlan: async () =>
|
|
1266
|
+
fidelityPlan: async () => tn(C, await O()),
|
|
1226
1267
|
plan: O,
|
|
1227
1268
|
apply: async (e) => {
|
|
1228
|
-
await J(x, M.SqlClient.pipe(j.flatMap((t) =>
|
|
1269
|
+
await J(x, M.SqlClient.pipe(j.flatMap((t) => ge(t, e, {
|
|
1229
1270
|
declared: d,
|
|
1230
1271
|
appliedBy: "cli:db-branch",
|
|
1231
1272
|
environment: $(),
|
|
@@ -1236,11 +1277,11 @@ var Pe = (e) => typeof e != "string", Fe = (e, t, n, r) => {
|
|
|
1236
1277
|
},
|
|
1237
1278
|
replan: async () => await O(),
|
|
1238
1279
|
teardown: async () => {
|
|
1239
|
-
await
|
|
1280
|
+
await me(v, "namespace", D);
|
|
1240
1281
|
}
|
|
1241
1282
|
});
|
|
1242
|
-
return o ? te(1, `${JSON.stringify(k, null, 2)}\n`) : console.log(`\n${
|
|
1243
|
-
},
|
|
1283
|
+
return o ? te(1, `${JSON.stringify(k, null, 2)}\n`) : console.log(`\n${Ce(k)}\n`), ye(k);
|
|
1284
|
+
}, on = async (e) => {
|
|
1244
1285
|
let t = Math.max(1, Number(s(e, "--limit") ?? "20")), n = await J(await q(), M.SqlClient.pipe(j.flatMap((e) => e`
|
|
1245
1286
|
SELECT ${e("id")}, ${e("fingerprint")}, ${e("operations")},
|
|
1246
1287
|
${e("appliedBy")}, ${e("environment")}, ${e("source")},
|
|
@@ -1254,12 +1295,12 @@ var Pe = (e) => typeof e != "string", Fe = (e, t, n, r) => {
|
|
|
1254
1295
|
for (let e of n) {
|
|
1255
1296
|
let t = 0;
|
|
1256
1297
|
try {
|
|
1257
|
-
t = JSON.parse(
|
|
1298
|
+
t = JSON.parse(dn(e.operations)).length;
|
|
1258
1299
|
} catch {}
|
|
1259
|
-
console.log(` ${e.id} fp=${I(e.fingerprint)} env=${e.environment} src=${e.source} ${t} op(s) ${e.durationMs}ms ${
|
|
1300
|
+
console.log(` ${e.id} fp=${I(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`);
|
|
1260
1301
|
}
|
|
1261
1302
|
return console.log(), 0;
|
|
1262
|
-
},
|
|
1303
|
+
}, sn = async (e) => {
|
|
1263
1304
|
let t = e[0];
|
|
1264
1305
|
if (!t) return console.error("voltro db restore-snapshot <plan-id>"), console.error(" Renames soft-dropped columns/tables from a plan back to their original names."), console.error(" Requires the plan to have been applied with VOLTRO_SOFT_DROP=1."), 2;
|
|
1265
1306
|
let n = await q(), r = await J(n, M.SqlClient.pipe(j.flatMap((e) => e`SELECT ${e("id")}, ${e("operations")}
|
|
@@ -1267,7 +1308,7 @@ var Pe = (e) => typeof e != "string", Fe = (e, t, n, r) => {
|
|
|
1267
1308
|
if (r.length === 0) return console.error(`restore-snapshot: plan '${t}' not found`), 1;
|
|
1268
1309
|
let i;
|
|
1269
1310
|
try {
|
|
1270
|
-
i = JSON.parse(
|
|
1311
|
+
i = JSON.parse(dn(r[0].operations));
|
|
1271
1312
|
} catch {
|
|
1272
1313
|
return console.error(`restore-snapshot: plan '${t}' has corrupted operations JSON`), 1;
|
|
1273
1314
|
}
|
|
@@ -1311,7 +1352,7 @@ var Pe = (e) => typeof e != "string", Fe = (e, t, n, r) => {
|
|
|
1311
1352
|
await J(n, M.SqlClient.pipe(j.flatMap((t) => t.unsafe(`ALTER TABLE ${G(r)} RENAME TO ${G(e.table)}`)))), c++, console.log(` ↩ restored table ${e.table} (from ${r})`);
|
|
1312
1353
|
}
|
|
1313
1354
|
return console.log(`\n✓ restored ${s} column(s) + ${c} table(s) from plan '${t}'\n`), 0;
|
|
1314
|
-
},
|
|
1355
|
+
}, cn = async (e) => {
|
|
1315
1356
|
let t = s(e, "--before");
|
|
1316
1357
|
if (!t) return console.error("voltro db gc-snapshots --before <date> [--dry-run]"), console.error(" Permanently drops soft-dropped columns/tables (<name>__dropped_<ts>) older than <date>."), console.error(" <date> is ISO — e.g. 2026-01-01 or 2026-01-01T00:00:00Z. NOT reversible."), 2;
|
|
1317
1358
|
let n = t.replace(/[^0-9]/g, "");
|
|
@@ -1335,16 +1376,16 @@ var Pe = (e) => typeof e != "string", Fe = (e, t, n, r) => {
|
|
|
1335
1376
|
t === null || t >= r || (console.log(` ${i ? "[dry-run] would drop table" : "dropping table"} ${e.table_name}`), i || await J(a, M.SqlClient.pipe(j.flatMap((t) => t.unsafe(`DROP TABLE ${G(e.table_name)}`)))), u++);
|
|
1336
1377
|
}
|
|
1337
1378
|
return console.log(`\n${i ? `[dry-run] ${u} snapshot(s) would be dropped` : `✓ dropped ${u} snapshot(s)`} (older than ${r}).\n`), 0;
|
|
1338
|
-
},
|
|
1379
|
+
}, ln = async (e) => {
|
|
1339
1380
|
let t = s(e, "--before");
|
|
1340
1381
|
if (!t) return console.error("voltro db squash --before <iso-date> [--note \"<text>\"]"), 2;
|
|
1341
1382
|
let n = t;
|
|
1342
1383
|
if (Number.isNaN(new Date(n).getTime())) return console.error(`voltro db squash: --before '${n}' is not a valid ISO date`), 2;
|
|
1343
1384
|
let r = s(e, "--note"), i = H(e), a = await Z(i);
|
|
1344
1385
|
if (a === void 0) return B.warn("db squash: no schema files found", { root: i }), 1;
|
|
1345
|
-
let o =
|
|
1386
|
+
let o = Se(be(a)), c = await q();
|
|
1346
1387
|
try {
|
|
1347
|
-
let e = await J(c,
|
|
1388
|
+
let e = await J(c, Ae({
|
|
1348
1389
|
before: n,
|
|
1349
1390
|
fingerprint: o,
|
|
1350
1391
|
appliedBy: process.env.USER ?? "cli",
|
|
@@ -1355,9 +1396,9 @@ var Pe = (e) => typeof e != "string", Fe = (e, t, n, r) => {
|
|
|
1355
1396
|
} catch (e) {
|
|
1356
1397
|
return console.error(`squash refused: ${e.message}`), 1;
|
|
1357
1398
|
}
|
|
1358
|
-
},
|
|
1399
|
+
}, un = async (e) => {
|
|
1359
1400
|
try {
|
|
1360
|
-
let t = await Y(e), n =
|
|
1401
|
+
let t = await Y(e), n = Se(t);
|
|
1361
1402
|
await J(e, M.SqlClient.pipe(j.flatMap((e) => e`
|
|
1362
1403
|
UPDATE ${e("_voltro_migration_plans")}
|
|
1363
1404
|
SET ${e("liveFingerprint")} = ${n}
|
|
@@ -1370,7 +1411,7 @@ var Pe = (e) => typeof e != "string", Fe = (e, t, n, r) => {
|
|
|
1370
1411
|
AND ${e("liveFingerprint")} IS NULL
|
|
1371
1412
|
`)));
|
|
1372
1413
|
} catch {}
|
|
1373
|
-
},
|
|
1414
|
+
}, 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 ? {
|
|
1374
1415
|
accept: !1,
|
|
1375
1416
|
reason: "no-declared-schema"
|
|
1376
1417
|
} : e > 0 ? {
|
|
@@ -1379,15 +1420,15 @@ var Pe = (e) => typeof e != "string", Fe = (e, t, n, r) => {
|
|
|
1379
1420
|
} : {
|
|
1380
1421
|
accept: !0,
|
|
1381
1422
|
reason: "converged"
|
|
1382
|
-
},
|
|
1423
|
+
}, mn = async (e) => {
|
|
1383
1424
|
let t = e.includes("--accept"), n = await q(), r = await J(n, M.SqlClient.pipe(j.flatMap((e) => e`
|
|
1384
1425
|
SELECT * FROM ${e("_voltro_migration_plans")}
|
|
1385
1426
|
ORDER BY ${e("appliedAt")} DESC
|
|
1386
1427
|
LIMIT 1
|
|
1387
|
-
`))), i = await Y(n), a =
|
|
1428
|
+
`))), i = await Y(n), a = Se(i);
|
|
1388
1429
|
if (r.length === 0) return B.info("db drift: no _voltro_migration_plans rows yet"), console.log(`live user-schema fingerprint: ${I(a)}`), console.log("No baseline to compare against. Run `voltro db apply` to lock in the current state."), 0;
|
|
1389
1430
|
let o = r[0];
|
|
1390
|
-
if (o.liveFingerprint === null || o.liveFingerprint === void 0) return B.warn("db drift: no drift baseline recorded yet — cannot compare"), console.log(), console.log(` last applied: ${o.id} at ${
|
|
1431
|
+
if (o.liveFingerprint === null || o.liveFingerprint === void 0) return B.warn("db drift: no drift baseline recorded yet — cannot compare"), console.log(), console.log(` last applied: ${o.id} at ${fn(o.appliedAt)}`), console.log(` live now: ${I(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
1432
|
if (o.liveFingerprint === a) return B.info(`db drift: live matches last applied (${I(a)})`), 0;
|
|
1392
1433
|
let s = await (async () => {
|
|
1393
1434
|
try {
|
|
@@ -1403,7 +1444,7 @@ var Pe = (e) => typeof e != "string", Fe = (e, t, n, r) => {
|
|
|
1403
1444
|
}
|
|
1404
1445
|
})();
|
|
1405
1446
|
if (t) {
|
|
1406
|
-
let e =
|
|
1447
|
+
let e = pn(s?.length);
|
|
1407
1448
|
if (e.reason === "no-declared-schema") return B.error("db drift --accept: no schema files found — cannot verify the live schema is current."), 1;
|
|
1408
1449
|
if (!e.accept && s !== void 0) {
|
|
1409
1450
|
B.error(`db drift --accept: refusing — ${s.length} operation(s) still pending against your declared schema.`), console.log();
|
|
@@ -1421,11 +1462,11 @@ var Pe = (e) => typeof e != "string", Fe = (e, t, n, r) => {
|
|
|
1421
1462
|
)
|
|
1422
1463
|
`))), B.info(`db drift: accepted the live schema as the baseline (${I(a)})`), console.log(), console.log("`voltro db plan` reports 0 operations against this schema, so the live state already"), console.log("matches your declaration — only the ledger did not know. It does now."), console.log(), console.log("No history entry was invented: the latest row's baseline was updated in place,"), console.log("because no migration ran."), 0;
|
|
1423
1464
|
}
|
|
1424
|
-
return B.error("db drift: live schema DIVERGED from last applied state"), console.log(), console.log(` baseline: ${I(o.liveFingerprint)} at ${
|
|
1425
|
-
},
|
|
1465
|
+
return B.error("db drift: live schema DIVERGED from last applied state"), console.log(), console.log(` baseline: ${I(o.liveFingerprint)} at ${fn(o.appliedAt)} (${o.id})`), console.log(` live now: ${I(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);
|
|
1466
|
+
}, hn = async (e, t) => {
|
|
1426
1467
|
let n = $();
|
|
1427
1468
|
try {
|
|
1428
|
-
let r = await J(t, M.SqlClient.pipe(j.flatMap((t) =>
|
|
1469
|
+
let r = await J(t, M.SqlClient.pipe(j.flatMap((t) => ke(t, {
|
|
1429
1470
|
projectRoot: e,
|
|
1430
1471
|
env: n,
|
|
1431
1472
|
appliedBy: process.env.USER ? `cli:${process.env.USER}` : "cli:user"
|
|
@@ -1434,10 +1475,10 @@ var Pe = (e) => typeof e != "string", Fe = (e, t, n, r) => {
|
|
|
1434
1475
|
} catch (e) {
|
|
1435
1476
|
return { failed: e };
|
|
1436
1477
|
}
|
|
1437
|
-
},
|
|
1478
|
+
}, gn = async (e) => {
|
|
1438
1479
|
let t = H(e), n = await q(), r = $();
|
|
1439
|
-
await J(n,
|
|
1440
|
-
let i = await J(n, M.SqlClient.pipe(j.flatMap((e) =>
|
|
1480
|
+
await J(n, _e(oe, W(), void 0, { retryFilter: (await l(W())).retryFilter }));
|
|
1481
|
+
let i = await J(n, M.SqlClient.pipe(j.flatMap((e) => ke(e, {
|
|
1441
1482
|
projectRoot: t,
|
|
1442
1483
|
env: r,
|
|
1443
1484
|
appliedBy: process.env.USER ? `cli:${process.env.USER}` : "cli:user"
|
|
@@ -1446,16 +1487,16 @@ var Pe = (e) => typeof e != "string", Fe = (e, t, n, r) => {
|
|
|
1446
1487
|
applied: i.applied.map((e) => `${e.id} (${e.durationMs}ms)`),
|
|
1447
1488
|
skipped: i.skipped.length
|
|
1448
1489
|
}), 0);
|
|
1449
|
-
},
|
|
1450
|
-
let n = H(e), r = c(e,
|
|
1490
|
+
}, _n = async (e) => {
|
|
1491
|
+
let n = H(e), r = c(e, Ot);
|
|
1451
1492
|
if (!r) return B.error("voltro db rollback-file <migration-id>"), 2;
|
|
1452
1493
|
if ((process.env.NODE_ENV ?? "").toLowerCase() === "production") return B.error("voltro db rollback-file: refusing on prod — schema rollback runs as an explicit deploy step." + t()), 3;
|
|
1453
|
-
let i = await J(await q(), M.SqlClient.pipe(j.flatMap((e) =>
|
|
1494
|
+
let i = await J(await q(), M.SqlClient.pipe(j.flatMap((e) => De(e, {
|
|
1454
1495
|
projectRoot: n,
|
|
1455
1496
|
id: r
|
|
1456
1497
|
}))));
|
|
1457
1498
|
return B.info(`db rollback-file: rolled back ${i.id} in ${i.durationMs}ms`), 0;
|
|
1458
|
-
},
|
|
1499
|
+
}, vn = () => {
|
|
1459
1500
|
let e = /* @__PURE__ */ new Date();
|
|
1460
1501
|
return [
|
|
1461
1502
|
e.getUTCFullYear(),
|
|
@@ -1465,7 +1506,7 @@ var Pe = (e) => typeof e != "string", Fe = (e, t, n, r) => {
|
|
|
1465
1506
|
String(e.getUTCMinutes()).padStart(2, "0"),
|
|
1466
1507
|
String(e.getUTCSeconds()).padStart(2, "0")
|
|
1467
1508
|
].join("");
|
|
1468
|
-
},
|
|
1509
|
+
}, yn = (e) => e.trim().toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "") || "migration", bn = (e, t) => `import { defineMigration, SqlClient } from '@voltro/database'
|
|
1469
1510
|
import { Effect } from 'effect'
|
|
1470
1511
|
|
|
1471
1512
|
// A hand-written migration. Reach for this when the DECLARATIVE differ can't
|
|
@@ -1497,25 +1538,25 @@ export default defineMigration({
|
|
|
1497
1538
|
}),
|
|
1498
1539
|
],
|
|
1499
1540
|
})
|
|
1500
|
-
`,
|
|
1501
|
-
plan:
|
|
1502
|
-
apply:
|
|
1503
|
-
branch:
|
|
1504
|
-
plans:
|
|
1505
|
-
drift:
|
|
1506
|
-
files:
|
|
1507
|
-
"rollback-file":
|
|
1508
|
-
migrate:
|
|
1509
|
-
rollback:
|
|
1510
|
-
status:
|
|
1511
|
-
seed:
|
|
1541
|
+
`, xn = {
|
|
1542
|
+
plan: Yt,
|
|
1543
|
+
apply: Zt,
|
|
1544
|
+
branch: an,
|
|
1545
|
+
plans: on,
|
|
1546
|
+
drift: mn,
|
|
1547
|
+
files: gn,
|
|
1548
|
+
"rollback-file": _n,
|
|
1549
|
+
migrate: jt,
|
|
1550
|
+
rollback: Mt,
|
|
1551
|
+
status: Nt,
|
|
1552
|
+
seed: Ft,
|
|
1512
1553
|
generate: async (e) => {
|
|
1513
|
-
let { value: t, rest: n } = a(e, "--root"), { value: r, rest: i } = a(n, "--name"), o = t ? T(t) : process.cwd(), s =
|
|
1514
|
-
return await E.mkdir(u, { recursive: !0 }), await E.writeFile(d,
|
|
1554
|
+
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`);
|
|
1555
|
+
return await E.mkdir(u, { recursive: !0 }), await E.writeFile(d, bn(l, s), "utf8"), B.info(`created ${w(o, d)}`), console.error("Fill in the apply/undo steps, then run `voltro db migrate` (rollback with `voltro db rollback`)."), console.error("For a plain schema shape change you may not need this — `voltro db apply` diffs declared vs live."), 0;
|
|
1515
1556
|
},
|
|
1516
|
-
squash:
|
|
1517
|
-
"restore-snapshot":
|
|
1518
|
-
"gc-snapshots":
|
|
1557
|
+
squash: ln,
|
|
1558
|
+
"restore-snapshot": sn,
|
|
1559
|
+
"gc-snapshots": cn,
|
|
1519
1560
|
adopt: async (e) => {
|
|
1520
1561
|
let t = (t) => {
|
|
1521
1562
|
let n = e.indexOf(`--${t}`);
|
|
@@ -1536,11 +1577,11 @@ export default defineMigration({
|
|
|
1536
1577
|
})), f = d(n), p = d(r);
|
|
1537
1578
|
if (f === void 0) return console.error(`voltro db adopt: '${n}' does not exist in the database`), 1;
|
|
1538
1579
|
if (p === void 0) return console.error(`voltro db adopt: '${r}' does not exist in the database — boot once so the plugin's table is created`), 1;
|
|
1539
|
-
let m = async (e) => await J(l, M.SqlClient.pipe(j.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 =
|
|
1540
|
-
for (let e of
|
|
1580
|
+
let m = async (e) => await J(l, M.SqlClient.pipe(j.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));
|
|
1581
|
+
for (let e of Re(s, g, await h(n))) console.log(e);
|
|
1541
1582
|
if (g.fatal) return 1;
|
|
1542
1583
|
if (!e.includes("--apply")) return console.log(""), console.log(" (dry run — nothing written. Re-run with --apply.)"), 0;
|
|
1543
|
-
let _ = await
|
|
1584
|
+
let _ = await Ue(s, g, c, "id", void 0, m, { keepSource: e.includes("--keep-source") });
|
|
1544
1585
|
return console.log(""), console.log(` copied ${_.copied}/${_.sourceRows} row(s)`), console.log(` snapshot: ${_.snapshotTable} — restore from here, then drop it yourself`), _.verified ? (console.log(_.sourceDropped ? ` dropped ${n}` : ` ${n} left in place (--keep-source)`), 0) : (console.error(" ✗ counts DIFFER — the source was NOT dropped. Compare the two tables before doing anything else."), 1);
|
|
1545
1586
|
},
|
|
1546
1587
|
"scan-credentials": async (e) => {
|
|
@@ -1555,8 +1596,8 @@ export default defineMigration({
|
|
|
1555
1596
|
column: o
|
|
1556
1597
|
});
|
|
1557
1598
|
}
|
|
1558
|
-
let i = [...
|
|
1559
|
-
return console.log(
|
|
1599
|
+
let i = [...We, ...n], a = await J(await q(), M.SqlClient.pipe(j.flatMap((e) => j.promise(() => nt(e, t, i, G)))));
|
|
1600
|
+
return console.log(rt(a, t)), it(a);
|
|
1560
1601
|
},
|
|
1561
1602
|
"encrypt-column": async (e) => {
|
|
1562
1603
|
let t = W(), n = e.includes("--dry-run"), i = e.includes("--yes"), a = (t) => {
|
|
@@ -1564,20 +1605,20 @@ export default defineMigration({
|
|
|
1564
1605
|
return n >= 0 ? e[n + 1] : void 0;
|
|
1565
1606
|
}, s = Math.max(1, Number(a("--batch") ?? 500)), c = a("--key-env") ?? "FIELD_ENCRYPTION_KEY", l = process.env[c];
|
|
1566
1607
|
if (!l) throw new r(`voltro db encrypt-column: ${c} is not set. It must be the SAME key your app runs with (\`governancePlugin({ fieldEncryption: { key } })\`) — encrypting with a different one produces rows the app cannot read. Use --key-env to name a different variable.`);
|
|
1567
|
-
let u =
|
|
1608
|
+
let u = Ne(l), d = o(e, Ot).filter((e) => e.includes(".")).map(pt);
|
|
1568
1609
|
if (d.length === 0) throw new r("voltro db encrypt-column: name at least one <table>.<column>");
|
|
1569
1610
|
let f = await q(), p = [];
|
|
1570
1611
|
for (let e of d) {
|
|
1571
1612
|
let a = G(e.table), o = G(e.column), l = await J(f, M.SqlClient.pipe(j.flatMap((n) => j.promise(async () => {
|
|
1572
|
-
let i = await j.runPromise(n.unsafe(
|
|
1613
|
+
let i = await j.runPromise(n.unsafe(Tt(t, e, K(t))));
|
|
1573
1614
|
if (i.length === 0) throw new r(`voltro db encrypt-column: ${e.table}.${e.column} does not exist on this database`);
|
|
1574
|
-
return
|
|
1615
|
+
return Et(Object.values(i[0])[0]);
|
|
1575
1616
|
})))), d = await J(f, M.SqlClient.pipe(j.flatMap((e) => j.promise(async () => await j.runPromise(e.unsafe(`SELECT ${G("id")} AS id, ${o} AS v FROM ${a}`)))))), m = 0;
|
|
1576
|
-
for (let e of d) typeof e.v != "string" || A(e.v) || (m = Math.max(m,
|
|
1577
|
-
let h =
|
|
1578
|
-
if (!h.fits) return console.error(` ✗ ${
|
|
1579
|
-
if (
|
|
1580
|
-
let g = d.filter((t) =>
|
|
1617
|
+
for (let e of d) typeof e.v != "string" || A(e.v) || (m = Math.max(m, bt(e.v)));
|
|
1618
|
+
let h = ht(m, l);
|
|
1619
|
+
if (!h.fits) return console.error(` ✗ ${gt(e, h)}`), 1;
|
|
1620
|
+
if (xt(d.map((e) => e.v).find((e) => typeof e == "string" && A(e)), u) === !1) return console.error(` ✗ ${St(e, c)}`), 1;
|
|
1621
|
+
let g = d.filter((t) => vt(t.v, u, e) !== void 0 || wt(t.v, u, e) !== void 0).length;
|
|
1581
1622
|
if (!n && !i) return console.error(` ✗ ${e.table}.${e.column}: ${g} row(s) would be rewritten in place. Re-run with --yes, or --dry-run to see the counts without writing.`), 1;
|
|
1582
1623
|
let _ = 0, v = 0, y = 0, b = 0, x = [];
|
|
1583
1624
|
for (let t of d) {
|
|
@@ -1586,7 +1627,7 @@ export default defineMigration({
|
|
|
1586
1627
|
continue;
|
|
1587
1628
|
}
|
|
1588
1629
|
if (typeof t.v == "string" && A(t.v)) {
|
|
1589
|
-
let n =
|
|
1630
|
+
let n = wt(t.v, u, e);
|
|
1590
1631
|
if (n === void 0) {
|
|
1591
1632
|
_ += 1;
|
|
1592
1633
|
continue;
|
|
@@ -1597,7 +1638,7 @@ export default defineMigration({
|
|
|
1597
1638
|
}), v += 1;
|
|
1598
1639
|
continue;
|
|
1599
1640
|
}
|
|
1600
|
-
let n =
|
|
1641
|
+
let n = vt(t.v, u, e);
|
|
1601
1642
|
if (n === void 0) {
|
|
1602
1643
|
y += 1;
|
|
1603
1644
|
continue;
|
|
@@ -1624,21 +1665,21 @@ export default defineMigration({
|
|
|
1624
1665
|
});
|
|
1625
1666
|
}
|
|
1626
1667
|
console.log(`field encryption · dialect ${t}${n ? " · DRY RUN, nothing written" : ""}`), console.log("");
|
|
1627
|
-
for (let e of p) console.log(
|
|
1628
|
-
return n || console.log(
|
|
1668
|
+
for (let e of p) console.log(_t(e, n));
|
|
1669
|
+
return n || console.log(Ct(d)), 0;
|
|
1629
1670
|
}
|
|
1630
|
-
},
|
|
1671
|
+
}, Sn = (e) => Object.prototype.hasOwnProperty.call(xn, e), Cn = async (t) => {
|
|
1631
1672
|
let [n, ...r] = t;
|
|
1632
1673
|
if (!n) {
|
|
1633
1674
|
console.error("voltro db <subcommand> [args]"), console.error("subcommands:");
|
|
1634
|
-
for (let e of Object.keys(
|
|
1675
|
+
for (let e of Object.keys(xn)) console.error(` ${e}`);
|
|
1635
1676
|
return 1;
|
|
1636
1677
|
}
|
|
1637
|
-
if (!
|
|
1638
|
-
let i =
|
|
1678
|
+
if (!Sn(n)) return console.error(`voltro db: unknown subcommand '${n}'`), console.error(` known: ${e.join(", ")}`), 2;
|
|
1679
|
+
let i = xn[n];
|
|
1639
1680
|
(process.env.DB_DIRECT_URL !== void 0 || process.env.DB_MIGRATE_URL !== void 0) && B.info("using a DIRECT (non-pooler) connection for the db-command path (DB_DIRECT_URL/DB_MIGRATE_URL set)");
|
|
1640
1681
|
let a = (e) => {
|
|
1641
|
-
|
|
1682
|
+
kt(e) ? B.error(At) : console.error(e), process.exit(1);
|
|
1642
1683
|
};
|
|
1643
1684
|
process.on("uncaughtException", a);
|
|
1644
1685
|
try {
|
|
@@ -1648,4 +1689,4 @@ export default defineMigration({
|
|
|
1648
1689
|
}
|
|
1649
1690
|
};
|
|
1650
1691
|
//#endregion
|
|
1651
|
-
export {
|
|
1692
|
+
export { Rt as a, Cn as c, pn as i, U as n, kt as o, Lt as r, X as s, At as t };
|