Skip to content

Commit

Permalink
fix: updating column check
Browse files Browse the repository at this point in the history
  • Loading branch information
soedirgo committed Mar 19, 2024
1 parent 596e81f commit f418160
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof postgresColumnUpdateSchema>

Expand Down
14 changes: 14 additions & 0 deletions test/lib/columns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
})

0 comments on commit f418160

Please sign in to comment.