@voltro/database 0.23.0 → 0.24.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 CHANGED
@@ -39,6 +39,117 @@ _Changes staged for the next release accumulate here (rolled up from
39
39
 
40
40
  ---
41
41
 
42
+ ## [0.24.0] — 2026-08-02
43
+
44
+ ### ⚠ BREAKING
45
+
46
+ - **@voltro/ai, @voltro/cli** — **`agent_threads` and `agent_messages` are `_voltro_agent_threads` and `_voltro_agent_messages`.** The last two framework-owned tables sitting in the user's namespace; the other ten moved in 0.22.0 and these were not in that set.
47
+
48
+ The collision it ends is the obvious half. The half that cost a consumer something is `versioningPlugin`: its "framework and plugin tables are out of the default" keys on the `_voltro_` prefix, so `agent_messages` was IN the default versioned set — and `runAssistant` patches the streaming assistant row about every 100 ms while it types. Under `timing: 'in-transaction'` that is a row-history write per throttle tick, on the hottest path in the app. They found it while adopting the versioning inversion and excluded both tables by hand; that `exclude:` entry can go now.
49
+
50
+ **The rows move themselves.** `.renamedFrom()` on both, so the next `db apply` or auto-migrate boot emits a catalog-only `ALTER TABLE … RENAME TO` on every dialect — no copy, no row rewrite. `AGENT_THREADS_TABLE` / `AGENT_MESSAGES_TABLE` are exported and carry the new names, and the synthesized `<agent>.messages` query moved with them, so typed code is unaffected.
51
+
52
+ The codemod is `manual` for the same reason the 0.22.0 one was: what a transform cannot see is raw SQL written by hand against those names.
53
+
54
+ ### Added
55
+
56
+ - **@voltro/plugin-auth** — Brute-force account lockout. After 5 failed credential attempts (wrong password OR wrong MFA code) within 15 minutes, sign-in for that email is refused with a `429 account_locked` for 15 minutes; a completed login clears the counter. The counter is keyed by email — an unknown address locks exactly like a real one, so the lock can't be used to probe which accounts exist. **On by default** (a security default); tune or disable via `authRoutesPlugin({ lockout: { maxAttempts, windowSeconds, lockSeconds } })`. Apps that spread `authTables` get the new `loginAttempts` table automatically on the next `voltro db apply` / `voltro dev` boot — it rides the declarative differ, no codemod.
57
+ - **@voltro/cli** — Backup provenance stamp. `voltro data backup` now writes a `voltro-backup-stamp.json` sidecar next to the native dump recording the dialect, the authoritative live-schema fingerprint, the `@voltro/cli` version, and the timestamp — a native `pg_dump`/`mariadb-dump` artifact is otherwise opaque about what it is. `voltro data restore` reads the stamp BEFORE touching the DB and acts on two failures that are silent until they corrupt: a CROSS-DIALECT restore (postgres dump into a mysql DB) is REFUSED (override with `--force`), and a SCHEMA/CODE fingerprint skew WARNS to run `voltro db apply` after the restore. A backup with no stamp (older/hand-made) restores with a caution, not a hard stop. Docs additionally clarify that point-in-time recovery (PITR) is a database/provider concern (WAL/binlog archiving) the framework deliberately does not reimplement, and that a backup you have never restored is a hypothesis. `codemod: none` — new CLI output + a restore-time guard; no user-authored code is affected.
58
+ - **@voltro/database, @voltro/sql-postgres, @voltro/runtime, @voltro/cli** — Per-statement query timeout via `DB_STATEMENT_TIMEOUT_MS` (or `ConnectionConfig.statementTimeoutMs`). A runaway query — a missing index, an accidental cartesian join — no longer pins a pooled connection indefinitely: it is cancelled once it outlasts the deadline, its connection returns to the pool, and the caller gets a normal error instead of a hang that, under load, exhausts the pool and stalls the whole app. Applies to the **runtime query path only** — migrations (`voltro db apply`) run legitimately long statements and are never cancelled by it. **Wired for postgres today** (the default dialect), where it maps to the server-side `statement_timeout` — a real server-enforced cancel (SQLSTATE `57014`), not a client-side disconnect that leaves the query running. Other dialects accept the field but currently ignore it (mssql's driver exposes no per-request timeout, MySQL/MariaDB's `max_execution_time` bounds SELECTs only, SQLite has no pool to protect). New `isQueryTimeout` classifier in `@voltro/runtime` recognises a timeout cancel across dialects. Off by default (unset = no timeout — unchanged behaviour). `codemod: none` — a new opt-in env var / config field; no user-authored code is affected.
59
+ - **@voltro/database, @voltro/cli** — Rolling-deploy safety classifier + `voltro db plan` advisory. A migration can be fully data-safe (every op auto-applies) and still break a zero-downtime rollout: during the overlap window old pods run the previous code against the already-migrated schema, so a dropped/renamed column, a narrowed type, or an added constraint makes those old pods 500 on reads or have their writes rejected. This is an axis ORTHOGONAL to the lossy/blocked data-safety gate — a `dropped()` column is blessed for data loss and still breaks an old reader.
60
+
61
+ `classifyRollingDeploySafety(op)` (a pure function in `@voltro/database`) returns a per-operation verdict with a reason + an expand/contract remedy; `voltro db plan` now lists the unsafe operations under a `⚠`, separately from the lossy/blocked summary. Advisory, NOT a refusal — the framework can't know the deploy strategy, and a maintenance-window / scale-to-zero deploy has no overlap window. The classifier is consumed by both the self-hosted advisory and (later) the cloud managed-hosting migration wall. Docs bless the expand/contract pattern. `codemod: none` — new API + CLI output only; no user-authored code is affected.
62
+ - **@voltro/runtime** — Configurable graceful-shutdown deadline via `VOLTRO_SHUTDOWN_GRACE_MS` (milliseconds, clamped to 1s–5min, default 10s). After `SIGTERM`/`SIGINT` the runtime runs its finalizers (connection-pool close, plugin `onDeactivate`, analytics flush, trace persist) and then exits — but installing the signal handler removes node's default kill, so a finalizer that never completes would otherwise hang the process forever; the deadline caps that. Operators set it to sit just under their orchestrator's hard kill (k8s `terminationGracePeriodSeconds` minus the preStop sleep, ECS `stopTimeout`) so the app drains and exits cleanly on its own before SIGKILL truncates it mid-drain. A non-numeric / non-positive value falls back to the 10s default (never a `NaN` deadline that fires immediately). `codemod: none` — a new opt-in env var; no user-authored code is affected.
63
+ - **@voltro/client, @voltro/runtime, @voltro/cli, @voltro/protocol** — WS-rpc mutation idempotency. A retried mutation carrying the same `idempotency-key` is deduplicated at the server: the first result is replayed and the handler does NOT run twice — so a network-blip retry, a reconnect resend, or (with a stable key) a double-click can't create a duplicate order / double charge. It reuses the same engine + `_voltro_idempotency` table as the REST path, so setting `idempotency` in `app.config.ts` now protects BOTH surfaces. `useMutation` / `useAction` mint a per-call key automatically and attach it to the rpc frame (over `RpcClient.currentHeaders`, merged with the auth headers) — pass `mutate(input, { idempotencyKey })` with a stable key for higher-level dedup. The key is scoped by `(tenant, subject, mutation)` so one subject's key can never replay for another, and the stored output is round-tripped through the mutation's output Schema so a `Date`-bearing replay reproduces the original exactly. Off by default (no `idempotency` config → no dedup). `@voltro/client` now peer-depends on `@effect/rpc` + `@effect/platform` (already transitive via `effect`).
64
+
65
+ ### Fixed
66
+
67
+ - **@voltro/runtime, @voltro/cli** — **A `*.schedule.ts` or `*.subscribe.ts` body written as an Effect silently did nothing.** Not "was rejected" — ran, recorded a success, and never executed.
68
+
69
+ ```ts
70
+ export const handler: ScheduleHandler = () =>
71
+ Effect.gen(function* () { yield* reconcileInvoices() }) // never ran
72
+ ```
73
+
74
+ Both call sites accepted the value and dropped it. `scheduler.ts` did `await def.handler(ctx)`, and an Effect is not a thenable, so `await` returned it unchanged. `subscriberRunner.ts` tested `result instanceof Promise`, which an Effect is not, so the branch was skipped. Neither raised anything. In an Effect-first framework the natural thing to write was the thing that quietly did nothing — worse than a type error, because a type error is visible.
75
+
76
+ Both handler types now accept sync, Promise **and** Effect forms, and one shared `settleHandlerBody` decides what a body IS, so the two call sites can no longer disagree about it. They keep their different DISPOSAL, deliberately: a schedule AWAITS its body (a firing that failed must not record as a success), a subscriber does not (a slow body must not back-pressure the change stream).
77
+
78
+ Reported four releases ago. It sat because it was listed as "open" at the bottom of a feedback round and never entered the backlog — the register that now holds that tail is `plans/open/framework/consumer-reported-tail.md`.
79
+ - **@voltro/plugin-auth** — **Brute-force lockout could be entirely inert, on by default, with nothing in the log to say so.** The postgres store fails OPEN on a store error — correct, a DB hiccup must not lock every user out of an app — but it failed open in silence: `recordLoginFailure` swallowed its write error, `isLockedOut` then read "not locked", and the security control that the release notes describe as **on by default** counted nothing at all.
80
+
81
+ The reachable case is not a hiccup. An app that enumerates its tables by hand instead of spreading `authTables` never migrates `loginAttempts`, so every write fails with `relation "loginAttempts" does not exist` — permanently, invisibly.
82
+
83
+ Behaviour is unchanged: still open, still no throw into the login flow. What is new is that each failure logs `[auth] lockout … failed — brute-force protection is not counting`, which also separates the two cases by hand: a transient error logs once, a missing table logs on every failed sign-in.
84
+
85
+ Found by the release gate, and the finding is uncomfortable in a useful way — the contract suite that runs against a LIVE postgres had been extended for lockout, and its hand-written fixture DDL was never given the new table. The fail-open then converted "relation does not exist" into a plain assertion failure, which is the only reason it was visible at all. The fixture now asserts that it covers every table the plugin declares, in both directions, and that assertion runs without postgres so the drift cannot be introduced on a machine where the pg half skips.
86
+ - **@voltro/cli, @voltro/database** — **`voltro db apply` now installs the change triggers the boot diagnostic tells you to install.** It did not, and said it did.
87
+
88
+ 0.23.0 added a check that compares declared reactivity against the triggers actually in the database, and it works — a consumer's first boot on 0.23.0 reported 500 of their 525 tables as having no change trigger. The remedy it named was `voltro db apply`, and `db apply` answered:
89
+
90
+ ```text
91
+ schema diff: 0 operations, 0 blocked
92
+ (schema is up to date)
93
+ db apply: schema is up to date — nothing to apply
94
+ ```
95
+
96
+ Both were telling the truth. Reactive triggers are emitted only by the two FULL-schema emitters — the CREATE-everything path for a fresh database, and the framework bootstrap — so every table an existing app has added through the PLANNER since it was created never got one. The planner has no trigger dimension to notice with, so `db plan` correctly reports zero operations while 500 tables sit untriggered. Their database had 27 triggers, all 27 on framework tables.
97
+
98
+ The consequence is the one the diagnostic describes: a single instance is unaffected (its own writes reach its own subscribers in-process), so this stays invisible until you scale out, and then subscriptions quietly stop seeing other instances' writes.
99
+
100
+ `db apply` and `db apply --plan` now converge triggers as an explicit, reported step — **including when the schema diff is empty**, which is not an edge case here but the reported one. It is deliberately NOT a planner operation: a trigger carries no data, its DDL is idempotent, and it is derived entirely from `isReactive`, so it converges rather than diffs.
101
+
102
+ **A second defect found while fixing the first: a custom `cdcChannel` made the check report every reactive table as missing.** The detector derived the trigger name itself (`framework_changes_<table>`) while the emitter puts the channel in the name on any non-default channel — two derivations of one name, disagreeing exactly where nobody looks. They read one function now.
103
+
104
+ Also: **`_voltro_schedule_claims` had no retention.** One row per (schedule, minute-bucket), append-only, and the only table of its family without a sweep — `_voltro_schedule_runs` (the OUTCOME of a firing) had one; its coordination twin (the RACE for the same firing) did not. Measured by the same consumer at 35,128 rows in 14 days across 31 schedules. Now pruned at 30 days by default (`VOLTRO_SCHEDULE_CLAIMS_TTL_HOURS`), which is safe because a claim only ever answers a question about one minute bucket and the scheduler asks about the current one.
105
+ - **@voltro/cli, @voltro/database** — **`voltro serve` could not boot from its own bundle on any app with binlog CDC enabled**, and reported it as a build problem.
106
+
107
+ ```text
108
+ [voltro] serve bundle failed to load: n7 is not a constructor
109
+ [voltro] FATAL: production `voltro serve` requires a precompiled serve bundle …
110
+ Run `voltro build` before serving
111
+ ```
112
+
113
+ The bundle was neither missing nor unloadable. `@vlasky/zongji` — the binlog reader — sat on `NATIVE_RUNTIME_LEAVES`, the list of packages routed through a runtime CJS shim instead of being inlined, under a comment describing it as a leaf with "a compiled `.node` binding". It has none: it is a pure-JS ESM package. Through the shim its consumer broke, from the opposite direction to the `pg` regression the same list already documents — the shim's `module.exports` IS the ESM namespace `{ default: ctor }`, esbuild's `__toESM` wraps it again, and `(await import('@vlasky/zongji')).default` came back as the namespace object. Measured both ways:
114
+
115
+ ```text
116
+ shimmed: typeof mod.default === 'object' → `is not a constructor`
117
+ inlined: typeof mod.default === 'function' → constructs
118
+ ```
119
+
120
+ Inlining it removes the shim's interop from the path. A new guard asserts the RULE rather than the list: every entry on `NATIVE_RUNTIME_LEAVES` must actually carry a compiled binding, or be one of the two documented dynamic-import cases.
121
+
122
+ **And the message that hid it is fixed.** The launcher wrapped the bundle's IMPORT and its RUN in one `try`, so every runtime fault the app's boot could raise came out as "serve bundle failed to load … Run `voltro build`", with the stack discarded. The reporter had just run it. The two are separated now: an import that throws is still a build problem, and an import that succeeds followed by a `runServe` throw is reported as itself, with its stack, and does not fall through to a second execution path.
123
+
124
+ **`voltro db files` ran a migration and could not record it, on MariaDB.** The file-migration writer passed an ISO-8601 string into `_voltro_migration_plans.appliedAt`, a `DATETIME`, which MariaDB rejects (`ER_TRUNCATED_WRONG_VALUE`). The INSERT runs AFTER `up()`, so the side effects landed and the bookkeeping did not: a probe migration inserting one row grew 1 → 2 → 3 → 4 across four invocations with zero `source='file'` ledger entries, and the deploy could never complete — `db apply` refuses while a file migration is pending and nothing could ever record it.
125
+
126
+ The PLANNER's writer had the conversion, inline, with a comment describing this exact rejection. The file writer was a second copy without it, so the common path worked and the escape hatch was broken exactly where it is reached for. One `appliedAtValue` now, shared, covered against a live MariaDB. A ledger write that fails after a successful `up()` also gets its own error type: the recovery is the opposite of the ordinary one — do NOT re-run — and it used to surface as a generic `Failed to execute statement`.
127
+
128
+ **`voltro build` never removed output from earlier builds.** Content-hashed chunks mean every build writes new names and nothing overwrites the old ones; nothing reads them either, so they accumulate and ship in the image. Measured by a consumer at 11,048 files where a clean build produces 2,131. Now pruned after the build, keyed on mtime — deliberately not a wipe before it, which opens a window in which the bundle does not exist.
129
+
130
+ **A completed drain now says so** (`drained in 80ms`), and one cut at the deadline says that instead. Previously the only trace of either was whatever a shutdown hook happened to log, so "drained in 80 ms" and "was cut at 10 s" looked identical.
131
+ - **@voltro/runtime** — **A request the SSRF policy blocks is now a catchable failure instead of an uncatchable defect.**
132
+
133
+ It was `Effect.die(new SsrfBlockedError(...))`. A blocked outbound request is a decision the policy made about a URL the CALLER supplied — and as a defect the caller could not do anything about it: the fiber collapsed, it surfaced as an untagged 500, and a handler that wanted to fall back to a queue, return a typed error to the client, or skip an optional enrichment had no way to.
134
+
135
+ It rides inside `HttpClientError.RequestError` rather than being raised on its own, because `HttpClient.HttpClient`'s error channel IS `HttpClientError` — failing with a foreign type would not typecheck for any consumer. So `catchTag('RequestError')` and `catchAll` both see it, `description` names the policy, and the `SsrfBlockedError` survives as `cause` for a caller that wants the specific reason.
136
+
137
+ Not breaking: the error channel already carried `HttpClientError`. What changed is that the failure now arrives on it.
138
+
139
+ Reported three releases ago. It sat because it was listed as open at the bottom of a feedback round and never entered the backlog — see `plans/open/framework/consumer-reported-tail.md`.
140
+
141
+ ### Internal (no consumer-facing effect)
142
+
143
+ - **@voltro/database** — `VOLTRO_SOFT_DROP=1` convergence is now proven against a live postgres, not argued.
144
+
145
+ The planner-side fix — treating `<name>__dropped_<YYYYMMDDHHMMSS>` as framework-managed so an undeclared snapshot is never re-proposed for dropping — shipped some releases ago. What never existed was the assertion, and a consumer had told us so: *"still not testable from a host without the DB"*. That was their constraint, read as ours. The docker stack is exactly what it needed.
146
+
147
+ The test soft-drops a COLUMN and a TABLE for real, asserts the data survives under the snapshot name, and asserts the **re-plan is EMPTY** — the property, not the statements. Verified red by disabling the planner's snapshot awareness: both cases then die in `applyPlan`'s convergence check, which is the original defect.
148
+
149
+ Two harness mistakes are recorded in the file because each produced a failure that reads exactly like the framework defect under test: an unscoped re-plan against a SHARED database proposes dropping every table in it, and a file-wide scope puts the first test's table into the second test's residue.
150
+
151
+ ---
152
+
42
153
  ## [0.23.0] — 2026-08-02
43
154
 
44
155
  ### ⚠ BREAKING
package/dist/index.d.ts CHANGED
@@ -1404,6 +1404,31 @@ export declare interface ConnectionConfig {
1404
1404
  */
1405
1405
  readonly ssl?: boolean;
1406
1406
  readonly maxConnections?: number;
1407
+ /**
1408
+ * Per-statement timeout in ms — a runaway query (missing index, cartesian
1409
+ * join) is aborted instead of holding a pooled connection forever, which under
1410
+ * load exhausts the pool and stalls the whole app. Applied at the CONNECTION
1411
+ * level so every query is bounded (no per-call opt-in). Env `DB_STATEMENT_TIMEOUT_MS`.
1412
+ * Runtime-path only — the migration path (`voltro db apply`) deliberately does
1413
+ * NOT read this, so a long backfill / index build is never cancelled by the app
1414
+ * query ceiling.
1415
+ *
1416
+ * **Wired for postgres only** (the default dialect), enforced server-side via
1417
+ * node-postgres' `statement_timeout` pool option — a runaway query is cancelled
1418
+ * with SQLSTATE 57014, not merely disconnected. Every OTHER dialect currently
1419
+ * ACCEPTS the field but IGNORES it, and the honest reasons differ:
1420
+ * - **mssql** — `@effect/sql-mssql` exposes only `connectTimeout` (connection
1421
+ * establishment), not tedious's per-request `requestTimeout`; mapping this
1422
+ * onto `connectTimeout` would bound the wrong phase, so it is left unwired
1423
+ * rather than wrong.
1424
+ * - **mysql/mariadb** — the server's `max_execution_time` bounds SELECTs only
1425
+ * (writes run unbounded), so a connection-level setting would be a partial,
1426
+ * misleading guarantee; not wired in V1.
1427
+ * - **sqlite** — in-process, one connection, no pool to exhaust; nothing to
1428
+ * protect.
1429
+ * Unset (or any non-postgres dialect) = no timeout — behaviour is unchanged.
1430
+ */
1431
+ readonly statementTimeoutMs?: number;
1407
1432
  /**
1408
1433
  * Postgres only: the schema the app's tables live in, pinned as the
1409
1434
  * connection `search_path` (env `DB_SCHEMA`). When set, EVERY pooled
package/dist/sql.d.ts CHANGED
@@ -190,6 +190,28 @@ export declare type BootMigrationOutcome = {
190
190
  * producing a complete, non-overlapping partition of the table list. */
191
191
  export declare const chunkTables: <T>(xs: ReadonlyArray<T>, n: number) => T[][];
192
192
 
193
+ /**
194
+ * Classify a single DDL operation for rolling-deploy safety.
195
+ *
196
+ * UNSAFE (breaks old code during the overlap window):
197
+ * - `drop-column` / `drop-table` — old code reads it → error.
198
+ * - `rename-column` / `rename-table` — to old code the old name vanished.
199
+ * - `alter-column-type` — old reads may fail to decode, old writes may be
200
+ * rejected by the new type; even a "widening" is risky to assume.
201
+ * - `alter-column-nullability` → NOT NULL — old code that inserts without the
202
+ * column (or with NULL) is now rejected.
203
+ * - `add-unique` / `add-unique-composite` / `add-check` / `add-foreign-key`
204
+ * — a constraint old writes may violate the instant it exists.
205
+ *
206
+ * SAFE (old code keeps working):
207
+ * - `create-table` / `add-column` (nullable or defaulted) / `add-index` —
208
+ * additive; old code doesn't see it.
209
+ * - `drop-index` / `drop-unique*` / `drop-check` / `drop-foreign-key` —
210
+ * removing enforcement never makes an old query ERROR.
211
+ * - `alter-column-nullability` → nullable, `alter-column-default` — relaxing.
212
+ */
213
+ export declare const classifyRollingDeploySafety: (op: MigrationOperation) => RollingDeploySafety;
214
+
193
215
  declare interface ColumnDefinition<TsType, Type extends ColumnType = ColumnType, HasDefault extends boolean = boolean> {
194
216
  readonly type: Type;
195
217
  readonly nullable: boolean;
@@ -712,10 +734,7 @@ declare type ColumnType = 'id' | 'text' | 'integer' | 'real' | 'decimal' | 'bigi
712
734
  */
713
735
  export declare const declaredSnapshot: (tables: ReadonlyArray<TableLike>, dialect?: DialectId) => SchemaSnapshot;
714
736
 
715
- /** The NOTIFY channel a schema emits on when none is configured. Exported so
716
- * the store and the DDL cannot drift: they must agree, and before this they
717
- * did not — the store read `options.cdcChannel` while the trigger hardcoded
718
- * the default, so any custom channel listened to silence. */
737
+ /** The NOTIFY channel a schema emits on when none is configured. */
719
738
  export declare const DEFAULT_CDC_CHANNEL = "framework_changes";
720
739
 
721
740
  /**
@@ -769,7 +788,11 @@ export declare const destructiveScope: (raw: string | undefined) => {
769
788
  export declare const detectReactiveTriggerDrift: (sql: SqlClient.SqlClient, tables: ReadonlyArray<{
770
789
  readonly tableName: string;
771
790
  readonly isReactive?: boolean;
772
- }>) => Effect.Effect<ReactiveTriggerDrift, SqlError_2>;
791
+ }>,
792
+ /** The app's `cdcChannel`. Part of the trigger NAME on any non-default
793
+ * channel, so omitting it here reported every table as missing on a database
794
+ * where every trigger was present. */
795
+ channel?: string) => Effect.Effect<ReactiveTriggerDrift, SqlError_2>;
773
796
 
774
797
  /** Dialect IDs the framework supports. */
775
798
  declare type DialectId = 'postgres' | 'mysql' | 'mariadb' | 'mssql' | 'sqlite' | 'turso';
@@ -938,6 +961,21 @@ export declare interface FileMigrationContext {
938
961
  readonly appliedAt: string;
939
962
  }
940
963
 
964
+ /**
965
+ * A migration whose `up()` SUCCEEDED and whose ledger row could not be written.
966
+ *
967
+ * Its own error type because the recovery is the opposite of the ordinary one:
968
+ * do NOT re-run. The change has landed; what is missing is the record that says
969
+ * so, and every future invocation will apply it again until that row exists.
970
+ */
971
+ export declare class FileMigrationLedgerError extends Error {
972
+ readonly migrationId: string;
973
+ readonly file: string;
974
+ readonly cause: unknown;
975
+ readonly _tag = "FileMigrationLedgerError";
976
+ constructor(migrationId: string, file: string, cause: unknown);
977
+ }
978
+
941
979
  export declare interface FileMigrationRunResult {
942
980
  readonly applied: ReadonlyArray<{
943
981
  id: string;
@@ -1565,7 +1603,7 @@ export declare interface RawSqlFragment {
1565
1603
  readonly dependsOn?: ReadonlyArray<string>;
1566
1604
  }
1567
1605
 
1568
- /** Prefix `reactiveTableTriggerSql` names its triggers with. */
1606
+ /** Prefix every reactive trigger name starts with, whatever the channel. */
1569
1607
  export declare const REACTIVE_TRIGGER_PREFIX = "framework_changes_";
1570
1608
 
1571
1609
  export declare interface ReactiveTriggerDrift {
@@ -1576,6 +1614,39 @@ export declare interface ReactiveTriggerDrift {
1576
1614
  readonly stale: ReadonlyArray<string>;
1577
1615
  }
1578
1616
 
1617
+ /**
1618
+ * The statements that bring the DATABASE's change triggers back in line with
1619
+ * what the schema declares.
1620
+ *
1621
+ * This exists because the diff could not do it and said it could. Reactive
1622
+ * triggers are emitted only by the two full-schema emitters — the CREATE-
1623
+ * everything path for a fresh database, and the framework bootstrap — so a
1624
+ * table that arrived through the PLANNER (every table an existing app has
1625
+ * added since it was created) never got one. The planner has no trigger
1626
+ * dimension at all, so `db plan` reports 0 operations and `db apply` reports
1627
+ * "schema is up to date" while the drift detector is simultaneously telling
1628
+ * you 500 tables have no trigger, and pointing at `voltro db apply` as the
1629
+ * remedy. Reported by a consumer with 525 tables and 27 triggers, all 27 on
1630
+ * framework tables.
1631
+ *
1632
+ * A single instance is unaffected — its own writes reach its own subscribers
1633
+ * through the in-process path — so this is invisible until you scale out, which
1634
+ * is the worst possible time to find it.
1635
+ *
1636
+ * Postgres only: it is the one dialect where reactivity is carried by DDL. The
1637
+ * binlog / Change Tracking readers are configured at runtime from the same
1638
+ * in-memory table list, so they cannot drift from it.
1639
+ */
1640
+ export declare const reactiveTriggerRepairSql: (input: {
1641
+ readonly tables: ReadonlyArray<AnyTable>;
1642
+ readonly dialect: DialectId;
1643
+ /** Table names the detector found reactive-but-untriggered. */
1644
+ readonly missing: ReadonlyArray<string>;
1645
+ /** Table names the detector found triggered-but-declared-nonReactive. */
1646
+ readonly stale: ReadonlyArray<string>;
1647
+ readonly channel?: string;
1648
+ }) => ReadonlyArray<string>;
1649
+
1579
1650
  export declare const releaseMigrationLock: (sql: SqlClient.SqlClient) => Effect.Effect<void, SqlError_2>;
1580
1651
 
1581
1652
  export declare const renderColumnMysql: (col: ColumnSnapshot) => string;
@@ -1600,6 +1671,27 @@ export declare const rollbackFileBasedMigration: (sql: SqlClient.SqlClient, ctx:
1600
1671
  durationMs: number;
1601
1672
  }, unknown>;
1602
1673
 
1674
+ /** Verdict for one operation under a rolling deploy. */
1675
+ export declare type RollingDeploySafety = {
1676
+ readonly safe: true;
1677
+ } | {
1678
+ readonly safe: false;
1679
+ /** Why an instance on the OLD code breaks against the new schema. */
1680
+ readonly reason: string;
1681
+ /** The expand/contract move that keeps both code versions working. */
1682
+ readonly remedy: string;
1683
+ };
1684
+
1685
+ /**
1686
+ * The rolling-deploy-unsafe operations in a plan, each paired with its verdict.
1687
+ * Empty ⇒ the whole plan is safe to apply while an old deploy is still live.
1688
+ */
1689
+ export declare const rollingDeployUnsafeOps: (operations: ReadonlyArray<PlannedOperation>) => ReadonlyArray<{
1690
+ readonly op: PlannedOperation;
1691
+ readonly reason: string;
1692
+ readonly remedy: string;
1693
+ }>;
1694
+
1603
1695
  export declare const runFileBasedMigrations: (sql: SqlClient.SqlClient, ctx: RunFileBasedMigrationsCtx) => Effect.Effect<FileMigrationRunResult, unknown>;
1604
1696
 
1605
1697
  export declare interface RunFileBasedMigrationsCtx {