diff --git a/src/lib/types.ts b/src/lib/types.ts index c3906b39..e49882ae 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -77,7 +77,12 @@ export const postgresColumnUpdateSchema = Type.Object({ is_nullable: Type.Optional(Type.Boolean()), is_unique: Type.Optional(Type.Boolean()), comment: Type.Optional(Type.String()), - check: Type.Optional(Type.Union([Type.String(), Type.Null()])), + check: Type.Optional( + Type.Union( + // Type.Null() must go first: https://github.com/sinclairzx81/typebox/issues/546 + [Type.Null(), Type.String()] + ) + ), }) export type PostgresColumnUpdate = Static diff --git a/test/lib/columns.ts b/test/lib/columns.ts index ef94618c..f16402c7 100644 --- a/test/lib/columns.ts +++ b/test/lib/columns.ts @@ -933,3 +933,17 @@ test('column with multiple checks', async () => { await pgMeta.query(`drop table t`) }) + +test('dropping column checks', async () => { + await pgMeta.query(`create table public.t(c int8 check (c != 0))`) + + let res = await pgMeta.columns.retrieve({ + schema: 'public', + table: 't', + name: 'c', + }) + res = await pgMeta.columns.update(res.data!.id, { check: null }) + expect(res?.data?.check).toMatchInlineSnapshot(`null`) + + await pgMeta.query(`drop table t`) +})