Skip to content

Commit dd47c6d

Browse files
committed
fix: triggers w/ the same name on different schemas are duplicated
1 parent a736ab5 commit dd47c6d

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

src/lib/sql/triggers.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ ON pg_t.tgrelid = pg_c.oid
2929
JOIN information_schema.triggers AS is_t
3030
ON is_t.trigger_name = pg_t.tgname
3131
AND pg_c.relname = is_t.event_object_table
32+
AND pg_c.relnamespace = is_t.event_object_schema::regnamespace
3233
JOIN pg_proc AS pg_p
3334
ON pg_t.tgfoid = pg_p.oid
3435
JOIN pg_namespace AS pg_n

test/lib/triggers.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,3 +217,50 @@ test('multi event', async () => {
217217
)
218218
await pgMeta.triggers.remove(res.data!.id)
219219
})
220+
221+
test('triggers with the same name on different schemas', async () => {
222+
await pgMeta.query(`
223+
create function tr_f() returns trigger language plpgsql as 'begin end';
224+
create schema s1; create table s1.t(); create trigger tr before insert on s1.t execute function tr_f();
225+
create schema s2; create table s2.t(); create trigger tr before insert on s2.t execute function tr_f();
226+
`)
227+
228+
const res = await pgMeta.triggers.list()
229+
const triggers = res.data?.map(({ id, table_id, ...trigger }) => trigger)
230+
expect(triggers).toMatchInlineSnapshot(`
231+
[
232+
{
233+
"activation": "BEFORE",
234+
"condition": null,
235+
"enabled_mode": "ORIGIN",
236+
"events": [
237+
"INSERT",
238+
],
239+
"function_args": [],
240+
"function_name": "tr_f",
241+
"function_schema": "public",
242+
"name": "tr",
243+
"orientation": "STATEMENT",
244+
"schema": "s1",
245+
"table": "t",
246+
},
247+
{
248+
"activation": "BEFORE",
249+
"condition": null,
250+
"enabled_mode": "ORIGIN",
251+
"events": [
252+
"INSERT",
253+
],
254+
"function_args": [],
255+
"function_name": "tr_f",
256+
"function_schema": "public",
257+
"name": "tr",
258+
"orientation": "STATEMENT",
259+
"schema": "s2",
260+
"table": "t",
261+
},
262+
]
263+
`)
264+
265+
await pgMeta.query('drop schema s1 cascade; drop schema s2 cascade;')
266+
})

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy