@ultimat3/db 31.35.0 → 31.36.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/branch.ts +3 -1
- package/src/connection-url.ts +1 -3
- package/src/ddl-errors.ts +5 -3
- package/src/drift-findings.ts +3 -9
- package/src/errors.ts +7 -8
- package/src/listen.ts +1 -1
- package/src/migration-errors.ts +3 -9
- package/src/object-drift.ts +1 -3
- package/src/unrendered.ts +2 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ultimat3/db",
|
|
3
|
-
"version": "31.
|
|
3
|
+
"version": "31.36.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.36.0"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
51
|
"@electric-sql/pglite": ">=0.5.0"
|
package/src/branch.ts
CHANGED
|
@@ -136,7 +136,9 @@ export async function dropBranch(
|
|
|
136
136
|
throw new DbError({
|
|
137
137
|
code: 'X_BRANCH_EXISTS',
|
|
138
138
|
cause: `"${branch}" is the database this session is connected to, so it cannot be dropped`,
|
|
139
|
-
|
|
139
|
+
// Read-only first: `x db branch delete` takes the SHORT name, which the list shows, and it
|
|
140
|
+
// must run from a session on the base database — a raw `drop database` skips both checks.
|
|
141
|
+
fix: 'x db branch list --json # its short name; then, with DATABASE_URL on the base database: x db branch delete <that name>',
|
|
140
142
|
meta: { branch },
|
|
141
143
|
});
|
|
142
144
|
}
|
package/src/connection-url.ts
CHANGED
|
@@ -45,9 +45,7 @@ const schemeUnsupported = (raw: string): DbError =>
|
|
|
45
45
|
cause:
|
|
46
46
|
'DATABASE_URL does not name a postgres:// or postgresql:// url: ' +
|
|
47
47
|
`received ${describeValue(raw)}`,
|
|
48
|
-
fix:
|
|
49
|
-
'set DATABASE_URL to postgres://user@host:5432/database — a value with no scheme parses ' +
|
|
50
|
-
'as a url whose scheme is its own first token — or run `x dev` to use the embedded PGlite',
|
|
48
|
+
fix: 'DATABASE_URL=postgres://user@host:5432/database # a value with no scheme parses as a url whose scheme is its own first token — or run `x dev` to use the embedded PGlite',
|
|
51
49
|
});
|
|
52
50
|
|
|
53
51
|
export function connectionUrl(options: ConnectionUrlOptions, profile: PoolProfile): string {
|
package/src/ddl-errors.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// is at its ceiling — `invariant-errors.ts`' reason. All three are `X_SQL_UNSAFE`, declared there:
|
|
4
4
|
// an unchecked operand reaching statement text is one situation, and axiom 1 gives it one code.
|
|
5
5
|
|
|
6
|
-
import { describeValue } from '@ultimat3/core';
|
|
6
|
+
import { describeValue, renderFixShellArg } from '@ultimat3/core';
|
|
7
7
|
import { DbError } from './errors';
|
|
8
8
|
|
|
9
9
|
/**
|
|
@@ -54,7 +54,7 @@ export const generatedExpressionUnsafe = (column: string, count: number): DbErro
|
|
|
54
54
|
new DbError({
|
|
55
55
|
code: 'X_SQL_UNSAFE',
|
|
56
56
|
cause: `the expression of generated column "${column}" holds ${count} commands; a generated column is one expression`,
|
|
57
|
-
fix: `
|
|
57
|
+
fix: `generated: 'lower("title")' // "${column}" gets a single expression, or .searchable() — then x db gen`,
|
|
58
58
|
meta: { column, count },
|
|
59
59
|
});
|
|
60
60
|
|
|
@@ -67,6 +67,8 @@ export const columnDefaultUnsafe = (column: string, count: number): DbError =>
|
|
|
67
67
|
new DbError({
|
|
68
68
|
code: 'X_SQL_UNSAFE',
|
|
69
69
|
cause: `the default of column "${column}" holds ${count} commands; a default is one expression`,
|
|
70
|
-
|
|
70
|
+
// The edit leads: a blanket `git checkout` of every snapshot would also discard a new
|
|
71
|
+
// migration's uncommitted one. Restoring a hand-edited snapshot names that one file.
|
|
72
|
+
fix: `grep -rn ${renderFixShellArg(column, '<column>')} --include=entity.ts . # give that column a single .default(<one expression>); a hand-edited snapshot is restored by checking out that one .snapshot.json; then: x db gen`,
|
|
71
73
|
meta: { column, count },
|
|
72
74
|
});
|
package/src/drift-findings.ts
CHANGED
|
@@ -218,9 +218,7 @@ export function unexpectedTable(schema: string, table: string): DriftDifference
|
|
|
218
218
|
`inspect the table this difference names with \\d, then claim it in a migration ` +
|
|
219
219
|
'with create table if not exists or drop it',
|
|
220
220
|
)
|
|
221
|
-
: `${psqlCommand(`\\d ${name}`)} # nothing declares it: put create table if not exists
|
|
222
|
-
`${spoken} (…) in a migration, then x db migrate — or, if nothing owns it, run ` +
|
|
223
|
-
`drop table ${spoken}; here`,
|
|
221
|
+
: `${psqlCommand(`\\d ${name}`)} # nothing declares it: put create table if not exists ${spoken} (…) in a migration, then x db migrate — or, if nothing owns it, run drop table ${spoken}; here`,
|
|
224
222
|
};
|
|
225
223
|
}
|
|
226
224
|
|
|
@@ -258,12 +256,8 @@ export function unknownSchema(migrations: readonly Migration[]): DriftDifference
|
|
|
258
256
|
// fix pointed back here — a cycle a scaffolded app hit on its first `x db migrate`. The
|
|
259
257
|
// pathspec is a glob because this package is tier 1: only `@ultimat3/cli` knows the directory.
|
|
260
258
|
fix: spellable
|
|
261
|
-
? `git checkout -- "*${renderFixShellArg(id, '')}.snapshot.json" # or, if it was never written: `
|
|
262
|
-
|
|
263
|
-
: 'git status --short -- "*.snapshot.json" # shows the sidecar that is gone: git ' +
|
|
264
|
-
'checkout it, or delete that migration and rerun x db gen with its description — the ' +
|
|
265
|
-
"migration named in this difference's cause carries a backtick, a dollar sign, a " +
|
|
266
|
-
'quote, a backslash or whitespace in its file name, so no command here can spell it',
|
|
259
|
+
? `git checkout -- "*${renderFixShellArg(id, '')}.snapshot.json" # or, if it was never written: delete migration "${id}" and rerun x db gen "${name}"`
|
|
260
|
+
: `git status --short -- "*.snapshot.json" # shows the sidecar that is gone: git checkout it, or delete that migration and rerun x db gen with its description — the migration named in this difference's cause carries a backtick, a dollar sign, a quote, a backslash or whitespace in its file name, so no command here can spell it`,
|
|
267
261
|
};
|
|
268
262
|
}
|
|
269
263
|
|
package/src/errors.ts
CHANGED
|
@@ -234,7 +234,7 @@ export const dbUnavailable = (detail: string, sourceError?: unknown): DbError =>
|
|
|
234
234
|
// The driver's own words ride along when there are any: `ECONNREFUSED 127.0.0.1:5432` is the
|
|
235
235
|
// half of "cannot reach the database" an operator acts on, and it was dropped on the floor.
|
|
236
236
|
cause: sourceError === undefined ? detail : `${detail}: ${renderThrowable(sourceError)}`,
|
|
237
|
-
fix: '
|
|
237
|
+
fix: 'DATABASE_URL=postgres://user@host:5432/database # a reachable Postgres url — or run `x dev` to use the embedded PGlite',
|
|
238
238
|
sourceError,
|
|
239
239
|
});
|
|
240
240
|
|
|
@@ -288,7 +288,7 @@ const UNNAMED_CONSTRAINT = 'the constraint named in cause';
|
|
|
288
288
|
* Every driver failure, typed by what the server actually said. The SQLSTATE has always been on
|
|
289
289
|
* the error — `isLedgerMissing` proved the read worked — and nothing exposed it, so a `23505`
|
|
290
290
|
* unique violation, a `40001` serialization failure and a `57014` timeout all reached the caller
|
|
291
|
-
* as `X_DB_UNAVAILABLE`, whose fix is
|
|
291
|
+
* as `X_DB_UNAVAILABLE`, whose fix is a reachable DATABASE_URL. Two clicks
|
|
292
292
|
* racing a signup paged on-call for an outage that never happened.
|
|
293
293
|
*
|
|
294
294
|
* `X_DB_UNAVAILABLE` stays the answer for everything the table does not classify, including every
|
|
@@ -363,7 +363,7 @@ export const drainTimeout = (ms: number, role: string): DbError =>
|
|
|
363
363
|
new DbError({
|
|
364
364
|
code: 'X_DB_DRAIN_TIMEOUT',
|
|
365
365
|
cause: `the ${role} pool still held connections after ${String(ms)}ms, so close() stopped waiting`,
|
|
366
|
-
fix: `
|
|
366
|
+
fix: `psql "$DATABASE_URL" -c "select pid, state, query from pg_stat_activity where state <> 'idle'" # finds the statement that will not finish — or raise drainTimeoutMs in postgresClient({ profile }) for the ${role} role`,
|
|
367
367
|
meta: { drainTimeoutMs: ms, role },
|
|
368
368
|
});
|
|
369
369
|
|
|
@@ -409,9 +409,7 @@ export const serializationExhausted = (attempts: number, sourceError: unknown):
|
|
|
409
409
|
cause:
|
|
410
410
|
`the transaction lost its serialization race on all ${attempts} attempts: ` +
|
|
411
411
|
renderThrowable(sourceError),
|
|
412
|
-
fix:
|
|
413
|
-
'raise the retry budget — withTransaction(fn, { retry: 8 }) — or cut the contention: ' +
|
|
414
|
-
"narrow what the transaction reads, or drop to isolation: 'repeatable read'",
|
|
412
|
+
fix: "withTransaction(fn, { retry: 8 }) // raise the retry budget — or cut the contention: narrow what the transaction reads, or drop to isolation: 'repeatable read'",
|
|
415
413
|
meta: { attempts },
|
|
416
414
|
sourceError,
|
|
417
415
|
});
|
|
@@ -422,7 +420,8 @@ export const sqlUnsafe = (received: string, position: number): DbError =>
|
|
|
422
420
|
cause:
|
|
423
421
|
`interpolation #${position} in a sql\`\` template is ${received}, ` +
|
|
424
422
|
'which cannot be bound as a parameter',
|
|
425
|
-
|
|
423
|
+
// biome-ignore lint/suspicious/noTemplateCurlyInString: the fix shows the tagged template to paste
|
|
424
|
+
fix: 'sql`… ${scalar} …` // a scalar binds as $n; a nested sql`` fragment composes; wrap audited SQL in raw()',
|
|
426
425
|
meta: { position, received },
|
|
427
426
|
});
|
|
428
427
|
|
|
@@ -430,7 +429,7 @@ export const identifierUnsafe = (name: string, why?: string): DbError =>
|
|
|
430
429
|
new DbError({
|
|
431
430
|
code: 'X_SQL_UNSAFE',
|
|
432
431
|
cause: `${JSON.stringify(name)} is not usable as a Postgres identifier${why === undefined ? '' : `: ${why}`}`,
|
|
433
|
-
fix: '
|
|
432
|
+
fix: "identifier('users') // a plain table/column name — identifiers cannot be bound as parameters",
|
|
434
433
|
meta: { name },
|
|
435
434
|
});
|
|
436
435
|
|
package/src/listen.ts
CHANGED
|
@@ -48,7 +48,7 @@ export function assertListenChannel(channel: string): void {
|
|
|
48
48
|
throw new DbError({
|
|
49
49
|
code: 'X_SQL_UNSAFE',
|
|
50
50
|
cause: 'the LISTEN channel is not a lower-case identifier of at most 63 characters',
|
|
51
|
-
fix: "
|
|
51
|
+
fix: "client.listen('x_jobs_wake', onNotify) // a channel matching [a-z_][a-z0-9_]*",
|
|
52
52
|
});
|
|
53
53
|
}
|
|
54
54
|
|
package/src/migration-errors.ts
CHANGED
|
@@ -24,10 +24,7 @@ export const migrateConcurrent = (lockKey: number, waitedMs: number): DbError =>
|
|
|
24
24
|
cause:
|
|
25
25
|
`another session still holds pg_advisory_lock(${lockKey}) after waiting ${waitedMs}ms, ` +
|
|
26
26
|
'so this migrator refused rather than block a deploy forever',
|
|
27
|
-
fix:
|
|
28
|
-
'psql "$DATABASE_URL" -c "select pid, application_name, state from pg_stat_activity ' +
|
|
29
|
-
"join pg_locks using (pid) where locktype = 'advisory'\"" +
|
|
30
|
-
' # pg_terminate_backend(pid) the wedged migrator, then: x db migrate',
|
|
27
|
+
fix: `psql "$DATABASE_URL" -c "select pid, application_name, state from pg_stat_activity join pg_locks using (pid) where locktype = 'advisory'" # pg_terminate_backend(pid) the wedged migrator, then: x db migrate`,
|
|
31
28
|
meta: { lockKey, waitedMs },
|
|
32
29
|
});
|
|
33
30
|
|
|
@@ -132,10 +129,7 @@ export const migrationSnapshotMissing = (id: string, file: string): DbError => {
|
|
|
132
129
|
fix: spellable
|
|
133
130
|
? `git checkout -- ${renderFixShellArg(file, '')} # or, if it was never written: ` +
|
|
134
131
|
`rm ${renderFixShellArg(snapshotStem(file), '')}.* && x db gen "${renderFixShellArg(migrationNameOf(id), '')}"`
|
|
135
|
-
:
|
|
136
|
-
'migration owns and rerun x db gen with its description — the file named in this ' +
|
|
137
|
-
"error's cause carries a backtick, a dollar sign, a quote, a backslash or whitespace, " +
|
|
138
|
-
'so no command here can spell it',
|
|
132
|
+
: `git status --short -- "*.snapshot.json" # shows the sidecar that is gone: restore the .snapshot.json committed beside this migration, or delete every file that migration owns and rerun x db gen with its description — the file named in this error's cause carries a backtick, a dollar sign, a quote, a backslash or whitespace, so no command here can spell it`,
|
|
139
133
|
meta: { id, file },
|
|
140
134
|
});
|
|
141
135
|
};
|
|
@@ -159,7 +153,7 @@ export const migrationDestructive = (
|
|
|
159
153
|
cause:
|
|
160
154
|
`${file} ${DESTRUCTIVE_CAUSE[first.kind]} and does not declare it` +
|
|
161
155
|
`${more === 0 ? '' : ` (and ${more} more destructive)`}: ${first.statement}`,
|
|
162
|
-
fix: `add the line "${DESTRUCTIVE_MARKER}" to ${file}
|
|
156
|
+
fix: `x db gen "<name>" --allow-destructive # regenerate it — or add the line "${DESTRUCTIVE_MARKER}" to ${file}`,
|
|
163
157
|
meta: { file, kind: first.kind, statements: more + 1 },
|
|
164
158
|
});
|
|
165
159
|
|
package/src/object-drift.ts
CHANGED
|
@@ -139,9 +139,7 @@ function unexpectedObject(object: ObjectIdentity): DriftDifference {
|
|
|
139
139
|
);
|
|
140
140
|
return {
|
|
141
141
|
...base,
|
|
142
|
-
fix:
|
|
143
|
-
`${show} # no migration creates it: copy its definition into a migration as a create ` +
|
|
144
|
-
`statement, run ${spoken} here, then x db migrate — or only drop it if nothing owns it`,
|
|
142
|
+
fix: `${show} # no migration creates it: copy its definition into a migration as a create statement, run ${spoken} here, then x db migrate — or only drop it if nothing owns it`,
|
|
145
143
|
};
|
|
146
144
|
}
|
|
147
145
|
|
package/src/unrendered.ts
CHANGED
|
@@ -94,9 +94,7 @@ function unrenderedInvariant(
|
|
|
94
94
|
cause:
|
|
95
95
|
`the entity declares "${invariant.name}" as an assert — a rule only the app can judge — ` +
|
|
96
96
|
'and this migration drops the CHECK a migration recorded for it',
|
|
97
|
-
fix:
|
|
98
|
-
`invariant('${invariant.name}', …) # express it in SQL to keep the CHECK — ` +
|
|
99
|
-
'an assert has none, so the next x db gen drops it',
|
|
97
|
+
fix: `invariant('${invariant.name}', …) # express it in SQL to keep the CHECK — an assert has none, so the next x db gen drops it`,
|
|
100
98
|
};
|
|
101
99
|
}
|
|
102
100
|
|
|
@@ -156,9 +154,7 @@ export function unrenderedOf(
|
|
|
156
154
|
table: entity.table,
|
|
157
155
|
name: column.column,
|
|
158
156
|
cause: 'the entity description carries hasDefault with no expression beside it',
|
|
159
|
-
fix:
|
|
160
|
-
'project ColumnMeta.default onto ColumnDescription in ' +
|
|
161
|
-
'packages/entity/src/describe.ts, then re-run x db gen',
|
|
157
|
+
fix: 'project ColumnMeta.default onto ColumnDescription in packages/entity/src/describe.ts, then re-run x db gen',
|
|
162
158
|
});
|
|
163
159
|
}
|
|
164
160
|
entries.push(
|