Skip to content

Commit b1787b6

Browse files
committed
fix(publications): handle table name w/ uppercase
1 parent ad397b2 commit b1787b6

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/lib/PostgresMetaPublications.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ 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.map(ident).join(',')}`
7272
}
7373

7474
let publishOps = []
@@ -138,7 +138,7 @@ CREATE PUBLICATION ${ident(name)} ${tableClause}
138138
} else if (old!.tables === null) {
139139
throw new Error('Tables cannot be added to or dropped from FOR ALL TABLES publications')
140140
} else if (tables.length > 0) {
141-
tableSql = `ALTER PUBLICATION ${ident(old!.name)} SET TABLE ${tables.join(',')};`
141+
tableSql = `ALTER PUBLICATION ${ident(old!.name)} SET TABLE ${tables.map(ident).join(',')};`
142142
} else if (old!.tables.length === 0) {
143143
tableSql = ''
144144
} else {

test/integration/index.spec.js

+10
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,16 @@ describe('/publications with tables', () => {
716716
const stillExists = publications.some((x) => x.id === id)
717717
assert.equal(stillExists, false)
718718
})
719+
it('/publications for tables with uppercase', async () => {
720+
const { data: table } = await axios.post(`${URL}/tables`, { name: 'T' })
721+
const { data: publication } = await axios.post(`${URL}/publications`, { name: 'pub', tables: ['T'] })
722+
assert.equal(publication.name, 'pub')
723+
const { data: alteredPublication } = await axios.patch(`${URL}/publications/${publication.id}`, { tables: ['T'] })
724+
assert.equal(alteredPublication.name, 'pub')
725+
726+
await axios.delete(`${URL}/publications/${publication.id}`)
727+
await axios.delete(`${URL}/tables/${table.id}`)
728+
})
719729
})
720730

721731
describe('/publications FOR ALL TABLES', () => {

0 commit comments

Comments
 (0)