-
Notifications
You must be signed in to change notification settings - Fork 57
fix: order function recreation after dependent view recreation (#480) #488
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
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
32 changes: 32 additions & 0 deletions
32
testdata/diff/dependency/issue_480_view_function_recreate/diff.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,32 @@ | ||
| DROP FUNCTION IF EXISTS fn_create_user(text); | ||
|
|
||
| ALTER TABLE tb_users ADD COLUMN role text DEFAULT 'member' NOT NULL; | ||
|
|
||
| DROP VIEW IF EXISTS vw_users RESTRICT; | ||
|
|
||
| CREATE OR REPLACE VIEW vw_users AS | ||
| SELECT id, | ||
| email, | ||
| role, | ||
| created_at | ||
| FROM tb_users | ||
| WHERE is_deleted = false; | ||
|
|
||
| CREATE OR REPLACE FUNCTION fn_create_user( | ||
| email text, | ||
| role text DEFAULT 'member' | ||
| ) | ||
| RETURNS vw_users | ||
| LANGUAGE plpgsql | ||
| VOLATILE | ||
| SECURITY DEFINER | ||
| AS $$ | ||
| DECLARE | ||
| v_result vw_users; | ||
| v_new_id UUID; | ||
| BEGIN | ||
| INSERT INTO tb_users (email, role) VALUES (email, role) RETURNING id INTO v_new_id; | ||
| SELECT id, email, role, created_at INTO v_result FROM vw_users WHERE id = v_new_id; | ||
| RETURN v_result; | ||
| END; | ||
| $$; |
25 changes: 25 additions & 0 deletions
25
testdata/diff/dependency/issue_480_view_function_recreate/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 tb_users ( | ||
| id uuid DEFAULT gen_random_uuid(), | ||
| is_deleted boolean DEFAULT false NOT NULL, | ||
| created_at timestamptz DEFAULT now(), | ||
| email text DEFAULT 'missing@missing.com' NOT NULL, | ||
| role text DEFAULT 'member' NOT NULL, | ||
| CONSTRAINT tb_users_pkey PRIMARY KEY (id) | ||
| ); | ||
|
|
||
| CREATE VIEW vw_users AS | ||
| SELECT id, email, role, created_at | ||
| FROM tb_users | ||
| WHERE is_deleted = FALSE; | ||
|
|
||
| CREATE FUNCTION fn_create_user(email TEXT, role TEXT DEFAULT 'member') | ||
| RETURNS vw_users AS $$ | ||
| DECLARE | ||
| v_result vw_users; | ||
| v_new_id UUID; | ||
| BEGIN | ||
| INSERT INTO tb_users (email, role) VALUES (email, role) RETURNING id INTO v_new_id; | ||
| SELECT id, email, role, created_at INTO v_result FROM vw_users WHERE id = v_new_id; | ||
| RETURN v_result; | ||
| END; | ||
| $$ LANGUAGE plpgsql SECURITY DEFINER; |
24 changes: 24 additions & 0 deletions
24
testdata/diff/dependency/issue_480_view_function_recreate/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,24 @@ | ||
| CREATE TABLE tb_users ( | ||
| id uuid DEFAULT gen_random_uuid(), | ||
| is_deleted boolean DEFAULT false NOT NULL, | ||
| created_at timestamptz DEFAULT now(), | ||
| email text DEFAULT 'missing@missing.com' NOT NULL, | ||
| CONSTRAINT tb_users_pkey PRIMARY KEY (id) | ||
| ); | ||
|
|
||
| CREATE VIEW vw_users AS | ||
| SELECT id, email, created_at | ||
| FROM tb_users | ||
| WHERE is_deleted = FALSE; | ||
|
|
||
| CREATE FUNCTION fn_create_user(email TEXT) | ||
| RETURNS vw_users AS $$ | ||
| DECLARE | ||
| v_result vw_users; | ||
| v_new_id UUID; | ||
| BEGIN | ||
| INSERT INTO tb_users (email) VALUES (email) RETURNING id INTO v_new_id; | ||
| SELECT id, email, created_at INTO v_result FROM vw_users WHERE id = v_new_id; | ||
| RETURN v_result; | ||
| END; | ||
| $$ LANGUAGE plpgsql SECURITY DEFINER; |
44 changes: 44 additions & 0 deletions
44
testdata/diff/dependency/issue_480_view_function_recreate/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,44 @@ | ||
| { | ||
| "version": "1.0.0", | ||
| "pgschema_version": "1.11.0", | ||
| "created_at": "1970-01-01T00:00:00Z", | ||
| "source_fingerprint": { | ||
| "hash": "c7ede31c4d93f537192a343c3b52ae33b76c573082ad077bfd20a09419482c9d" | ||
| }, | ||
| "groups": [ | ||
| { | ||
| "steps": [ | ||
| { | ||
| "sql": "DROP FUNCTION IF EXISTS fn_create_user(text);", | ||
| "type": "function", | ||
| "operation": "drop", | ||
| "path": "public.fn_create_user" | ||
| }, | ||
| { | ||
| "sql": "ALTER TABLE tb_users ADD COLUMN role text DEFAULT 'member' NOT NULL;", | ||
| "type": "table.column", | ||
| "operation": "create", | ||
| "path": "public.tb_users.role" | ||
| }, | ||
| { | ||
| "sql": "DROP VIEW IF EXISTS vw_users RESTRICT;", | ||
| "type": "view", | ||
| "operation": "alter", | ||
| "path": "public.vw_users" | ||
| }, | ||
| { | ||
| "sql": "CREATE OR REPLACE VIEW vw_users AS\n SELECT id,\n email,\n role,\n created_at\n FROM tb_users\n WHERE is_deleted = false;", | ||
| "type": "view", | ||
| "operation": "alter", | ||
| "path": "public.vw_users" | ||
| }, | ||
| { | ||
| "sql": "CREATE OR REPLACE FUNCTION fn_create_user(\n email text,\n role text DEFAULT 'member'\n)\nRETURNS vw_users\nLANGUAGE plpgsql\nVOLATILE\nSECURITY DEFINER\nAS $$\nDECLARE\n v_result vw_users;\n v_new_id UUID;\nBEGIN\n INSERT INTO tb_users (email, role) VALUES (email, role) RETURNING id INTO v_new_id;\n SELECT id, email, role, created_at INTO v_result FROM vw_users WHERE id = v_new_id;\n RETURN v_result;\nEND;\n$$;", | ||
| "type": "function", | ||
| "operation": "create", | ||
| "path": "public.fn_create_user" | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } |
32 changes: 32 additions & 0 deletions
32
testdata/diff/dependency/issue_480_view_function_recreate/plan.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,32 @@ | ||
| DROP FUNCTION IF EXISTS fn_create_user(text); | ||
|
|
||
| ALTER TABLE tb_users ADD COLUMN role text DEFAULT 'member' NOT NULL; | ||
|
|
||
| DROP VIEW IF EXISTS vw_users RESTRICT; | ||
|
|
||
| CREATE OR REPLACE VIEW vw_users AS | ||
| SELECT id, | ||
| email, | ||
| role, | ||
| created_at | ||
| FROM tb_users | ||
| WHERE is_deleted = false; | ||
|
|
||
| CREATE OR REPLACE FUNCTION fn_create_user( | ||
| email text, | ||
| role text DEFAULT 'member' | ||
| ) | ||
| RETURNS vw_users | ||
| LANGUAGE plpgsql | ||
| VOLATILE | ||
| SECURITY DEFINER | ||
| AS $$ | ||
| DECLARE | ||
| v_result vw_users; | ||
| v_new_id UUID; | ||
| BEGIN | ||
| INSERT INTO tb_users (email, role) VALUES (email, role) RETURNING id INTO v_new_id; | ||
| SELECT id, email, role, created_at INTO v_result FROM vw_users WHERE id = v_new_id; | ||
| RETURN v_result; | ||
| END; | ||
| $$; |
53 changes: 53 additions & 0 deletions
53
testdata/diff/dependency/issue_480_view_function_recreate/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,53 @@ | ||
| Plan: 1 to add, 2 to modify, 1 to drop. | ||
|
|
||
| Summary by type: | ||
| functions: 1 to add, 1 to drop | ||
| tables: 1 to modify | ||
| views: 1 to modify | ||
|
|
||
| Functions: | ||
| - fn_create_user | ||
| + fn_create_user | ||
|
|
||
| Tables: | ||
| ~ tb_users | ||
| + role (column) | ||
|
|
||
| Views: | ||
| ~ vw_users | ||
|
|
||
| DDL to be executed: | ||
| -------------------------------------------------- | ||
|
|
||
| DROP FUNCTION IF EXISTS fn_create_user(text); | ||
|
|
||
| ALTER TABLE tb_users ADD COLUMN role text DEFAULT 'member' NOT NULL; | ||
|
|
||
| DROP VIEW IF EXISTS vw_users RESTRICT; | ||
|
|
||
| CREATE OR REPLACE VIEW vw_users AS | ||
| SELECT id, | ||
| email, | ||
| role, | ||
| created_at | ||
| FROM tb_users | ||
| WHERE is_deleted = false; | ||
|
|
||
| CREATE OR REPLACE FUNCTION fn_create_user( | ||
| email text, | ||
| role text DEFAULT 'member' | ||
| ) | ||
| RETURNS vw_users | ||
| LANGUAGE plpgsql | ||
| VOLATILE | ||
| SECURITY DEFINER | ||
| AS $$ | ||
| DECLARE | ||
| v_result vw_users; | ||
| v_new_id UUID; | ||
| BEGIN | ||
| INSERT INTO tb_users (email, role) VALUES (email, role) RETURNING id INTO v_new_id; | ||
| SELECT id, email, role, created_at INTO v_result FROM vw_users WHERE id = v_new_id; | ||
| RETURN v_result; | ||
| END; | ||
| $$; |
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.
Uh oh!
There was an error while loading. Please reload this page.