-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
d769a75
commit 6787a1b
Showing
9 changed files
with
159 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
41 | ||
42 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
ALTER TABLE hdb_catalog.event_triggers | ||
DROP CONSTRAINT IF EXISTS event_triggers_schema_name_fkey; | ||
|
||
ALTER TABLE hdb_catalog.event_triggers | ||
DROP CONSTRAINT IF EXISTS event_triggers_schema_name_table_name_fkey; | ||
|
||
-- since we removed the foreign key constraint with hdb_catalog.hdb_table which had 'ON UPDATE CASCADE' | ||
-- (see Note [Diff-and-patch event triggers on replace] in Hasura.RQL.DDL.EventTrigger), we perform the update using trigger | ||
CREATE OR REPLACE FUNCTION hdb_catalog.event_trigger_table_name_update() | ||
RETURNS TRIGGER | ||
LANGUAGE PLPGSQL | ||
AS | ||
$$ | ||
BEGIN | ||
IF (NEW.table_schema, NEW.table_name) <> (OLD.table_schema, OLD.table_name) THEN | ||
UPDATE hdb_catalog.event_triggers | ||
SET schema_name = NEW.table_schema, table_name = NEW.table_name | ||
WHERE (schema_name, table_name) = (OLD.table_schema, OLD.table_name); | ||
END IF; | ||
RETURN NEW; | ||
END; | ||
$$; | ||
|
||
CREATE TRIGGER event_trigger_table_name_update_trigger | ||
AFTER UPDATE ON hdb_catalog.hdb_table | ||
FOR EACH ROW EXECUTE PROCEDURE hdb_catalog.event_trigger_table_name_update(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
DROP TRIGGER event_trigger_table_name_update_trigger ON hdb_catalog.hdb_table; | ||
|
||
DROP FUNCTION hdb_catalog.event_trigger_table_name_update(); | ||
|
||
ALTER TABLE hdb_catalog.event_triggers | ||
ADD CONSTRAINT event_triggers_schema_name_table_name_fkey | ||
FOREIGN KEY (schema_name, table_name) | ||
REFERENCES hdb_catalog.hdb_table(table_schema, table_name) | ||
ON UPDATE CASCADE; |
68 changes: 46 additions & 22 deletions
68
server/tests-py/queries/event_triggers/create-delete/create_and_reset.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,50 @@ | ||
description: create an event trigger and then reset metadata | ||
url: /v1/query | ||
status: 200 | ||
query: | ||
type: bulk | ||
args: | ||
- type: track_table | ||
- description: create an event trigger and then reset metadata | ||
url: /v1/query | ||
status: 200 | ||
query: | ||
type: bulk | ||
args: | ||
schema: hge_tests | ||
name: test_t1 | ||
- type: create_event_trigger | ||
args: &def_args | ||
name: t1_1 | ||
table: | ||
- type: track_table | ||
args: | ||
schema: hge_tests | ||
name: test_t1 | ||
insert: | ||
columns: "*" | ||
update: | ||
columns: "*" | ||
delete: | ||
columns: "*" | ||
webhook: http://127.0.0.1:5592 | ||
- type: create_event_trigger | ||
args: &def_args | ||
name: t1_1 | ||
table: | ||
schema: hge_tests | ||
name: test_t1 | ||
insert: | ||
columns: "*" | ||
update: | ||
columns: "*" | ||
delete: | ||
columns: "*" | ||
webhook: http://127.0.0.1:5592 | ||
- type: insert | ||
args: | ||
table: | ||
schema: hge_tests | ||
name: test_t1 | ||
objects: | ||
- c1: 1 | ||
c2: world | ||
returning: [] | ||
- type: clear_metadata | ||
args: {} | ||
|
||
- type: clear_metadata | ||
args: {} | ||
- description: ensure the event was archived | ||
url: /v1/query | ||
status: 200 | ||
response: | ||
- trigger_name: t1_1 | ||
archived: true | ||
query: | ||
type: select | ||
args: | ||
table: | ||
schema: hdb_catalog | ||
name: event_log | ||
columns: [trigger_name, archived] | ||
order_by: ['-created_at'] | ||
limit: 1 |