Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/lib/PostgresMetaTables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export default class PostgresMetaTables {
if (replica_identity === undefined) {
// skip
} else if (replica_identity === 'INDEX') {
replicaSql = `${alter} REPLICA IDENTITY USING INDEX ${replica_identity_index};`
replicaSql = `${alter} REPLICA IDENTITY USING INDEX ${ident(replica_identity_index)};`
} else {
replicaSql = `${alter} REPLICA IDENTITY ${replica_identity};`
}
Expand Down
22 changes: 22 additions & 0 deletions test/lib/tables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -577,3 +577,25 @@ test('composite primary keys preserve order', async () => {

await pgMeta.tables.remove(res.data!.id)
})

test('update replica identity using an index whose name needs quoting', async () => {
// The index name contains a space and uppercase letters, so it only resolves
// if it is passed through ident(). An unquoted name would make the generated
// ALTER TABLE ... USING INDEX statement invalid.
await pgMeta.query(`
CREATE TABLE public.t_replica_idx (id int8 NOT NULL);
CREATE UNIQUE INDEX "Weird Index" ON public.t_replica_idx (id);
`)
const { data: tables } = await pgMeta.tables.list()
const tableId = tables!.find((t) => t.name === 't_replica_idx')!.id

const res = await pgMeta.tables.update(tableId, {
replica_identity: 'INDEX',
replica_identity_index: 'Weird Index',
})

expect(res.error).toBeNull()
expect(res.data!.replica_identity).toBe('INDEX')

await pgMeta.tables.remove(tableId)
})