Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: create column with fully-qualified type [GEN-8366] #742

Merged
merged 1 commit into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;`)
})