Skip to content

Commit e60faaa

Browse files
committed
feat(columns): populate enums in enum array columns
1 parent 6d6d58c commit e60faaa

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

src/lib/sql/columns.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ SELECT
5050
FROM
5151
pg_catalog.pg_enum enums
5252
WHERE
53-
quote_ident(COALESCE(bt.typname, t.typname)) = format_type(enums.enumtypid, NULL)
53+
enums.enumtypid = coalesce(bt.oid, t.oid)
54+
OR enums.enumtypid = coalesce(bt.typelem, t.typelem)
5455
ORDER BY
5556
enums.enumsortorder
5657
)

test/lib/columns.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,3 +733,51 @@ test('alter column to type with uppercase', async () => {
733733
await pgMeta.tables.remove(testTable!.id)
734734
await pgMeta.query('DROP TYPE "T"')
735735
})
736+
737+
test('enums are populated in enum array columns', async () => {
738+
await pgMeta.query(`create type test_enum as enum ('a')`)
739+
const { data: testTable } = await pgMeta.tables.create({ name: 't' })
740+
741+
let res = await pgMeta.columns.create({
742+
table_id: testTable!.id,
743+
name: 'c',
744+
type: '_test_enum',
745+
})
746+
expect(res).toMatchInlineSnapshot(
747+
{
748+
data: {
749+
id: expect.stringMatching(/^\d+\.1$/),
750+
table_id: expect.any(Number),
751+
},
752+
},
753+
`
754+
Object {
755+
"data": Object {
756+
"comment": null,
757+
"data_type": "ARRAY",
758+
"default_value": null,
759+
"enums": Array [
760+
"a",
761+
],
762+
"format": "_test_enum",
763+
"id": StringMatching /\\^\\\\d\\+\\\\\\.1\\$/,
764+
"identity_generation": null,
765+
"is_generated": false,
766+
"is_identity": false,
767+
"is_nullable": true,
768+
"is_unique": false,
769+
"is_updatable": true,
770+
"name": "c",
771+
"ordinal_position": 1,
772+
"schema": "public",
773+
"table": "t",
774+
"table_id": Any<Number>,
775+
},
776+
"error": null,
777+
}
778+
`
779+
)
780+
781+
await pgMeta.tables.remove(testTable!.id)
782+
await pgMeta.query(`drop type test_enum`)
783+
})

0 commit comments

Comments
 (0)