Skip to content

Commit

Permalink
fix: create column with fully-qualified type
Browse files Browse the repository at this point in the history
  • Loading branch information
soedirgo committed Mar 20, 2024
1 parent 9c61b75 commit fab59a7
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/lib/PostgresMetaColumns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,12 @@ COMMIT;`
}
}

// TODO: make this more robust - use type_id or type_schema + type_name instead
// of just type.
const typeIdent = (type: string) => {
return type.endsWith('[]') ? `${ident(type.slice(0, -2))}[]` : ident(type)
return type.endsWith('[]')
? `${ident(type.slice(0, -2))}[]`
: type.includes('.')
? type
: ident(type)
}
41 changes: 41 additions & 0 deletions test/lib/columns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -947,3 +947,44 @@ test('dropping column checks', async () => {

await pgMeta.query(`drop table t`)
})

test('column with fully-qualified type', async () => {
await pgMeta.query(`create table public.t(); create schema s; create type s.my_type as enum ();`)

const table = await pgMeta.tables.retrieve({
schema: 'public',
name: 't',
})
const column = await pgMeta.columns.create({
table_id: table.data!.id,
name: 'c',
type: 's.my_type',
})
expect(column).toMatchInlineSnapshot(`
{
"data": {
"check": null,
"comment": null,
"data_type": "USER-DEFINED",
"default_value": null,
"enums": [],
"format": "my_type",
"id": "16619.1",
"identity_generation": null,
"is_generated": false,
"is_identity": false,
"is_nullable": true,
"is_unique": false,
"is_updatable": true,
"name": "c",
"ordinal_position": 1,
"schema": "public",
"table": "t",
"table_id": 16619,
},
"error": null,
}
`)

await pgMeta.query(`drop table public.t; drop schema s cascade;`)
})

0 comments on commit fab59a7

Please sign in to comment.