From f5ed62276e7ba617156c45e1565ed423092cff51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Fri, 16 Oct 2026 02:59:47 +0200 Subject: [PATCH] test(wipe): seed a column fenced by a CHECK list with a value it admits The schema-driven seeder wrote a synthetic tag into every required text column. The v1.43 tables fence some of them with CHECK (col IN (...)), so the seed was refused before either wipe ran. Read each single-column IN-list check from pg_constraint and seed its first admitted value. --- tests/integration/wipe-seeder.ts | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/tests/integration/wipe-seeder.ts b/tests/integration/wipe-seeder.ts index c23514fc9..23274df00 100644 --- a/tests/integration/wipe-seeder.ts +++ b/tests/integration/wipe-seeder.ts @@ -133,6 +133,27 @@ export async function seedEveryTable( if (!enums.has(row.typname)) enums.set(row.typname, row.enumlabel); } + // A column fenced by a single-column `CHECK (col IN (...))` takes the first + // value the fence admits; a synthesised tag would be refused before the wipe + // ever ran. Postgres stores the IN list as `col = ANY (ARRAY['a'::text, ...])`. + const checkRows = await prisma.$queryRaw< + Array<{ table_name: string; column_name: string; def: string }> + >` + SELECT con.conrelid::regclass::text AS table_name, + att.attname AS column_name, + pg_get_constraintdef(con.oid) AS def + FROM pg_constraint con + JOIN pg_attribute att + ON att.attrelid = con.conrelid AND att.attnum = con.conkey[1] + WHERE con.contype = 'c' + AND con.connamespace = 'public'::regnamespace + AND cardinality(con.conkey) = 1`; + const admitted = new Map(); + for (const row of checkRows) { + const first = /=\s*ANY\s*\(\s*\(?ARRAY\['((?:[^']|'')*)'/.exec(row.def); + if (first) admitted.set(`${row.table_name}.${row.column_name}`, first[1]); + } + const byTable = new Map(); for (const column of columns) { if (SEED_SKIP.has(column.table_name)) continue; @@ -206,7 +227,12 @@ export async function seedEveryTable( continue; } names.push(column.column_name); - values.push(synthesise(column.udt_name, enums, `seed-${tag++}`)); + const fenced = admitted.get(`${table}.${column.column_name}`); + values.push( + fenced !== undefined + ? `'${fenced}'` + : synthesise(column.udt_name, enums, `seed-${tag++}`), + ); } const sql =