Skip to content

Commit 1c924e2

Browse files
authored
pg introspector - Wrap schema.table in double quotes for case handling (#1426)
* pg introspector - Wrap schema.table in double quotes for case handling Use quote_ident instead of manual concat * Add test for MixedCaseTable in pg introspect
1 parent b856577 commit 1c924e2

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/dialect/postgres/postgres-introspector.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export class PostgresIntrospector implements DatabaseIntrospector {
6262
),
6363
sql<
6464
string | null
65-
>`pg_get_serial_sequence(ns.nspname || '.' || c.relname, a.attname)`.as(
65+
>`pg_get_serial_sequence(quote_ident(ns.nspname) || '.' || quote_ident(c.relname), a.attname)`.as(
6666
'auto_incrementing',
6767
),
6868
])

test/node/src/introspect.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,22 @@ for (const dialect of DIALECTS) {
256256
},
257257
],
258258
},
259+
{
260+
name: 'MixedCaseTable',
261+
isView: false,
262+
schema: 'some_schema',
263+
columns: [
264+
{
265+
name: 'some_column',
266+
dataType: 'int4',
267+
dataTypeSchema: 'pg_catalog',
268+
isNullable: false,
269+
isAutoIncrementing: true,
270+
hasDefaultValue: true,
271+
comment: undefined,
272+
},
273+
],
274+
},
259275
{
260276
name: 'pet',
261277
isView: false,
@@ -878,6 +894,11 @@ for (const dialect of DIALECTS) {
878894
.asEnum(['cat', 'dog', 'frog'])
879895
.execute()
880896

897+
await ctx.db.schema
898+
.createTable('some_schema.MixedCaseTable')
899+
.addColumn('some_column', 'serial', (col) => col.primaryKey())
900+
.execute()
901+
881902
await ctx.db.schema
882903
.createTable('some_schema.pet')
883904
.addColumn('some_column', 'serial', (col) => col.primaryKey())
@@ -908,6 +929,10 @@ for (const dialect of DIALECTS) {
908929

909930
async function dropSchema() {
910931
await ctx.db.schema.dropTable('some_schema.pet').ifExists().execute()
932+
await ctx.db.schema
933+
.dropTable('some_schema.MixedCaseTable')
934+
.ifExists()
935+
.execute()
911936
await ctx.db.schema
912937
.dropTable('some_schema.pet_partition')
913938
.ifExists()

0 commit comments

Comments
 (0)