@ultimat3/db 31.31.0 → 31.33.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/package.json +2 -2
- package/src/bound-parameters.ts +3 -2
- package/src/branch-errors.ts +2 -1
- package/src/catalog.ts +3 -2
- package/src/check-ddl.ts +7 -6
- package/src/client.ts +5 -3
- package/src/column-alter.ts +6 -4
- package/src/column-default.ts +8 -6
- package/src/drift-errors.ts +9 -6
- package/src/drift-findings.ts +7 -3
- package/src/errors.ts +1 -1
- package/src/index-ddl.ts +3 -1
- package/src/index-plan.ts +6 -4
- package/src/invariant-errors.ts +4 -3
- package/src/migration-errors.ts +18 -12
- package/src/pg-instant.ts +1 -0
- package/src/pglite-branch.ts +1 -0
- package/src/pglite-turns.ts +4 -2
- package/src/pool-profile.ts +4 -1
- package/src/replica-identity.ts +6 -4
- package/src/sql-noise.ts +1 -1
- package/src/sqlstate.ts +4 -1
- package/src/statement-shape.ts +1 -0
- package/src/statement-span.ts +4 -2
- package/src/type-pins.ts +9 -9
- package/src/ungeneratable.ts +6 -4
- package/src/unrendered.ts +6 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ultimat3/db",
|
|
3
|
-
"version": "31.
|
|
3
|
+
"version": "31.33.0",
|
|
4
4
|
"description": "Postgres access, transactions, migrations and drift detection",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ultimate",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"test": "bun test"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@ultimat3/core": "31.
|
|
48
|
+
"@ultimat3/core": "31.33.0"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
51
|
"@electric-sql/pglite": ">=0.5.0"
|
package/src/bound-parameters.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
// Single responsibility: every value of one statement, encoded into what `Bun.SQL` sends correctly.
|
|
2
|
+
//
|
|
2
3
|
// Two kinds need it, both measured against Postgres 17: a JS array (`array-parameter.ts`, #384),
|
|
3
4
|
// and a `Date` once the pool runs unnamed statements (`prepare: false`, `bun-sql.ts`) — with no
|
|
4
|
-
// described type to go by the driver sent `Date.prototype.toString()`, a local-zone string
|
|
5
|
-
//
|
|
5
|
+
// described type to go by the driver sent `Date.prototype.toString()`, a local-zone string Postgres
|
|
6
|
+
// refuses (`22007`), so every entity write carrying a timestamp failed.
|
|
6
7
|
|
|
7
8
|
import { instantText, pgArrayLiteral } from './array-parameter';
|
|
8
9
|
|
package/src/branch-errors.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
// Single responsibility: the two refusals `x db branch` raises — a branch that exists, and a name
|
|
2
2
|
// that is not one. Split from `errors.ts` at its line ceiling; `index.ts` re-exports both.
|
|
3
3
|
|
|
4
|
+
import { renderFixShellArg } from '@ultimat3/core';
|
|
4
5
|
import { DbError } from './errors';
|
|
5
6
|
|
|
6
7
|
export const branchExists = (branch: string): DbError =>
|
|
7
8
|
new DbError({
|
|
8
9
|
code: 'X_BRANCH_EXISTS',
|
|
9
10
|
cause: `database "${branch}" already exists`,
|
|
10
|
-
fix: `x db branch delete ${branch} # then re-create, or pick another name`,
|
|
11
|
+
fix: `x db branch delete ${renderFixShellArg(branch, '<branch>')} # then re-create, or pick another name`,
|
|
11
12
|
meta: { branch },
|
|
12
13
|
});
|
|
13
14
|
|
package/src/catalog.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
// Single responsibility: the SHAPE of a whole schema as the catalog holds it — every object kind
|
|
2
2
|
// the schema dump renders, in Postgres' own spelling. Distinct from `SchemaDescription`
|
|
3
3
|
// (`introspect.ts`) on purpose: that one is the entity vocabulary a snapshot is diffed in, and a
|
|
4
|
-
// catalog spelling can never compare equal to a generated one.
|
|
5
|
-
//
|
|
4
|
+
// catalog spelling can never compare equal to a generated one.
|
|
5
|
+
//
|
|
6
|
+
// This one is only ever compared to itself, which is why it may carry `pg_get_*def` text verbatim.
|
|
6
7
|
|
|
7
8
|
export interface CatalogExtension {
|
|
8
9
|
readonly name: string;
|
package/src/check-ddl.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
// Single responsibility: every CHECK constraint a table declares — a COLUMN's own and an
|
|
2
|
-
// INVARIANT's — and which of them a migration adds, rebuilds or drops.
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
// `
|
|
6
|
-
//
|
|
7
|
-
//
|
|
2
|
+
// INVARIANT's — and which of them a migration adds, rebuilds or drops.
|
|
3
|
+
//
|
|
4
|
+
// Split out of `generate.ts` and `invariant-ddl.ts` because a column check was the one part of a
|
|
5
|
+
// column that reached `create table` and nothing else: `columnClause` wrote `check (…)` inline and
|
|
6
|
+
// ANONYMOUS, `snapshotOf` recorded nothing for it and `diffTable` had no arm for it, so the SECOND
|
|
7
|
+
// `x db gen` turned `enumerated(POST_STATUSES)` into bare `text` accepting any string, and the
|
|
8
|
+
// value set the entity still declares left the database with no statement anywhere saying so.
|
|
8
9
|
//
|
|
9
10
|
// One list, for the reason `declaredIndexes` is one list: `createTable`, `diffTable` and
|
|
10
11
|
// `snapshotOf` must agree about what exists, and two producers of `add constraint` that never met
|
package/src/client.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
// Single responsibility: the pooled Postgres client and the ambient `db()` handle — the lazy
|
|
2
2
|
// connect, the reserved-connection pin, and the process-wide client every repository reaches
|
|
3
|
-
// through.
|
|
4
|
-
//
|
|
5
|
-
//
|
|
3
|
+
// through.
|
|
4
|
+
//
|
|
5
|
+
// Sizing lives in `pool-profile.ts`, the connection string in `connection-url.ts`, the `Bun.SQL`
|
|
6
|
+
// slice in `bun-sql.ts` and the observed statement funnel in `statement-funnel.ts`, so importing
|
|
7
|
+
// this module never opens a socket.
|
|
6
8
|
|
|
7
9
|
import { logger, type Role, resolveRole, type Scheduler } from '@ultimat3/core';
|
|
8
10
|
import {
|
package/src/column-alter.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
// Single responsibility: the attributes of an EXISTING column that move in place — its default, its
|
|
2
|
-
// collation and its nullability.
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
2
|
+
// collation and its nullability.
|
|
3
|
+
//
|
|
4
|
+
// Split from `generate.ts` because `diffTable` emitted SQL for a type change only: a changed or
|
|
5
|
+
// removed `.default()`, or a nullability change, emitted nothing while the snapshot beside it
|
|
6
|
+
// recorded the move, so `x verify` answered `X_DB_SCHEMA_UNMIGRATED` and its own fix, `x db gen`,
|
|
7
|
+
// produced an empty diff. A gate red forever, with the repair being the thing that failed.
|
|
6
8
|
|
|
7
9
|
import { defaultExpression, hasUnrenderedDefault } from './column-default';
|
|
8
10
|
import { columnDefaultUnsafe } from './ddl-errors';
|
package/src/column-default.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
// Single responsibility: what a column's DEFAULT is, as SQL. Split out of `generate.ts` because
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
1
|
+
// Single responsibility: what a column's DEFAULT is, as SQL. Split out of `generate.ts` because the
|
|
2
|
+
// question has two halves that must be answered together — what a declared default renders as, and
|
|
3
|
+
// what it MEANS when a column claims one this generator cannot write down.
|
|
4
|
+
//
|
|
5
|
+
// That second half had no answer at all until 2026-08-25: `hasDefault` reached the generator with
|
|
6
|
+
// no expression beside it, so nine scalar defaults in the reference app's own schema were dropped
|
|
7
|
+
// in silence and only `now()` and `gen_random_uuid()` survived, because those two are inferable
|
|
8
|
+
// from the kind.
|
|
7
9
|
|
|
8
10
|
import { assert } from '@ultimat3/core';
|
|
9
11
|
import { literal } from './sql';
|
package/src/drift-errors.ts
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
// Single responsibility: the `X_DB_DRIFT` constructor — the error form of the finding
|
|
2
2
|
// `drift-findings.ts`'s `unexpectedColumn` reports, thrown where a caller has no report to hand
|
|
3
|
-
// back.
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
// `errors.ts`,
|
|
3
|
+
// back.
|
|
4
|
+
//
|
|
5
|
+
// Split out of `errors.ts` for the import it needs and nothing else: the fix line puts a column
|
|
6
|
+
// name into a shell command, so it screens through `shellInertIdentifier` (`sql.ts`) — and `sql.ts`
|
|
7
|
+
// imports `errors.ts`, so this cannot live there without a cycle around the module whose evaluation
|
|
8
|
+
// registers every code. The code is still declared, titled and registered in `errors.ts`, exactly
|
|
9
|
+
// as `migration-errors.ts` and `invariant-errors.ts` are.
|
|
8
10
|
|
|
11
|
+
import { renderFixShellArg } from '@ultimat3/core';
|
|
9
12
|
import { DbError } from './errors';
|
|
10
13
|
import { shellInertIdentifier } from './sql';
|
|
11
14
|
|
|
@@ -36,6 +39,6 @@ export const dbDrift = (tableName: string, columnName: string): DbError =>
|
|
|
36
39
|
fix:
|
|
37
40
|
shellInertIdentifier(columnName) === null
|
|
38
41
|
? `x db gen "add the column named in this error" # its name carries shell syntax, so it is in the cause and not in this command; ${undeclaredColumnNext('it')}`
|
|
39
|
-
: `x db gen "add ${columnName}" # ${undeclaredColumnNext(columnName)}`,
|
|
42
|
+
: `x db gen "add ${renderFixShellArg(columnName, 'the undeclared column')}" # ${undeclaredColumnNext(columnName)}`,
|
|
40
43
|
meta: { table: tableName, column: columnName },
|
|
41
44
|
});
|
package/src/drift-findings.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// compares anything (`drift.ts` decides whether two schemas disagree). A `fix:` is ONE command a shell runs, and a difference names the declared
|
|
4
4
|
// side's spelling, never the catalog's — which is Postgres' rewriting.
|
|
5
5
|
|
|
6
|
+
import { isFixShellSafe, renderFixShellArg } from '@ultimat3/core';
|
|
6
7
|
import { psqlCommand } from './dependent-view';
|
|
7
8
|
import { undeclaredColumnNext } from './drift-errors';
|
|
8
9
|
import { addForeignKey, dropForeignKey, onDeleteRule, validateConstraint } from './foreign-key';
|
|
@@ -134,7 +135,7 @@ export function unexpectedColumn(table: string, column: string): DriftDifference
|
|
|
134
135
|
fix:
|
|
135
136
|
shellInertIdentifier(column) === null
|
|
136
137
|
? `x db gen "add the undeclared column" # the live column name carries shell syntax, so it is in the cause and not in this command; ${undeclaredColumnNext('it')}`
|
|
137
|
-
: `x db gen "add ${column}" # ${undeclaredColumnNext(column)}`,
|
|
138
|
+
: `x db gen "add ${renderFixShellArg(column, 'the undeclared column')}" # ${undeclaredColumnNext(column)}`,
|
|
138
139
|
};
|
|
139
140
|
}
|
|
140
141
|
|
|
@@ -240,8 +241,11 @@ export function unknownSchema(migrations: readonly Migration[]): DriftDifference
|
|
|
240
241
|
// identifier and a migration description is not one either, so neither has a quoted form that
|
|
241
242
|
// makes a hostile name safe. An EMPTY id is inert by construction and keeps its glob — that is
|
|
242
243
|
// "no migrations at all", not a name this function refused to spell.
|
|
244
|
+
// `isFixShellSafe` too, for the id: it is screened where it is spliced into the glob, and a
|
|
245
|
+
// screen answering its placeholder there would widen the glob to every snapshot in the tree.
|
|
243
246
|
const spellable =
|
|
244
|
-
(id === '' || shellInertIdentifier(id) !== null
|
|
247
|
+
(id === '' || (shellInertIdentifier(id) !== null && isFixShellSafe(id))) &&
|
|
248
|
+
shellInertIdentifier(name) !== null;
|
|
245
249
|
return {
|
|
246
250
|
kind: 'unknown-schema',
|
|
247
251
|
table: '',
|
|
@@ -254,7 +258,7 @@ export function unknownSchema(migrations: readonly Migration[]): DriftDifference
|
|
|
254
258
|
// fix pointed back here — a cycle a scaffolded app hit on its first `x db migrate`. The
|
|
255
259
|
// pathspec is a glob because this package is tier 1: only `@ultimat3/cli` knows the directory.
|
|
256
260
|
fix: spellable
|
|
257
|
-
? `git checkout -- "*${id}.snapshot.json" # or, if it was never written: ` +
|
|
261
|
+
? `git checkout -- "*${renderFixShellArg(id, '')}.snapshot.json" # or, if it was never written: ` +
|
|
258
262
|
`delete migration "${id}" and rerun x db gen "${name}"`
|
|
259
263
|
: 'git status --short -- "*.snapshot.json" # shows the sidecar that is gone: git ' +
|
|
260
264
|
'checkout it, or delete that migration and rerun x db gen with its description — the ' +
|
package/src/errors.ts
CHANGED
|
@@ -338,7 +338,7 @@ export const driverError = (statement: string, sourceError: unknown): DbError =>
|
|
|
338
338
|
fix:
|
|
339
339
|
state === SQLSTATE.idleInTransactionTimeout
|
|
340
340
|
? IDLE_IN_TRANSACTION_FIX
|
|
341
|
-
: code === 'X_DB_STATEMENT_FAILED'
|
|
341
|
+
: code === 'X_DB_STATEMENT_FAILED' || !Object.hasOwn(SQLSTATE_FIXES, code)
|
|
342
342
|
? `psql "$DATABASE_URL" -c "<the statement in cause>" # SQLSTATE ${state} is the server's verdict on it: fix the SQL or the data it names, not the connection`
|
|
343
343
|
: SQLSTATE_FIXES[code].replace('{constraint}', () => constraint ?? UNNAMED_CONSTRAINT),
|
|
344
344
|
meta: {
|
package/src/index-ddl.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// Single responsibility: the DDL an entity's INDEX declaration becomes — the `create index` a
|
|
2
2
|
// declaration writes out, what makes two definitions the same index, and what a moved definition
|
|
3
|
-
// rebuilds.
|
|
3
|
+
// rebuilds.
|
|
4
|
+
//
|
|
5
|
+
// Split out of `generate.ts` at the 500-line ceiling, along the seam `check-ddl.ts` and
|
|
4
6
|
// `generated-column.ts` already drew: `generate.ts` assembles a plan, this file writes the index
|
|
5
7
|
// statements it puts in it, and `invariant-ddl.ts` decides which indexes a table declares.
|
|
6
8
|
|
package/src/index-plan.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
// Single responsibility: which indexes an existing table gains, has rebuilt, or LOSES. Split out
|
|
2
|
-
//
|
|
1
|
+
// Single responsibility: which indexes an existing table gains, has rebuilt, or LOSES. Split out of
|
|
2
|
+
// `generate.ts` along the seam `check-ddl.ts` and `index-ddl.ts` already drew — `generate.ts`
|
|
3
3
|
// assembles a plan, `index-ddl.ts` writes the statements, and this file decides which of them go
|
|
4
|
-
// in.
|
|
5
|
-
//
|
|
4
|
+
// in.
|
|
5
|
+
//
|
|
6
|
+
// `checkPlan` is its shape, deliberately: "what does the record hold that the declaration does not"
|
|
7
|
+
// is one question, and a fourth spelling of it is the split axiom 1 refuses.
|
|
6
8
|
//
|
|
7
9
|
// The removal arm is why this file exists. `diffTable` walked `declaredIndexes(entity)` and matched
|
|
8
10
|
// by name, with no reverse pass, so an index the entities stopped declaring stayed on the database
|
package/src/invariant-errors.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
// Single responsibility: the two refusals an entity INVARIANT earns before its DDL exists — a name
|
|
2
2
|
// that cannot be an identifier, and a predicate holding a second command. Split out of `errors.ts`
|
|
3
3
|
// only because that file reached the 500-line ceiling; both carry `X_SQL_UNSAFE`, which
|
|
4
|
-
// `DB_OWNED_ERROR_CODES` there still declares and registers.
|
|
5
|
-
//
|
|
6
|
-
//
|
|
4
|
+
// `DB_OWNED_ERROR_CODES` there still declares and registers.
|
|
5
|
+
//
|
|
6
|
+
// No new code, and none is needed: an invariant name reaching a statement text is the same hazard a
|
|
7
|
+
// branch name or an isolation level is, and axiom 1 says one situation gets one code.
|
|
7
8
|
|
|
8
9
|
import { describeValue } from '@ultimat3/core';
|
|
9
10
|
import { DbError } from './errors';
|
package/src/migration-errors.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
// Single responsibility: the refusals a MIGRATION earns — the lock it could not take, a ledger that
|
|
2
2
|
// disagrees with this build, a plan that cannot be reversed, a plan that destroys rows without
|
|
3
|
-
// saying so, a snapshot never written, a view in a retype's way, a concurrent build.
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
3
|
+
// saying so, a snapshot never written, a view in a retype's way, a concurrent build.
|
|
4
|
+
//
|
|
5
|
+
// Split out of `errors.ts` only because that file reached the 500-line ceiling, exactly as
|
|
6
|
+
// `invariant-errors.ts` was: every code below is still declared, titled and registered there, and
|
|
7
|
+
// `DbError` is still the one class. One direction only — nothing here is imported back.
|
|
7
8
|
|
|
8
9
|
import { renderFixShellArg } from '@ultimat3/core';
|
|
9
10
|
import { DESTRUCTIVE_CAUSE, DESTRUCTIVE_MARKER, type DestructiveStatement } from './destructive';
|
|
@@ -76,12 +77,12 @@ export const rollbackStepsInvalid = (received: number): DbError =>
|
|
|
76
77
|
});
|
|
77
78
|
|
|
78
79
|
/**
|
|
79
|
-
* `packages/db/migrations/0000_initial.snapshot.json` → `packages/db/migrations/0000_initial
|
|
80
|
-
* every file that one migration owns,
|
|
81
|
-
* rather than rebuilt from a directory this package does not know:
|
|
82
|
-
* keeps its migrations is `@ultimat3/cli`'s answer, not this one's.
|
|
80
|
+
* `packages/db/migrations/0000_initial.snapshot.json` → `packages/db/migrations/0000_initial` —
|
|
81
|
+
* the stem every file that one migration owns shares, so `<stem>.*` is one `rm` argument. Derived
|
|
82
|
+
* from the path the caller passed rather than rebuilt from a directory this package does not know:
|
|
83
|
+
* `db` is tier 1 and where an app keeps its migrations is `@ultimat3/cli`'s answer, not this one's.
|
|
83
84
|
*/
|
|
84
|
-
const
|
|
85
|
+
const snapshotStem = (file: string): string => file.replace(/\.snapshot\.json$/, '');
|
|
85
86
|
|
|
86
87
|
/**
|
|
87
88
|
* `20260817120000_add_posts` → `add_posts`, the argument `x db gen` takes. The name is free text
|
|
@@ -114,7 +115,12 @@ export const migrationSnapshotMissing = (id: string, file: string): DbError => {
|
|
|
114
115
|
// rather than half of it being escaped — the same screen and the same degradation `unknownSchema`
|
|
115
116
|
// (`drift-findings.ts`) runs on the same condition. A `rm` whose argument was substituted away
|
|
116
117
|
// still reads as a command, and now removes something else.
|
|
117
|
-
|
|
118
|
+
// Each value below is screened where it is spliced as well, and `spellable` is what makes the
|
|
119
|
+
// screen's placeholder unreachable: a line is spelled whole or not at all.
|
|
120
|
+
const spellable =
|
|
121
|
+
shellSpellable(file) &&
|
|
122
|
+
shellSpellable(snapshotStem(file)) &&
|
|
123
|
+
shellSpellable(migrationNameOf(id));
|
|
118
124
|
return new DbError({
|
|
119
125
|
code: 'X_MIGRATION_SNAPSHOT_MISSING',
|
|
120
126
|
cause: `migration "${id}" records no schema snapshot (${file}), so there is nothing to diff against`,
|
|
@@ -124,8 +130,8 @@ export const migrationSnapshotMissing = (id: string, file: string): DbError => {
|
|
|
124
130
|
// the two errors pointed at each other and an app's first migration had no way out.
|
|
125
131
|
// `x db gen` is named only *after* the files it would trip over are gone.
|
|
126
132
|
fix: spellable
|
|
127
|
-
? `git checkout -- ${file} # or, if it was never written: ` +
|
|
128
|
-
`rm ${
|
|
133
|
+
? `git checkout -- ${renderFixShellArg(file, '')} # or, if it was never written: ` +
|
|
134
|
+
`rm ${renderFixShellArg(snapshotStem(file), '')}.* && x db gen "${renderFixShellArg(migrationNameOf(id), '')}"`
|
|
129
135
|
: 'restore the .snapshot.json committed beside this migration, or delete every file that ' +
|
|
130
136
|
'migration owns and rerun x db gen with its description — the file named in this ' +
|
|
131
137
|
"error's cause carries a backtick, a dollar sign, a quote, a backslash or whitespace, " +
|
package/src/pg-instant.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// Single responsibility: Postgres' TEXT form of `timestamptz` and `timestamp`, read as an instant.
|
|
2
|
+
//
|
|
2
3
|
// PGlite's own parser — and Bun.SQL's on the text protocol — read year `0099` as 1999, and under a
|
|
3
4
|
// session zone that is not UTC answered Invalid Date for an offset carrying seconds (local mean
|
|
4
5
|
// time before a zone's standard time: `-04:56:02`), which `@ultimat3/entity` then refused as
|
package/src/pglite-branch.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// validated before it ever reaches a path, and why the caller must have closed the source first:
|
|
4
4
|
// this copies files, it does not take a snapshot of a running instance.
|
|
5
5
|
|
|
6
|
+
// why: cp/rm recursive and an empty-directory mkdir — Bun copies and writes single files only.
|
|
6
7
|
import { cp, mkdir, rm, stat } from 'node:fs/promises';
|
|
7
8
|
import { basename, dirname, join } from 'node:path';
|
|
8
9
|
import { NotImplementedError, systemClock } from '@ultimat3/core';
|
package/src/pglite-turns.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
// Single responsibility: taking turns on PGlite's one connection. Embedded Postgres is a single
|
|
2
2
|
// session, not a pool, so two units of work that each `BEGIN` would be sharing one transaction —
|
|
3
3
|
// the second `COMMIT` commits the first's uncommitted rows and the first `ROLLBACK` finds nothing
|
|
4
|
-
// to undo.
|
|
5
|
-
//
|
|
4
|
+
// to undo.
|
|
5
|
+
//
|
|
6
|
+
// This queue makes them consecutive instead, which is what a pinned pool connection gives
|
|
7
|
+
// `withTransaction` and `readOnlyQuery` on a real server.
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
10
|
* Gives the connection back. `release()` is idempotent for free: it is a settled promise's
|
package/src/pool-profile.ts
CHANGED
|
@@ -116,7 +116,10 @@ export const POOL_PROFILES = Object.freeze<Record<Role, PoolProfile>>({
|
|
|
116
116
|
});
|
|
117
117
|
|
|
118
118
|
export function poolProfileFor(role: Role = resolveRole()): PoolProfile {
|
|
119
|
-
return POOL_PROFILES[role];
|
|
119
|
+
if (Object.hasOwn(POOL_PROFILES, role)) return POOL_PROFILES[role];
|
|
120
|
+
// Typed, and untyped at a JS caller: `POOL_PROFILES['constructor']` was the `Object` function,
|
|
121
|
+
// a pool with no `max`. Read as the env would be, a non-role is refused with `X_ROLE_INVALID`.
|
|
122
|
+
return poolProfileFor(resolveRole({ env: { ROLE: role } }));
|
|
120
123
|
}
|
|
121
124
|
|
|
122
125
|
/** The one pool knob an operator can turn without a rebuild. Layered over the role default. */
|
package/src/replica-identity.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
// Single responsibility: the `alter table … replica identity full` a live query needs, emitted
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
1
|
+
// Single responsibility: the `alter table … replica identity full` a live query needs, emitted
|
|
2
|
+
// once.
|
|
3
|
+
//
|
|
4
|
+
// `@ultimat3/realtime` refuses a subscription to a table without it — logical replication carries
|
|
5
|
+
// no old row on an UPDATE, so no patch can be computed — and which tables need it is a tier-3 fact
|
|
6
|
+
// no entity carries, so it arrives as `GenerateOptions.replicaIdentityFull` and is recorded on the
|
|
5
7
|
// snapshot: the record is what stops the statement being re-emitted on every `x db gen`.
|
|
6
8
|
|
|
7
9
|
import type { Plan } from './foreign-key-plan';
|
package/src/sql-noise.ts
CHANGED
package/src/sqlstate.ts
CHANGED
|
@@ -136,7 +136,10 @@ export const DB_SQLSTATE_CODES: Readonly<Record<string, DbSqlStateCode>> = Objec
|
|
|
136
136
|
*/
|
|
137
137
|
export function sqlStateCode(error: unknown): DbSqlStateCode | undefined {
|
|
138
138
|
const state = sqlState(error);
|
|
139
|
-
|
|
139
|
+
// A state the table does not classify — and never a prototype member — is unclassified.
|
|
140
|
+
return state === undefined || !Object.hasOwn(DB_SQLSTATE_CODES, state)
|
|
141
|
+
? undefined
|
|
142
|
+
: DB_SQLSTATE_CODES[state];
|
|
140
143
|
}
|
|
141
144
|
|
|
142
145
|
/** Whether re-running the whole transaction is the documented answer. `withTransaction`'s retry. */
|
package/src/statement-shape.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// writes, and the identity repeated statements are counted under. Two detectors above this package
|
|
3
3
|
// group statements by that identity (`x dev`'s ledger, the `statements` test fixture) and a third
|
|
4
4
|
// names spans from the same verb, so the rule lives once, next to the `DbStatementEvent` it reads.
|
|
5
|
+
//
|
|
5
6
|
// Nothing here counts anything: a threshold is a verdict's, and a verdict is `@ultimat3/entity`'s.
|
|
6
7
|
|
|
7
8
|
import type { DbStatementEvent } from '@ultimat3/core';
|
package/src/statement-span.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
// Single responsibility: what one statement is to the rest of the process — a `db.<verb>` client
|
|
2
2
|
// span carrying OTel's stable database attributes, opened for EVERY statement (production has DB
|
|
3
3
|
// spans, not only `x dev`), and one `db.statement` event on the instrumentation bus once it has
|
|
4
|
-
// settled.
|
|
5
|
-
//
|
|
4
|
+
// settled.
|
|
5
|
+
//
|
|
6
|
+
// Both drivers' funnels (`statement-funnel.ts`, `pglite.ts`) call `traceStatement` and nothing
|
|
7
|
+
// else, so the two cannot answer differently for the same statement.
|
|
6
8
|
|
|
7
9
|
import { instrument, SEMCONV, SEMCONV_VALUES, subscribed, withSpan } from '@ultimat3/core';
|
|
8
10
|
import { statementAttribution } from './attribution';
|
package/src/type-pins.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
// Compile-time pins for this package's disposable resources. Source, not a `.test.ts`, on
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
// a red test.
|
|
1
|
+
// Compile-time pins for this package's disposable resources. Source, not a `.test.ts`, on purpose:
|
|
2
|
+
// `tsconfig.json` excludes `src/**/*.test.ts`, so `tsc -b` never reads a test file and a type-level
|
|
3
|
+
// assertion written there can never fail. This module emits nothing and exports nothing anybody
|
|
4
|
+
// imports — a regression is a build error, the only enforcement that counts (axiom 3).
|
|
5
|
+
//
|
|
6
|
+
// `DbConnection` and `Turn` both went through a session where `release()`/`close()` left a resource
|
|
7
|
+
// cached or unreturned; the fix each time was RAII (`Disposable` + `using`), and this pin is what
|
|
8
|
+
// stops a future edit from quietly dropping `Disposable` off either interface — the one place a
|
|
9
|
+
// regression here would otherwise surface is a leaked connection under load, not a red test.
|
|
10
10
|
|
|
11
11
|
import type { DbConnection } from './client';
|
|
12
12
|
import type { Turn } from './pglite-turns';
|
package/src/ungeneratable.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
// Single responsibility: which statements in a migration's `up` half `x db gen` could never have
|
|
2
|
-
// written — the SQL a squash discards in silence.
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
2
|
+
// written — the SQL a squash discards in silence.
|
|
3
|
+
//
|
|
4
|
+
// `REPLICA IDENTITY FULL`, `CREATE EXTENSION`, a `GRANT`, a data backfill: none of them is a
|
|
5
|
+
// declaration, none reaches a `.snapshot.json`, and no declaration-based drift check can see them,
|
|
6
|
+
// because a regenerated sidecar equals the declaration by construction. The rail is the same shape
|
|
7
|
+
// `destructive.ts` is — statements in, statements out.
|
|
6
8
|
|
|
7
9
|
import { PARTITION_FUNCTION } from './generate-partition';
|
|
8
10
|
import { ROW_SECURITY_POLICY } from './row-security';
|
package/src/unrendered.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
// Single responsibility: what a generated migration declares it could NOT write, and how that
|
|
2
|
-
// reaches the file.
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
2
|
+
// reaches the file.
|
|
3
|
+
//
|
|
4
|
+
// A generator that silently emits less than the declaration is the defect this module exists
|
|
5
|
+
// against — ten invariants and nine defaults went missing between an entity and its own regenerated
|
|
6
|
+
// migration, and the `drift` gate step compares a source hash to a sidecar and never reads the SQL,
|
|
7
|
+
// so the loss was GREEN. A comment in the emitted `up` cannot be green.
|
|
6
8
|
|
|
7
9
|
import { assert } from '@ultimat3/core';
|
|
8
10
|
import { columnNamesConstraint } from './check-ddl';
|