diff --git a/src/lib/sql/triggers.sql b/src/lib/sql/triggers.sql index 114d756c..b77651d7 100644 --- a/src/lib/sql/triggers.sql +++ b/src/lib/sql/triggers.sql @@ -29,6 +29,7 @@ ON pg_t.tgrelid = pg_c.oid JOIN information_schema.triggers AS is_t ON is_t.trigger_name = pg_t.tgname AND pg_c.relname = is_t.event_object_table +AND pg_c.relnamespace = is_t.event_object_schema::regnamespace JOIN pg_proc AS pg_p ON pg_t.tgfoid = pg_p.oid JOIN pg_namespace AS pg_n diff --git a/test/lib/triggers.ts b/test/lib/triggers.ts index 2ae34b0d..fdb42123 100644 --- a/test/lib/triggers.ts +++ b/test/lib/triggers.ts @@ -217,3 +217,50 @@ test('multi event', async () => { ) await pgMeta.triggers.remove(res.data!.id) }) + +test('triggers with the same name on different schemas', async () => { + await pgMeta.query(` +create function tr_f() returns trigger language plpgsql as 'begin end'; +create schema s1; create table s1.t(); create trigger tr before insert on s1.t execute function tr_f(); +create schema s2; create table s2.t(); create trigger tr before insert on s2.t execute function tr_f(); +`) + + const res = await pgMeta.triggers.list() + const triggers = res.data?.map(({ id, table_id, ...trigger }) => trigger) + expect(triggers).toMatchInlineSnapshot(` + [ + { + "activation": "BEFORE", + "condition": null, + "enabled_mode": "ORIGIN", + "events": [ + "INSERT", + ], + "function_args": [], + "function_name": "tr_f", + "function_schema": "public", + "name": "tr", + "orientation": "STATEMENT", + "schema": "s1", + "table": "t", + }, + { + "activation": "BEFORE", + "condition": null, + "enabled_mode": "ORIGIN", + "events": [ + "INSERT", + ], + "function_args": [], + "function_name": "tr_f", + "function_schema": "public", + "name": "tr", + "orientation": "STATEMENT", + "schema": "s2", + "table": "t", + }, + ] + `) + + await pgMeta.query('drop schema s1 cascade; drop schema s2 cascade;') +})