Skip to content

Commit dd2af8c

Browse files
committed
fix: allow deletion of check constraints
1 parent 2e54b2d commit dd2af8c

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/lib/PostgresMetaColumns.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ COMMIT;`
225225
is_nullable?: boolean
226226
is_unique?: boolean
227227
comment?: string
228-
check?: string
228+
check?: string | null
229229
}
230230
): Promise<PostgresMetaResult<PostgresColumn>> {
231231
const { data: old, error } = await this.retrieve({ id })
@@ -353,9 +353,12 @@ BEGIN
353353
)} DROP CONSTRAINT %s', v_conname);
354354
END IF;
355355
356+
${
357+
check !== null
358+
? `
356359
ALTER TABLE ${ident(old!.schema)}.${ident(old!.table)} ADD CONSTRAINT ${ident(
357-
`${old!.table}_${old!.name}_check`
358-
)} CHECK (${check});
360+
`${old!.table}_${old!.name}_check`
361+
)} CHECK (${check});
359362
360363
SELECT conkey into v_conkey FROM pg_constraint WHERE conname = ${literal(
361364
`${old!.table}_${old!.name}_check`
@@ -366,6 +369,9 @@ BEGIN
366369
ASSERT v_conkey[1] = ${literal(
367370
old!.ordinal_position
368371
)}, 'error creating column constraint: check condition cannot refer to other columns';
372+
`
373+
: ''
374+
}
369375
END
370376
$$;
371377
`

0 commit comments

Comments
 (0)