Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: triggers w/ the same name on different schemas are duplicated [GEN-8547] #746

Merged
merged 1 commit into from
Mar 21, 2024
Merged
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
1 change: 1 addition & 0 deletions src/lib/sql/triggers.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
47 changes: 47 additions & 0 deletions test/lib/triggers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;')
})