@voltro/database 0.14.0 → 0.15.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 +127 -0
- package/dist/sql.d.ts +20 -17
- package/dist/sql.js +61 -35
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -39,6 +39,133 @@ _Changes staged for the next release accumulate here (rolled up from
|
|
|
39
39
|
|
|
40
40
|
---
|
|
41
41
|
|
|
42
|
+
## [0.15.0] — 2026-07-27
|
|
43
|
+
|
|
44
|
+
### ⚠ BREAKING
|
|
45
|
+
|
|
46
|
+
- **@voltro/cli** — **A rename now carries the ALIASED importers, not only the relative ones.**
|
|
47
|
+
|
|
48
|
+
An app's web build stopped compiling after `voltro update`: 84 relative imports were rewritten correctly, 163 aliased ones across 88 files were not, and `tsc` reported 249 errors on names that no longer existed. Nothing in the codemod's output hinted that a whole class of import had been skipped.
|
|
49
|
+
|
|
50
|
+
Two independent halves, and each alone leaves the imports stale:
|
|
51
|
+
|
|
52
|
+
- The codemod's ts-morph project was built with **no `baseUrl` and no `paths`**, so `@/components/link` resolved to nothing. It now gets the compiler's own shape — the raw `paths`, not the pre-resolved Vite table, because a `paths` target is relative to `baseUrl` by definition and an absolute one does not resolve. - `SourceFile.move()` rewrites relative specifiers and **nothing else**, which is correct on its own terms: ts-morph cannot know whether the alias mapping or the file is meant to change. So the codemods now rewrite the aliased ones themselves, narrowly — only specifiers that RESOLVED to the moved file, and only the trailing stem, which needs no alias table and so cannot disagree with one. The run reports how many it rewrote.
|
|
53
|
+
|
|
54
|
+
**A file an exact `paths` entry names is left alone and reported.** Renaming `link.tsx` while `"@/link": ["src/components/link.tsx"]` points at it leaves the mapping resolving to nothing — and the same path is usually repeated in a vite/vitest alias table no codemod owns. One app hit this and then saw a taxonomy violation reported on a file the codemod had itself created.
|
|
55
|
+
|
|
56
|
+
**`page/unsuffixed-in-pages` is now an error, not a warning.** The comment justifying the warning contradicted the scanner it described: that bucket is already narrowed to a default export nothing imports, which is what an unmigrated page looks like and what a co-located component never does. The failure it names is invisible everywhere else — an unmigrated route simply 404s, with a clean `tsc` and a green suite. One app finished a migration with 51 of them. `codemod: none`: the rename it asks for already ships as `0.14.0/03_pages-suffix`, and nothing about a user's SOURCE changes here — what changes is that `voltro check` now fails on a route that does not route.
|
|
57
|
+
- **@voltro/protocol, @voltro/client, @voltro/web** — **`errorTag` moves from `@voltro/client` to `@voltro/protocol`.**
|
|
58
|
+
|
|
59
|
+
It reads the `_tag` that `toRpc` writes, so it now lives beside `toRpc` — one file owning both ends of that contract. Where it used to live had a cost invisible from inside the framework: an app's shared error handler sat in a package that pulled only `@voltro/i18n`, and reading a tag would have meant depending on the entire client package for seven lines. They declined, and kept parsing message strings with a regex — the exact outcome the helper exists to prevent.
|
|
60
|
+
|
|
61
|
+
`@voltro/web` re-exports the client surface, so it loses the symbol too — the same codemod covers an app that imported it from there.
|
|
62
|
+
|
|
63
|
+
Not re-exported from `@voltro/client`: two import paths for one helper is how the next reader learns the wrong one. The transform codemod repoints the import, preserving an alias (`errorTag as tagOf`) and the type-only form, and merges into an existing `@voltro/protocol` import rather than adding a second.
|
|
64
|
+
|
|
65
|
+
While moving it, its doc comment gained the thing that matters at the call site and was only implied before: **`instanceof` does not hold on the client.** What arrives there was decoded from JSON and never constructed, so match on the tag, not on the class. One team read the old wording as a promise that `instanceof` works and was right to say so.
|
|
66
|
+
|
|
67
|
+
### Added
|
|
68
|
+
|
|
69
|
+
- **@voltro/protocol, @voltro/cli** — **An auth strategy reaches the app's DataStore, on `input.store`.**
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
const sessionStrategy: AuthStrategy = {
|
|
73
|
+
id: 'db-session',
|
|
74
|
+
resolve: async ({ headers, store }) => {
|
|
75
|
+
if (store === undefined) return { kind: 'skip' } // still booting
|
|
76
|
+
const [row] = await store.query(sessions.byToken(headers.authorization))
|
|
77
|
+
return row ? { kind: 'matched', subject: toSubject(row) } : { kind: 'skip' }
|
|
78
|
+
},
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Without it, a DB-backed strategy — a session row, an API-key record, a PAT table — had to open a SECOND connection path beside the framework's, to the same database the request store opens a moment later. One adopter's `auth/db.ts` is 105 lines of exactly that: a second `ManagedRuntime` plus a `MysqlClient`, load-bearing for their session lookup and their ApiKeyStore. Every DB-backed OIDC / SAML / PAT integration rebuilds it, which is what made this a framework gap rather than an app's problem.
|
|
83
|
+
|
|
84
|
+
It is the **same value** `auth.resolveScopes` already receives, through the **same lazy getter** — one ref, two consumers, rather than each caller reaching for the store its own way. That is deliberate: `voltro dev` builds the store AFTER the auth chain and `voltro serve` builds it BEFORE, so a value captured at config time would be `undefined` forever in dev and correct in production. The getter is read ONCE per request, not once per strategy.
|
|
85
|
+
|
|
86
|
+
`store` is `undefined` only while the store is still being built, and on an app with no store — a strategy should `skip` rather than throw. It is the BOOT store, not a request-scoped one: strategies resolve before a request store exists.
|
|
87
|
+
|
|
88
|
+
**Not narrowed to a read-only surface**, and the reason is worth stating: the narrower type would be the better guarantee, `DataStore` is the driver SPI, and giving strategies a different type from the one `resolveScopes` gets would put two views of one object in the same file. A strategy that writes during subject resolution is a design mistake; the type system is not going to catch it for you. Read users / sessions / keys, do not run domain writes.
|
|
89
|
+
|
|
90
|
+
### Fixed
|
|
91
|
+
|
|
92
|
+
- **@voltro/cli** — `voltro dev` terminates when its dev server does, instead of living forever.
|
|
93
|
+
|
|
94
|
+
The supervisor never watched its child die. `runChild` was an `Effect.acquireUseRelease` whose `use` was `Effect.never`, so `proc.on('exit')` existed ONLY in the release path — and that path runs when the fiber is interrupted (a restart, a signal), never when the child exits by itself. Two more places assumed the same thing: `runSupervisor` was typed `Effect<never>`, and `dev.ts` returned `new Promise(() => {})` after starting it.
|
|
95
|
+
|
|
96
|
+
So a boot that aborted — an unreachable database, a refused migration, a failed env gate — left the child dead and the supervisor waiting for a file change that nobody was there to make. Measured, not inferred: one developer machine carried 15 such `voltro dev` process pairs, `ppid=1`, the oldest 7 days old, every one a boot that had failed against a remote database. They hold a watcher and a terminal-less process each; in CI the same shape keeps a runner busy after the job "finished".
|
|
97
|
+
|
|
98
|
+
`use` now awaits the child (`awaitChildExit`) and the supervisor races that against the watch loop, so whichever happens first decides. A restart still does NOT end it — `stopChild` interrupts the fiber, so the deferred is never completed on that path. A child killed by a signal reports `code: null`, which is reported as a failure rather than a clean 0.
|
|
99
|
+
|
|
100
|
+
What a self-exit MEANS then depends on whether anyone is watching, because the two failure modes pull in opposite directions:
|
|
101
|
+
|
|
102
|
+
- **Interactive** (stdout is a TTY) — a crashed boot is something you are about to fix, so the supervisor says so and keeps watching. The next save restarts it, which is what every other dev server does; stopping would throw away the watcher mid-edit and make you retype the command. - **Non-interactive** — nobody is going to fix anything. `voltro dev` exits with the child's code, so a failed boot is a failed command. This is the case that produced the invisible processes, and the one CI actually waits on.
|
|
103
|
+
|
|
104
|
+
A CLEAN exit always stops, watched or not. `VOLTRO_DEV_KEEP_ALIVE=1|0` forces the answer for what the TTY check cannot see — a CI runner with a TTY allocated, or a wrapper that pipes output while a human still watches it — and cannot keep a clean exit alive, which would turn a deliberate shutdown into a hang.
|
|
105
|
+
|
|
106
|
+
Pinned against REAL child processes, because the defect was an Effect that never settled — a stubbed `once('exit')` that resolves is exactly what would have passed while the bug shipped.
|
|
107
|
+
- **@voltro/database** — **A user-facing message that names an API must have one — now checked in CI.**
|
|
108
|
+
|
|
109
|
+
The sibling of the claimed-wiring check. That one asserts a doc comment's claimed caller exists; this one asserts a message's claimed API exists. Same failure shape, worse audience: a doc comment is read by somebody browsing, a refusal by somebody already blocked and looking for the sanctioned way out.
|
|
110
|
+
|
|
111
|
+
It exists for a reported bug that nothing could have caught. The drop-table refusal offered, as its FIRST option, *"chain `.dropped()` on it"* — tables have no such marker, only columns do. Doc SAMPLES are typechecked; message strings are not, and cannot be. Three of one release's reported defects lived in that blind spot.
|
|
112
|
+
|
|
113
|
+
Three rules, each with an unambiguous answer, because a noisy gate is skipped and then costs more than it saves:
|
|
114
|
+
|
|
115
|
+
- a `VOLTRO_*` variable a message tells you to **set** must be read somewhere, - a `` `.method()` `` a message tells you to **chain** must be a callable MEMBER of a published type, - a `--flag` in a `voltro …` instruction must be parsed.
|
|
116
|
+
|
|
117
|
+
The member rule is the one that took two attempts. The first version asked "does this name exist in the public surface" and the motivating bug **passed it**: `dropped` is exported, as a free `dropped()` you write as a column's value. A dotted claim is a claim about something chainable, so a free function and a `readonly dropped?: boolean` data property are both correctly rejected now.
|
|
118
|
+
|
|
119
|
+
**It immediately found a second instance nobody had reported** — the drop-COLUMN refusal also said "chain `.dropped()`", one level down from the reported one, and the real spelling is `<column>: dropped()` as the field's value. Close enough to guess from, which is why it survived.
|
|
120
|
+
|
|
121
|
+
Ships with a `--selftest` that runs first in CI, for the reason the changelog gate has one: a check that has quietly stopped detecting anything still prints green, and green is read as evidence.
|
|
122
|
+
- **@voltro/database** — **Two migration refusals sent people the wrong way** — the worst place for a bad hint, because whoever reads one is already blocked and looking for the sanctioned way out.
|
|
123
|
+
|
|
124
|
+
**The drop-table refusal recommended an API that does not exist.** Its first option was *"add it to your declared set + chain `.dropped()` on it"*. There is no table-level `dropped()` — only the column marker. The recommendation was also the conceptually RIGHT one, which is what made it expensive: the two options that do work are both worse, so a reader picks the one they cannot follow.
|
|
125
|
+
|
|
126
|
+
There is now a real per-table answer: **`VOLTRO_DESTRUCTIVE_OK` accepts a table list**, not just `1`. `VOLTRO_DESTRUCTIVE_OK=old_things` acknowledges the data loss for that table and leaves every other lossy op in the plan blocked. `1` still means all of them — which is rarely what somebody means, and was previously the only way to say anything. A user with one intended drop and three other lossy ops had to acknowledge all four or hand-write a `DROP TABLE` migration, the path 0.14.0's own upgrade note warns against.
|
|
127
|
+
|
|
128
|
+
The message also states why there is deliberately no table marker: a dropped COLUMN leaves a slot worth documenting in the declaration; a dropped TABLE leaves nothing, so the marker would be a dead entry you must remember to delete.
|
|
129
|
+
|
|
130
|
+
**The drop-column refusal never mentioned `renamedFrom`.** It offered "chain `.dropped()`" or "restore the field" — and followed literally on a rename, the first costs exactly the data the user was trying to keep. When the plan drops AND adds columns on the same table, the message now leads with *"did you rename one?"* and names both sides. The evidence was in the plan the whole time.
|
|
131
|
+
|
|
132
|
+
Finding that required fixing a second thing: the footer read only the BLOCKED operations, and an `add-column` is `safe`. The counterpart of a rename was never in the list it was looking at.
|
|
133
|
+
- **@voltro/cli** — **0.14.0's taxonomy codemod renamed two kinds of file it should not have, and a repo that already upgraded carries the damage with a green build.** Both were found by adopters running it on real projects; both are silent — the rename succeeds, the imports are rewritten, nothing throws.
|
|
134
|
+
|
|
135
|
+
**A framework primitive was treated as an undeclared file.** `health.route.tsx` → `health.route.component.tsx`, five times in one app. The codemod kept its OWN list of "suffixes that already carry a contract" instead of reading `fileConventions.ts`, and `.route.` was not on it — the exact drift that module exists to prevent, reproduced inside a file that imports from it. The list is gone; the registry answers now, and it gained `ROUTE_PATTERN` plus a `carriesFrameworkConvention()` every consumer shares.
|
|
136
|
+
|
|
137
|
+
The root cause underneath was worse than a missing entry: `export default defineRestRoute({...})` resolved to the placeholder name `Default`, which starts with a capital, and was counted as a COMPONENT on that basis. A default export is now only evidence of a component when the exported thing is callable — so a convention nobody has registered yet is safe too.
|
|
138
|
+
|
|
139
|
+
**A file with no exports was called a type file.** `test-setup.ts` → `test-setup.types.ts`, while `vitest.config.ts` still named `./test-setup.ts` as a **string**. Not an import, so nothing rewrote it and nothing failed: that suite would have run without its setup and stayed green. Five more went the same way — a registry module, two migration runners, a `.register.ts`, and a code generator whose `export` tokens live inside template strings.
|
|
140
|
+
|
|
141
|
+
`*.types.ts` promises "zero runtime exports", and that promise only means something for a file that exports TYPES. Zero of everything promises nothing, and renames a module whose whole purpose is being imported for effect — where the filename is often the only reference there is. It now requires at least one exported type.
|
|
142
|
+
|
|
143
|
+
**The shipped codemod undoes both**, and can only reach files whose content proves the suffix was wrong: a `.component.` on a name that already carries a framework convention, and a `.types.` on a file that exports nothing at all. It also prints the one thing it cannot fix — references by PATH rather than by import (a vitest `setupFiles`, a tsconfig `include`, a Docker `COPY`) were strings on the way out and are strings on the way back.
|
|
144
|
+
- **@voltro/cli** — Three ways `voltro update` failed on a real adopter's host, none of which we could have found ourselves — each needs a machine we do not have.
|
|
145
|
+
|
|
146
|
+
**The install could not run here, and the refusal left the tree half-upgraded.** Their install runs in a container against its own store. `voltro update` ran the package manager on the host anyway; pnpm refused (it wanted to remove `node_modules` and had no TTY to ask) and exited — after the version bumps were already written and before any codemod ran. That is the state this command's own documentation calls the worst one to be in, and it was reachable by design.
|
|
147
|
+
|
|
148
|
+
`--no-install` now writes the bump and stops, saying plainly that the tree is half-upgraded and naming both remaining steps. The install-failed message points at it too. Note what this is not: a compatibility flag. It is a mode for a host where the install is somebody else's job, and it ends by telling you the job is not done.
|
|
149
|
+
|
|
150
|
+
**The codemod scan exhausted a 12 GB heap, and said nothing about why.** The crash was a bare V8 out-of-memory stack. The scan pruned the directories WE know about — `node_modules`, `dist`, `.turbo` — which cannot cover a project's own heavy ignored trees (a build cache, a data dump, a virtualenv).
|
|
151
|
+
|
|
152
|
+
Inside a git repository the scan now asks git: `git ls-files --cached --others --exclude-standard` is exactly "files this project considers its own", and a codemod rewrites source — source that git ignores is not source we may rewrite. It also removes the traversal, so there is nothing left to exhaust memory on. Outside a repo the walk remains, now with a ceiling that REPORTS which directory to exclude instead of dying namelessly.
|
|
153
|
+
|
|
154
|
+
**"not a Voltro app" was the wrong conclusion.** Said of a directory containing an `app.config.ts`, it sends the reader looking for the wrong problem. Three web apps in a workspace inherited from another tool had their `@voltro/*` dependencies in an ancestor `package.json` — the apps ARE Voltro apps; only the declaration lives elsewhere. With an `app.config.ts` present the message now says that, and names the two ways forward.
|
|
155
|
+
|
|
156
|
+
**A monorepo may keep ONE root `package.json`** with its apps carrying only an `app.config.ts`. Running `voltro update` inside such an app used to say "no package.json at <dir>" — true, and useless. It now recognises the layout, says it is supported, and prints the command with the root already filled in.
|
|
157
|
+
- **@voltro/cli** — **`voltro update --only <id>`**, and a summary that stops contradicting itself.
|
|
158
|
+
|
|
159
|
+
`--only` runs just the named codemods (repeatable or comma-separated; ids are what `--dry-run` prints). The ask behind it: two of three codemods were load-bearing for one app — without them, 52 type errors and 51 routes that 404 — while the third was elective, and the repairing tool refuses on a dirty tree, so there was no way to take the necessary half first.
|
|
160
|
+
|
|
161
|
+
It is deliberately NOT a `--required` flag over a REQUIRED/OPTIONAL axis on each codemod. "Required" would have to mean *this app does not run without it*, and that is a property of the app: `03_pages-suffix` is unavoidable for a project with pages and irrelevant to an api-only one. Marking it on the codemod would encode a guess as a contract. An unknown id is an error listing the ids that ARE available — "it did nothing" and "you typed it wrong" otherwise look identical.
|
|
162
|
+
|
|
163
|
+
**The summary counted only edited files, and renames vanished from it.** The before-snapshot is keyed by PATH, so a moved file has no entry under its new one: a pass that renamed 238 files and edited 9 importers reported `(9 files)`, understating the change by a factor of 26 in the line a user plans around. Moves are now paired by content and reported separately — `(238 renamed, 9 edited)`.
|
|
164
|
+
|
|
165
|
+
**A dry run no longer speaks in the past tense.** It printed `✓ <id> — <title>`, the same line a real run prints. Now `·` and `[would apply]`.
|
|
166
|
+
|
|
167
|
+
---
|
|
168
|
+
|
|
42
169
|
## [0.14.0] — 2026-07-26
|
|
43
170
|
|
|
44
171
|
### ⚠ BREAKING
|
package/dist/sql.d.ts
CHANGED
|
@@ -702,6 +702,25 @@ export declare const defaultJsonClause: (value: object, dialect: DialectId) => s
|
|
|
702
702
|
|
|
703
703
|
export declare const describeOutcome: (outcome: BootMigrationOutcome, dialectId: string) => string;
|
|
704
704
|
|
|
705
|
+
/**
|
|
706
|
+
* Parse `VOLTRO_DESTRUCTIVE_OK`.
|
|
707
|
+
*
|
|
708
|
+
* `1` / `true` acknowledges every lossy op in the run. A comma-separated list
|
|
709
|
+
* acknowledges only those TABLES — which is the form somebody wants far more
|
|
710
|
+
* often, and its absence was a real complaint: a plan carrying one intended drop
|
|
711
|
+
* plus three other lossy ops had no way to say yes to the one. `1` said yes to
|
|
712
|
+
* all four, and the alternative was a hand-written DROP migration, which the
|
|
713
|
+
* framework's own upgrade note warns against.
|
|
714
|
+
*
|
|
715
|
+
* `undefined` = not set at all.
|
|
716
|
+
*/
|
|
717
|
+
export declare const destructiveScope: (raw: string | undefined) => {
|
|
718
|
+
readonly kind: "all";
|
|
719
|
+
} | {
|
|
720
|
+
readonly kind: "tables";
|
|
721
|
+
readonly tables: ReadonlySet<string>;
|
|
722
|
+
} | undefined;
|
|
723
|
+
|
|
705
724
|
/**
|
|
706
725
|
* Compare declared reactivity against the triggers actually installed.
|
|
707
726
|
*
|
|
@@ -2160,23 +2179,7 @@ declare interface TableUnique {
|
|
|
2160
2179
|
};
|
|
2161
2180
|
}
|
|
2162
2181
|
|
|
2163
|
-
|
|
2164
|
-
* Clear the `blocked` flag on every LOSSY operation in a plan.
|
|
2165
|
-
*
|
|
2166
|
-
* Called only after the destructive opt-in has been established, and it is not
|
|
2167
|
-
* cosmetic. `applyPlan` carries its OWN unconditional refusal on any blocked
|
|
2168
|
-
* operation, with no override parameter. So a plan that the boot gate has
|
|
2169
|
-
* decided may proceed, but which still arrives marked blocked, is refused a
|
|
2170
|
-
* second time by the applier — which meant `VOLTRO_DESTRUCTIVE_OK=1` could
|
|
2171
|
-
* never actually drop a table. The planner's fix hint names that exact
|
|
2172
|
-
* variable, so the documented escape hatch pointed at a wall.
|
|
2173
|
-
*
|
|
2174
|
-
* Only `lossy` ops are unblocked, and callers must have already established
|
|
2175
|
-
* that no other class is blocked. A rename-without-marker or a NOT NULL
|
|
2176
|
-
* without backfill stays blocked even in destructive-OK mode: those lose data
|
|
2177
|
-
* regardless of intent, so intent is not the question being asked.
|
|
2178
|
-
*/
|
|
2179
|
-
export declare const unblockLossy: (plan: MigrationPlan) => MigrationPlan;
|
|
2182
|
+
export declare const unblockLossy: (plan: MigrationPlan, scope?: ReturnType<typeof destructiveScope>) => MigrationPlan;
|
|
2180
2183
|
|
|
2181
2184
|
/**
|
|
2182
2185
|
* Unique-constraint metadata. Set by `.unique()` (or `.unique({ dedup })`).
|
package/dist/sql.js
CHANGED
|
@@ -2416,21 +2416,35 @@ BEGIN
|
|
|
2416
2416
|
}), fr = () => {
|
|
2417
2417
|
let e = (process.env.VOLTRO_DB_IGNORE_TABLES ?? "").split(",").map((e) => e.trim()).filter((e) => e.length > 0);
|
|
2418
2418
|
return e.length > 0 ? { ignoreTables: e } : {};
|
|
2419
|
-
}, pr = (e) =>
|
|
2419
|
+
}, pr = (e) => {
|
|
2420
|
+
if (e === void 0) return;
|
|
2421
|
+
let t = e.trim();
|
|
2422
|
+
if (t === "") return;
|
|
2423
|
+
if (t === "1" || t.toLowerCase() === "true") return { kind: "all" };
|
|
2424
|
+
let n = t.split(",").map((e) => e.trim()).filter((e) => e.length > 0);
|
|
2425
|
+
return n.length > 0 ? {
|
|
2426
|
+
kind: "tables",
|
|
2427
|
+
tables: new Set(n)
|
|
2428
|
+
} : void 0;
|
|
2429
|
+
}, mr = (e) => typeof e.table == "string" ? e.table : void 0, hr = (e, t = { kind: "all" }) => ({
|
|
2420
2430
|
...e,
|
|
2421
2431
|
operations: e.operations.map((e) => {
|
|
2422
2432
|
if (!e.blocked || e.classification !== "lossy") return e;
|
|
2423
|
-
|
|
2424
|
-
|
|
2433
|
+
if (t?.kind === "tables") {
|
|
2434
|
+
let n = mr(e.op);
|
|
2435
|
+
if (n === void 0 || !t.tables.has(n)) return e;
|
|
2436
|
+
}
|
|
2437
|
+
let { blocked: n, ...r } = e;
|
|
2438
|
+
return r;
|
|
2425
2439
|
})
|
|
2426
|
-
}),
|
|
2440
|
+
}), gr = (e, t, n) => t === "postgres" ? at(e, n).pipe(d.flatMap((e) => {
|
|
2427
2441
|
let t = ot(e);
|
|
2428
2442
|
return t === void 0 ? d.void : d.logWarning(`auto-migrate: ${t}`).pipe(d.annotateLogs({ scope: "voltro:migrate" }));
|
|
2429
|
-
}), d.catchAll(() => d.void)) : d.void,
|
|
2443
|
+
}), d.catchAll(() => d.void)) : d.void, _r = (e, t, n) => d.gen(function* () {
|
|
2430
2444
|
let r = sr(e), i = t.filter((e) => !I(e.tableName));
|
|
2431
2445
|
if (process.env.VOLTRO_MIGRATE_FORCE !== "1") {
|
|
2432
2446
|
let t = N(F(i, r));
|
|
2433
|
-
if ((yield* or(e)) === t) return yield*
|
|
2447
|
+
if ((yield* or(e)) === t) return yield* gr(e, r, i), {
|
|
2434
2448
|
kind: "up-to-date",
|
|
2435
2449
|
fingerprint: t
|
|
2436
2450
|
};
|
|
@@ -2447,12 +2461,11 @@ BEGIN
|
|
|
2447
2461
|
...fr()
|
|
2448
2462
|
});
|
|
2449
2463
|
if (s.summary.blocked > 0) {
|
|
2450
|
-
let e = s.operations.filter((e) => e.blocked).every((e) => e.classification === "lossy");
|
|
2451
|
-
if (
|
|
2464
|
+
let e = s.operations.filter((e) => e.blocked).every((e) => e.classification === "lossy"), t = pr(process.env.VOLTRO_DESTRUCTIVE_OK);
|
|
2465
|
+
if (t === void 0 || !e || (s = hr(s, t), s.operations.some((e) => e.blocked))) return {
|
|
2452
2466
|
kind: "refused-blocked",
|
|
2453
2467
|
plan: s
|
|
2454
2468
|
};
|
|
2455
|
-
s = pr(s);
|
|
2456
2469
|
}
|
|
2457
2470
|
return s.operations.length === 0 ? {
|
|
2458
2471
|
kind: "up-to-date",
|
|
@@ -2476,10 +2489,10 @@ BEGIN
|
|
|
2476
2489
|
}),
|
|
2477
2490
|
plan: s
|
|
2478
2491
|
};
|
|
2479
|
-
}),
|
|
2492
|
+
}), vr = (e, t, n) => process.env.VOLTRO_AUTO_MIGRATE === "0" ? d.succeed({
|
|
2480
2493
|
kind: "skipped",
|
|
2481
2494
|
reason: "VOLTRO_AUTO_MIGRATE=0"
|
|
2482
|
-
}) : n.environment === "prod" ? cr(e, t) :
|
|
2495
|
+
}) : n.environment === "prod" ? cr(e, t) : _r(e, t, n), yr = (e, t) => {
|
|
2483
2496
|
switch (e.kind) {
|
|
2484
2497
|
case "skipped": return `auto-migrate: skipped (${e.reason})`;
|
|
2485
2498
|
case "up-to-date": return `auto-migrate: schema up to date (${t}, fingerprint=${P(e.fingerprint)})`;
|
|
@@ -2489,11 +2502,24 @@ BEGIN
|
|
|
2489
2502
|
}
|
|
2490
2503
|
case "prod-mismatch": return `auto-migrate: SCHEMA FINGERPRINT MISMATCH — declared=${P(e.expected)}` + (e.actual ? ` live=${P(e.actual)}` : " live=<no _voltro_migration_plans row>") + ". Run `voltro db apply --plan plan.json` from the deploy pipeline before serving.";
|
|
2491
2504
|
case "refused-blocked": {
|
|
2492
|
-
let t = e.plan.operations.filter((e) => e.blocked), n = t.filter((e) => e.op.kind === "drop-table").length, r = t.filter((e) => e.op.kind === "add-column").length,
|
|
2493
|
-
|
|
2505
|
+
let t = e.plan.operations.filter((e) => e.blocked), n = t.filter((e) => e.op.kind === "drop-table").length, r = t.filter((e) => e.op.kind === "drop-table").map((e) => "table" in e.op ? e.op.table : "").filter(Boolean), i = t.filter((e) => e.op.kind === "add-column").length, a = t.filter((e) => e.op.kind === "drop-column").length, o = t.filter((e) => e.classification === "needs-rename-annotation").length, s = `auto-migrate: REFUSED — ${e.plan.summary.blocked} blocked operation(s):\n` + ar(e.plan), c = [""];
|
|
2506
|
+
if (n > 0 && c.push(`${n} table(s) exist in the live DB but aren't in your declared schema.`, "This is usually one of three things:", " (a) You're iterating on the schema — the table file got renamed, moved, or temporarily commented out.", " → Restore the declaration. Your data stays intact.", " (b) You want to KEEP the table but NOT manage it with Voltro (a leftover from another tool —", " a Strapi/Rails/legacy migration artifact, or an externally-owned table).", ` → Set \`VOLTRO_DB_IGNORE_TABLES=${r.join(",")}\` (comma-separated).`, " The planner excludes those tables from the diff entirely — it never drops them, and they", " stop blocking your OTHER (additive) changes. This is the fix when a leftover freezes your schema.", " (c) You actually want to drop the table.", ` → Set \`VOLTRO_DESTRUCTIVE_OK=${r.join(",")}\` for ONE run — it acknowledges`, " the data loss for THOSE tables only; every other lossy op in this plan stays blocked.", " (`VOLTRO_DESTRUCTIVE_OK=1` acknowledges all of them, which is rarely what you mean.)", " There is deliberately no `dropped()` marker for a TABLE, unlike for a column: a", " dropped column leaves a slot worth documenting in the declaration, a dropped table", " leaves nothing — the marker would be a dead entry you must remember to delete.", " Soft-drop: set `VOLTRO_SOFT_DROP=1` alongside DESTRUCTIVE_OK to RENAME instead of DROP", " (data survives as `<name>__dropped_<ts>` for ~7d; restorable via `voltro db restore-snapshot`)."), i > 0 && c.push(`${i} required column(s) need a backfill strategy before adding to a populated table.`, " → Annotate the column: `.backfill(sql`<expr>`)` or `.backfill(row => <fn>)` or `.default(<value>)`.", " Existing rows get the backfill value; the column then lands as NOT NULL."), a > 0) {
|
|
2507
|
+
let t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map();
|
|
2508
|
+
for (let r of e.plan.operations) {
|
|
2509
|
+
let e = "table" in r.op ? r.op.table : void 0;
|
|
2510
|
+
if (e === void 0) continue;
|
|
2511
|
+
let i = "column" in r.op ? String(r.op.column) : void 0;
|
|
2512
|
+
if (i === void 0) continue;
|
|
2513
|
+
let a = r.op.kind === "drop-column" ? t : r.op.kind === "add-column" ? n : void 0;
|
|
2514
|
+
a !== void 0 && a.set(e, [...a.get(e) ?? [], i]);
|
|
2515
|
+
}
|
|
2516
|
+
let r = [...t.entries()].filter(([e]) => (n.get(e)?.length ?? 0) > 0).map(([e, t]) => `${e}: ${t.join(", ")} gone, ${n.get(e).join(", ")} new`);
|
|
2517
|
+
c.push(`${a} column(s) are missing from your declared schema.`), r.length > 0 && c.push(" → DID YOU RENAME ONE? This plan drops AND adds columns on the same table:", ...r.map((e) => ` ${e}`), " If so, add `.renamedFrom('<oldName>')` to the NEW column — the planner then emits a", " RENAME and the data moves with it. Dropping and re-adding loses every value."), c.push(" → If intentional: give the field the `dropped()` marker as its VALUE —", " `<column>: dropped()` (import it from `@voltro/database`). It is not a method", " chained onto the column; the slot stays, documenting the hole.", " → If a typo: restore the field. Data survives until you drop it.");
|
|
2518
|
+
}
|
|
2519
|
+
return o > 0 && c.push(`${o} column(s) look like renames (one column gone + a new one of same shape appeared).`, " → On the NEW column add `.renamedFrom('<oldName>')` so the planner emits RENAME instead of DROP+ADD."), c.push("", "See `voltro db plan` for the full machine-readable diff."), s + "\n" + c.join("\n");
|
|
2494
2520
|
}
|
|
2495
2521
|
}
|
|
2496
|
-
},
|
|
2522
|
+
}, br = /* @__PURE__ */ new Set([
|
|
2497
2523
|
"node_modules",
|
|
2498
2524
|
"dist",
|
|
2499
2525
|
"build",
|
|
@@ -2502,11 +2528,11 @@ BEGIN
|
|
|
2502
2528
|
".next",
|
|
2503
2529
|
".git",
|
|
2504
2530
|
".framework"
|
|
2505
|
-
]),
|
|
2531
|
+
]), xr = async (e) => {
|
|
2506
2532
|
let t = [], n = async (e) => {
|
|
2507
2533
|
let r = await h.readdir(e, { withFileTypes: !0 }).catch(() => []);
|
|
2508
2534
|
for (let i of r) {
|
|
2509
|
-
if (
|
|
2535
|
+
if (br.has(i.name)) continue;
|
|
2510
2536
|
let r = g(e, i.name);
|
|
2511
2537
|
i.isDirectory() ? await n(r) : i.isFile() && l.test(i.name) && t.push(r);
|
|
2512
2538
|
}
|
|
@@ -2515,7 +2541,7 @@ BEGIN
|
|
|
2515
2541
|
let n = e.split("/").pop() ?? e, r = t.split("/").pop() ?? t;
|
|
2516
2542
|
return n.localeCompare(r);
|
|
2517
2543
|
});
|
|
2518
|
-
},
|
|
2544
|
+
}, Sr = async (e) => {
|
|
2519
2545
|
let t = [];
|
|
2520
2546
|
for (let n of e) {
|
|
2521
2547
|
let e = (await import(ee(n).href)).default;
|
|
@@ -2529,11 +2555,11 @@ BEGIN
|
|
|
2529
2555
|
});
|
|
2530
2556
|
}
|
|
2531
2557
|
return t;
|
|
2532
|
-
},
|
|
2558
|
+
}, Cr = (e) => e`
|
|
2533
2559
|
SELECT ${e("id")}
|
|
2534
2560
|
FROM ${e("_voltro_migration_plans")}
|
|
2535
2561
|
WHERE ${e("source")} = 'file'
|
|
2536
|
-
`.pipe(d.map((e) => e.map((e) => e.id)), d.catchAll(() => d.succeed([]))),
|
|
2562
|
+
`.pipe(d.map((e) => e.map((e) => e.id)), d.catchAll(() => d.succeed([]))), wr = (e, t, n, r) => d.gen(function* () {
|
|
2537
2563
|
let i = Date.now(), a = (/* @__PURE__ */ new Date()).toISOString(), o = {
|
|
2538
2564
|
sql: e,
|
|
2539
2565
|
log: {
|
|
@@ -2566,9 +2592,9 @@ BEGIN
|
|
|
2566
2592
|
${r}, ${n}, ${"file"},
|
|
2567
2593
|
${c}, ${a}, ${t.migration.description})
|
|
2568
2594
|
`, { durationMs: c };
|
|
2569
|
-
}),
|
|
2595
|
+
}), Tr = (e, t) => d.gen(function* () {
|
|
2570
2596
|
let n = yield* d.tryPromise({
|
|
2571
|
-
try: () =>
|
|
2597
|
+
try: () => xr(g(t, "migrations")),
|
|
2572
2598
|
catch: (e) => e
|
|
2573
2599
|
});
|
|
2574
2600
|
if (n.length === 0) return {
|
|
@@ -2576,20 +2602,20 @@ BEGIN
|
|
|
2576
2602
|
skipped: []
|
|
2577
2603
|
};
|
|
2578
2604
|
let r = yield* d.tryPromise({
|
|
2579
|
-
try: () =>
|
|
2605
|
+
try: () => Sr(n),
|
|
2580
2606
|
catch: (e) => e
|
|
2581
2607
|
});
|
|
2582
2608
|
if (r.length === 0) return {
|
|
2583
2609
|
pending: [],
|
|
2584
2610
|
skipped: []
|
|
2585
2611
|
};
|
|
2586
|
-
let i = new Set(yield*
|
|
2612
|
+
let i = new Set(yield* Cr(e));
|
|
2587
2613
|
return {
|
|
2588
2614
|
pending: r.filter((e) => !i.has(e.migration.id)),
|
|
2589
2615
|
skipped: r.filter((e) => i.has(e.migration.id)).map((e) => e.migration.id)
|
|
2590
2616
|
};
|
|
2591
|
-
}),
|
|
2592
|
-
let { pending: n, skipped: r } = yield*
|
|
2617
|
+
}), Er = (e, t) => Tr(e, t).pipe(d.map((e) => e.pending.map((e) => e.migration.id))), Dr = (e, t) => d.gen(function* () {
|
|
2618
|
+
let { pending: n, skipped: r } = yield* Tr(e, t.projectRoot);
|
|
2593
2619
|
if (n.length === 0) return {
|
|
2594
2620
|
applied: [],
|
|
2595
2621
|
skipped: r
|
|
@@ -2603,7 +2629,7 @@ BEGIN
|
|
|
2603
2629
|
id: r.migration.id,
|
|
2604
2630
|
file: r.file
|
|
2605
2631
|
}));
|
|
2606
|
-
let { durationMs: n } = yield*
|
|
2632
|
+
let { durationMs: n } = yield* wr(e, r, t.env, t.appliedBy);
|
|
2607
2633
|
i.push({
|
|
2608
2634
|
id: r.migration.id,
|
|
2609
2635
|
durationMs: n
|
|
@@ -2620,18 +2646,18 @@ BEGIN
|
|
|
2620
2646
|
applied: i,
|
|
2621
2647
|
skipped: r
|
|
2622
2648
|
};
|
|
2623
|
-
}),
|
|
2649
|
+
}), Or = (e, t) => e`
|
|
2624
2650
|
SELECT ${e("id")}
|
|
2625
2651
|
FROM ${e("_voltro_migration_plans")}
|
|
2626
2652
|
WHERE ${e("id")} = ${t} AND ${e("source")} = 'file'
|
|
2627
2653
|
LIMIT 1
|
|
2628
|
-
`,
|
|
2629
|
-
if (!(yield*
|
|
2654
|
+
`, kr = (e, t) => d.gen(function* () {
|
|
2655
|
+
if (!(yield* Or(e, t.id))[0]) return yield* d.fail(/* @__PURE__ */ Error(`rollback: ${t.id} not found in _voltro_migration_plans (file source)`));
|
|
2630
2656
|
let n = yield* d.tryPromise({
|
|
2631
|
-
try: () =>
|
|
2657
|
+
try: () => xr(g(t.projectRoot, "migrations")),
|
|
2632
2658
|
catch: (e) => e
|
|
2633
2659
|
}), r = (yield* d.tryPromise({
|
|
2634
|
-
try: () =>
|
|
2660
|
+
try: () => Sr(n),
|
|
2635
2661
|
catch: (e) => e
|
|
2636
2662
|
})).find((e) => e.migration.id === t.id);
|
|
2637
2663
|
if (!r) return yield* d.fail(/* @__PURE__ */ Error(`rollback: file for migration ${t.id} not found on disk under ${t.projectRoot}/migrations/`));
|
|
@@ -2664,7 +2690,7 @@ BEGIN
|
|
|
2664
2690
|
} finally {
|
|
2665
2691
|
yield* E(e).pipe(d.orDie);
|
|
2666
2692
|
}
|
|
2667
|
-
}),
|
|
2693
|
+
}), Ar = (e) => d.gen(function* () {
|
|
2668
2694
|
let t = yield* p.SqlClient, n = yield* t`
|
|
2669
2695
|
SELECT id, fingerprint, appliedAt FROM _voltro_migration_plans
|
|
2670
2696
|
WHERE source = 'auto-diff'
|
|
@@ -2709,10 +2735,10 @@ BEGIN
|
|
|
2709
2735
|
snapshotFingerprint: e.fingerprint,
|
|
2710
2736
|
snapshotId: i
|
|
2711
2737
|
};
|
|
2712
|
-
}),
|
|
2738
|
+
}), jr = (e, ...t) => ({
|
|
2713
2739
|
_tag: "RawSqlFragment",
|
|
2714
2740
|
strings: [...e],
|
|
2715
2741
|
values: [...t]
|
|
2716
|
-
}),
|
|
2742
|
+
}), Mr = (e) => typeof e == "object" && !!e && e._tag === "RawSqlFragment";
|
|
2717
2743
|
//#endregion
|
|
2718
|
-
export { l as FILE_MIGRATION_PATTERN, it as REACTIVE_TRIGGER_PREFIX, te as VOLTRO_MIGRATION_LOCK_KEY, ft as _internalCmp, T as acquireMigrationLock, Ke as applyNamespacedSchema, ir as applyPlan, Be as applySchema, zt as chunkTables, F as declaredSnapshot, ve as defaultArrayClause, _e as defaultClause, k as defaultJsonClause,
|
|
2744
|
+
export { l as FILE_MIGRATION_PATTERN, it as REACTIVE_TRIGGER_PREFIX, te as VOLTRO_MIGRATION_LOCK_KEY, ft as _internalCmp, T as acquireMigrationLock, Ke as applyNamespacedSchema, ir as applyPlan, Be as applySchema, zt as chunkTables, F as declaredSnapshot, ve as defaultArrayClause, _e as defaultClause, k as defaultJsonClause, yr as describeOutcome, pr as destructiveScope, at as detectReactiveTriggerDrift, tn as emitDropColumnDdl, nn as emitDropColumnDdlMysql, ze as emitFrameworkBootstrapSql, Le as emitNamespaceProvisionDdl, Re as emitNamespacedSchemaSql, M as emitSchemaSql, N as fingerprintSchema, ot as formatReactiveTriggerDrift, fr as ignoreTablesFromEnv, Yt as introspectSchema, o as isFileMigration, Mr as isRawSqlFragment, Pt as mapPgType, s as migration, A as numericIdSql, Nt as parseEnumCheck, Er as pendingFileMigrationIds, Mt as planMigrations, qe as provisionTenantNamespace, E as releaseMigrationLock, gn as renderColumnMysql, pn as renderColumnPg, kr as rollbackFileBasedMigration, Dr as runFileBasedMigrations, Je as runFrameworkBootstrap, Ge as runMigrate, vr as runPlannedMigrations, P as shortFingerprint, et as snapshotColumn, jr as sql, O as sqlType, Ar as squashMigrationPlans, hr as unblockLossy, he as withMigrationLock };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@voltro/database",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"description": "Browser-safe schema DSL, query builder, and cross-dialect migration planner for Voltro — one schema, every SQL backend.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"voltro",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@effect/sql": "^0.51.1",
|
|
46
|
-
"@voltro/logger": "0.
|
|
46
|
+
"@voltro/logger": "0.15.0",
|
|
47
47
|
"typeid-js": "^1.2.0",
|
|
48
48
|
"ulidx": "^2.4.1"
|
|
49
49
|
},
|