-
Notifications
You must be signed in to change notification settings - Fork 30
feat: trigger old table #64
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
Merged
+166
−10
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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,5 @@ | ||
| CREATE OR REPLACE TRIGGER orders_delete_trigger | ||
| AFTER DELETE ON orders | ||
| REFERENCING OLD TABLE AS old_orders | ||
| FOR EACH STATEMENT | ||
| EXECUTE FUNCTION archive_deleted_orders(); |
25 changes: 25 additions & 0 deletions
25
testdata/diff/create_trigger/add_trigger_old_table/new.sql
This file contains hidden or 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,25 @@ | ||
| CREATE TABLE public.orders ( | ||
| id serial PRIMARY KEY, | ||
| amount numeric(10,2) | ||
| ); | ||
|
|
||
| CREATE TABLE public.orders_archive ( | ||
| id integer, | ||
| amount numeric(10,2), | ||
| deleted_at timestamp DEFAULT CURRENT_TIMESTAMP | ||
| ); | ||
|
|
||
| CREATE OR REPLACE FUNCTION public.archive_deleted_orders() | ||
| RETURNS trigger AS $$ | ||
| BEGIN | ||
| INSERT INTO orders_archive (id, amount) | ||
| SELECT id, amount FROM old_orders; | ||
| RETURN NULL; | ||
| END; | ||
| $$ LANGUAGE plpgsql; | ||
|
|
||
| CREATE TRIGGER orders_delete_trigger | ||
| AFTER DELETE ON public.orders | ||
| REFERENCING OLD TABLE AS old_orders | ||
| FOR EACH STATEMENT | ||
| EXECUTE FUNCTION public.archive_deleted_orders(); |
19 changes: 19 additions & 0 deletions
19
testdata/diff/create_trigger/add_trigger_old_table/old.sql
This file contains hidden or 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,19 @@ | ||
| CREATE TABLE public.orders ( | ||
| id serial PRIMARY KEY, | ||
| amount numeric(10,2) | ||
| ); | ||
|
|
||
| CREATE TABLE public.orders_archive ( | ||
| id integer, | ||
| amount numeric(10,2), | ||
| deleted_at timestamp DEFAULT CURRENT_TIMESTAMP | ||
| ); | ||
|
|
||
| CREATE OR REPLACE FUNCTION public.archive_deleted_orders() | ||
| RETURNS trigger AS $$ | ||
| BEGIN | ||
| INSERT INTO orders_archive (id, amount) | ||
| SELECT id, amount FROM old_orders; | ||
| RETURN NULL; | ||
| END; | ||
| $$ LANGUAGE plpgsql; |
20 changes: 20 additions & 0 deletions
20
testdata/diff/create_trigger/add_trigger_old_table/plan.json
This file contains hidden or 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,20 @@ | ||
| { | ||
| "version": "1.0.0", | ||
| "pgschema_version": "1.2.1", | ||
| "created_at": "1970-01-01T00:00:00Z", | ||
| "source_fingerprint": { | ||
| "hash": "087a74a25f6a817a556750d274e732048ca5281379e6c0bedd1f5a35176daa2e" | ||
| }, | ||
| "groups": [ | ||
| { | ||
| "steps": [ | ||
| { | ||
| "sql": "CREATE OR REPLACE TRIGGER orders_delete_trigger\n AFTER DELETE ON orders\n REFERENCING OLD TABLE AS old_orders\n FOR EACH STATEMENT\n EXECUTE FUNCTION archive_deleted_orders();", | ||
| "type": "table.trigger", | ||
| "operation": "create", | ||
| "path": "public.orders.orders_delete_trigger" | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } |
This file contains hidden or 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,5 @@ | ||
| CREATE OR REPLACE TRIGGER orders_delete_trigger | ||
| AFTER DELETE ON orders | ||
| REFERENCING OLD TABLE AS old_orders | ||
| FOR EACH STATEMENT | ||
| EXECUTE FUNCTION archive_deleted_orders(); |
17 changes: 17 additions & 0 deletions
17
testdata/diff/create_trigger/add_trigger_old_table/plan.txt
This file contains hidden or 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,17 @@ | ||
| Plan: 1 to modify. | ||
|
|
||
| Summary by type: | ||
| tables: 1 to modify | ||
|
|
||
| Tables: | ||
| ~ orders | ||
| + orders_delete_trigger (trigger) | ||
|
|
||
| DDL to be executed: | ||
| -------------------------------------------------- | ||
|
|
||
| CREATE OR REPLACE TRIGGER orders_delete_trigger | ||
| AFTER DELETE ON orders | ||
| REFERENCING OLD TABLE AS old_orders | ||
| FOR EACH STATEMENT | ||
| EXECUTE FUNCTION archive_deleted_orders(); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The transition table assignment logic overwrites parsed values unconditionally. This could cause issues when the catalog data is empty but the parser correctly extracted values from DDL. Consider only setting these values when they're currently empty in the trigger object.