Schema check: a unique key is matched by shape, not name; quiet fixture pools
The rule mutation that stopped checking a named unique index by its name survived, and rightly: an index of the same table, key columns, predicate, uniqueness and immediacy keeps R21.1 whatever it is called, and the named index's existence is already required as a relation. The name condition and REQUIRED_KEYS' index field are deleted. The live block failed 5 of 10 repeated runs with unhandled 57P01 errors: a test's own pool, already ended, still had connections closing when the forced drop terminated them, and nothing listened. Every pool the tests open now goes through fixturePool, which ignores those errors; the store's own pool keeps its listener and is not a fixture. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
fd98e36186
commit
6c0c87669f
3 changed files with 29 additions and 26 deletions
|
|
@ -335,11 +335,10 @@ export class PostgresStore implements HeimdallStore {
|
|||
AND a.atttypid = to_regtype(required.type_name)
|
||||
)
|
||||
UNION ALL
|
||||
SELECT 'missing' FROM unnest($5::text[], $6::text[], $7::text[], $8::text[]) AS required(table_name, columns, index_name, predicate)
|
||||
SELECT 'missing' FROM unnest($5::text[], $6::text[], $7::text[]) AS required(table_name, columns, predicate)
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1 FROM pg_index i
|
||||
WHERE i.indrelid = to_regclass(required.table_name)
|
||||
AND (required.index_name = '' OR i.indexrelid = to_regclass(required.index_name))
|
||||
AND i.indisunique
|
||||
AND i.indimmediate
|
||||
AND coalesce(regexp_replace(lower(pg_get_expr(i.indpred, i.indrelid)), '[()[:space:]]', '', 'g'), '') = required.predicate
|
||||
|
|
@ -352,7 +351,7 @@ export class PostgresStore implements HeimdallStore {
|
|||
) = required.columns
|
||||
)
|
||||
UNION ALL
|
||||
SELECT 'privilege' FROM unnest($9::text[], $10::text[]) AS required(table_name, privilege)
|
||||
SELECT 'privilege' FROM unnest($8::text[], $9::text[]) AS required(table_name, privilege)
|
||||
WHERE to_regclass(required.table_name) IS NOT NULL
|
||||
AND NOT has_table_privilege(to_regclass(required.table_name), required.privilege)
|
||||
`,
|
||||
|
|
@ -363,7 +362,6 @@ export class PostgresStore implements HeimdallStore {
|
|||
REQUIRED_COLUMNS.map((required) => required.type),
|
||||
REQUIRED_KEYS.map((required) => required.table),
|
||||
REQUIRED_KEYS.map((required) => required.columns),
|
||||
REQUIRED_KEYS.map((required) => required.index),
|
||||
REQUIRED_KEYS.map((required) => required.predicate),
|
||||
privileges.map((required) => required.table),
|
||||
privileges.map((required) => required.privilege),
|
||||
|
|
|
|||
|
|
@ -223,26 +223,24 @@ export const REQUIRED_COLUMNS = [
|
|||
|
||||
/**
|
||||
* Every unique key the schema makes: the primary keys and unique constraints
|
||||
* of the created tables, and each unique index it creates by name with that
|
||||
* index's predicate. The store relies on each as an immediate unique index
|
||||
* whose key columns are exactly these, with exactly this predicate: ON
|
||||
* of the created tables, and each unique index it creates, with that index's
|
||||
* predicate. The store relies on each as an immediate unique index on its
|
||||
* table whose key columns are exactly these, with exactly this predicate: ON
|
||||
* CONFLICT refuses a deferrable arbiter and cannot infer a partial or wider
|
||||
* one, and the partial attempt index is what keeps one unconsumed completion
|
||||
* per attempt (R21.1). `index` is empty for a constraint, which may be
|
||||
* satisfied by any such index on its table.
|
||||
* per attempt (R21.1). Any index with that shape serves, whatever its name.
|
||||
*/
|
||||
export const REQUIRED_KEYS = [
|
||||
...createdTables.flatMap(({ table, lines }) =>
|
||||
lines.flatMap((line) => {
|
||||
const columns =
|
||||
/^(\w+) .*\bPRIMARY KEY\b/.exec(line)?.[1] ?? keyColumns(line, "PRIMARY KEY") ?? keyColumns(line, "UNIQUE");
|
||||
return columns ? [{ table, columns, index: "", predicate: "" }] : [];
|
||||
return columns ? [{ table, columns, predicate: "" }] : [];
|
||||
})
|
||||
),
|
||||
...[...schemaText.matchAll(/^CREATE UNIQUE INDEX IF NOT EXISTS (\w+)\s+ON (\w+)\(([^)]*)\)(?:\s+WHERE ([^;]+))?;/gm)].map((match) => ({
|
||||
table: match[2]!,
|
||||
columns: columnList(match[3]!),
|
||||
index: match[1]!,
|
||||
predicate: comparablePredicate(match[4] ?? ""),
|
||||
...[...schemaText.matchAll(/^CREATE UNIQUE INDEX IF NOT EXISTS \w+\s+ON (\w+)\(([^)]*)\)(?:\s+WHERE ([^;]+))?;/gm)].map((match) => ({
|
||||
table: match[1]!,
|
||||
columns: columnList(match[2]!),
|
||||
predicate: comparablePredicate(match[3] ?? ""),
|
||||
})),
|
||||
];
|
||||
|
|
|
|||
Loading…
Reference in a new issue