-
-
Notifications
You must be signed in to change notification settings - Fork 193
fix: generate Insert/Update types for views with INSTEAD OF triggers #1062
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -229,6 +229,22 @@ create schema s2; create table s2.t(); create trigger tr before insert on s2.t e | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const triggers = res.data?.map(({ id, table_id, ...trigger }) => trigger) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(triggers).toMatchInlineSnapshot(` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "activation": "INSTEAD OF", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "condition": null, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "enabled_mode": "ORIGIN", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "events": [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "INSERT", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "UPDATE", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "function_args": [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "function_name": "profile_view_instead_of_trigger", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "function_schema": "public", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "name": "profile_view_instead_of_trigger", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "orientation": "ROW", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "schema": "public", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "table": "profile_view", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
229
to
248
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const triggers = res.data?.map(({ id, table_id, ...trigger }) => trigger) | |
| expect(triggers).toMatchInlineSnapshot(` | |
| [ | |
| { | |
| "activation": "INSTEAD OF", | |
| "condition": null, | |
| "enabled_mode": "ORIGIN", | |
| "events": [ | |
| "INSERT", | |
| "UPDATE", | |
| ], | |
| "function_args": [], | |
| "function_name": "profile_view_instead_of_trigger", | |
| "function_schema": "public", | |
| "name": "profile_view_instead_of_trigger", | |
| "orientation": "ROW", | |
| "schema": "public", | |
| "table": "profile_view", | |
| }, | |
| { | |
| const triggers = res.data | |
| ?.filter(({ name, schema }) => name === 'tr' && (schema === 's1' || schema === 's2')) | |
| .map(({ id, table_id, ...trigger }) => trigger) | |
| expect(triggers).toMatchInlineSnapshot(` | |
| [ | |
| { |
Copilot
AI
Apr 11, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test snapshots the entire output of pgMeta.triggers.list(), which now includes unrelated triggers from the shared test DB init (e.g. profile_view_instead_of_trigger). To keep this test focused and stable, filter the returned triggers to the schema/table/name created in this test (e.g. schema MySchema) before snapshotting.
| const triggers = res.data?.map(({ id, table_id, ...trigger }) => trigger) | |
| expect(triggers).toMatchInlineSnapshot(` | |
| [ | |
| { | |
| "activation": "INSTEAD OF", | |
| "condition": null, | |
| "enabled_mode": "ORIGIN", | |
| "events": [ | |
| "INSERT", | |
| "UPDATE", | |
| ], | |
| "function_args": [], | |
| "function_name": "profile_view_instead_of_trigger", | |
| "function_schema": "public", | |
| "name": "profile_view_instead_of_trigger", | |
| "orientation": "ROW", | |
| "schema": "public", | |
| "table": "profile_view", | |
| }, | |
| { | |
| const triggers = res.data | |
| ?.filter( | |
| ({ schema, table, name }) => | |
| schema === 'MySchema' && table === 'MyTable' && name === 'my_trigger' | |
| ) | |
| .map(({ id, table_id, ...trigger }) => trigger) | |
| expect(triggers).toMatchInlineSnapshot(` | |
| [ | |
| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
VIEWS_SQLdefinesis_insert_enabled/is_update_enabledtwice in the same SELECT (first at lines 14-35, then again at lines 36-57). This yields duplicate output column names and the second definition can override the first in result mapping, which can makeis_insert_enabled/is_update_enabledincorrect (e.g. preventing view Insert type generation). Remove the duplicated block and keep a single, consistent trigger-bit check for INSTEAD OF INSERT/UPDATE.