Skip to content

Commit d1ec463

Browse files
committed
fix: actually escape tables
1 parent 17fa5be commit d1ec463

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

src/lib/PostgresMetaPublications.ts

+22-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,17 @@ export default class PostgresMetaPublications {
6868
} else if (tables.length === 0) {
6969
tableClause = ''
7070
} else {
71-
tableClause = `FOR TABLE ${tables.join(',')}`
71+
tableClause = `FOR TABLE ${tables
72+
.map((t) => {
73+
if (!t.includes('.')) {
74+
return ident(t)
75+
}
76+
77+
const [schema, ...rest] = t.split('.')
78+
const table = rest.join('.')
79+
return `${ident(schema)}.${ident(table)}`
80+
})
81+
.join(',')}`
7282
}
7383

7484
let publishOps = []
@@ -138,7 +148,17 @@ CREATE PUBLICATION ${ident(name)} ${tableClause}
138148
} else if (old!.tables === null) {
139149
throw new Error('Tables cannot be added to or dropped from FOR ALL TABLES publications')
140150
} else if (tables.length > 0) {
141-
tableSql = `ALTER PUBLICATION ${ident(old!.name)} SET TABLE ${tables.join(',')};`
151+
tableSql = `ALTER PUBLICATION ${ident(old!.name)} SET TABLE ${tables
152+
.map((t) => {
153+
if (!t.includes('.')) {
154+
return ident(t)
155+
}
156+
157+
const [schema, ...rest] = t.split('.')
158+
const table = rest.join('.')
159+
return `${ident(schema)}.${ident(table)}`
160+
})
161+
.join(',')};`
142162
} else if (old!.tables.length === 0) {
143163
tableSql = ''
144164
} else {

0 commit comments

Comments
 (0)