-
Notifications
You must be signed in to change notification settings - Fork 810
Add support of DEPENDS/NO DEPENDS ON EXTENSION for ALTER FUNCTION.#6385 #9170
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
82 changes: 82 additions & 0 deletions
82
..._groups/servers/databases/schemas/functions/templates/functions/pg/sql/13_plus/create.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,82 @@ | ||
| {% import 'macros/functions/security.macros' as SECLABEL %} | ||
| {% import 'macros/functions/privilege.macros' as PRIVILEGE %} | ||
| {% import 'macros/functions/variable.macros' as VARIABLE %} | ||
| {% set is_columns = [] %} | ||
| {% set exclude_quoting = ['search_path'] %} | ||
| {% if data %} | ||
| {% if query_for == 'sql_panel' and func_def is defined %} | ||
| CREATE{% if query_type is defined %}{{' OR REPLACE'}}{% endif %} FUNCTION {{func_def}} | ||
| {% else %} | ||
| CREATE{% if query_type is defined %}{{' OR REPLACE'}}{% endif %} FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({% if data.arguments %} | ||
| {% for p in data.arguments %}{% if p.argmode %}{{p.argmode}} {% endif %}{% if p.argname %}{{ conn|qtIdent(p.argname) }} {% endif %}{% if p.argtype %}{{ p.argtype }}{% endif %}{% if p.argdefval %} DEFAULT {{p.argdefval}}{% endif %} | ||
| {% if not loop.last %}, {% endif %} | ||
| {% endfor %} | ||
| {% endif -%} | ||
| ) | ||
| {% endif %} | ||
| RETURNS{% if data.proretset and (data.prorettypename.startswith('SETOF ') or data.prorettypename.startswith('TABLE')) %} {{ data.prorettypename }} {% elif data.proretset %} SETOF {{ data.prorettypename }}{% else %} {{ data.prorettypename }}{% endif %} | ||
|
|
||
| LANGUAGE {{ data.lanname|qtLiteral(conn) }} | ||
| {% if data.procost %} | ||
| COST {{data.procost}} | ||
| {% endif %} | ||
| {% if data.provolatile %}{% if data.provolatile == 'i' %}IMMUTABLE{% elif data.provolatile == 's' %}STABLE{% else %}VOLATILE{% endif %} {% endif %}{% if data.proleakproof %}LEAKPROOF {% endif %} | ||
| {% if data.proisstrict %}STRICT {% endif %} | ||
| {% if data.prosecdef %}SECURITY DEFINER {% endif %} | ||
| {% if data.proiswindow %}WINDOW {% endif %} | ||
| {% if data.proparallel and (data.proparallel == 'r' or data.proparallel == 's' or data.proparallel == 'u') %} | ||
| {% if data.proparallel == 'r' %}PARALLEL RESTRICTED {% elif data.proparallel == 's' %}PARALLEL SAFE {% elif data.proparallel == 'u' %}PARALLEL UNSAFE{% endif %}{% endif %} | ||
| {% if data.prorows and (data.prorows | int) > 0 %} | ||
|
|
||
| ROWS {{data.prorows}} | ||
| {% endif %} | ||
| {% if data.prosupportfunc %} | ||
| SUPPORT {{ data.prosupportfunc }} | ||
| {% endif -%} | ||
| {% if data.variables %}{% for v in data.variables %} | ||
|
|
||
| SET {{ conn|qtIdent(v.name) }}={% if v.name in exclude_quoting %}{{ v.value }}{% else %}{{ v.value|qtLiteral(conn) }}{% endif %}{% endfor %} | ||
| {% endif %} | ||
|
|
||
| AS {% if data.lanname == 'c' %} | ||
| {{ data.probin|qtLiteral(conn) }}, {{ data.prosrc_c|qtLiteral(conn) }} | ||
| {% else %} | ||
| $BODY${{ data.prosrc }}$BODY${% endif -%}; | ||
| {% if data.funcowner %} | ||
|
|
||
| ALTER FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args_without}}) | ||
| OWNER TO {{ conn|qtIdent(data.funcowner) }}; | ||
| {% endif -%} | ||
|
|
||
| {% if data.dependsonextensions %} | ||
| {% for ext in data.dependsonextensions %} | ||
|
|
||
| ALTER FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args_without}}) | ||
| DEPENDS ON EXTENSION {{ conn|qtIdent(ext) }}; | ||
| {% endfor %} | ||
| {% endif %} | ||
|
|
||
| {% if data.acl %} | ||
| {% for p in data.acl %} | ||
|
|
||
| {{ PRIVILEGE.SET(conn, "FUNCTION", p.grantee, data.name, p.without_grant, p.with_grant, data.pronamespace, data.func_args_without)}} | ||
| {% endfor %}{% endif %} | ||
| {% if data.revoke_all %} | ||
|
|
||
| {{ PRIVILEGE.UNSETALL(conn, "FUNCTION", "PUBLIC", data.name, data.pronamespace, data.func_args_without)}} | ||
| {% endif %} | ||
| {% if data.description %} | ||
|
|
||
| COMMENT ON FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({{data.func_args_without}}) | ||
| IS {{ data.description|qtLiteral(conn) }}; | ||
| {% endif -%} | ||
| {% if data.seclabels %} | ||
| {% for r in data.seclabels %} | ||
| {% if r.label and r.provider %} | ||
|
|
||
| {{ SECLABEL.SET(conn, 'FUNCTION', data.name, r.provider, r.label, data.pronamespace, data.func_args_without) }} | ||
| {% endif %} | ||
| {% endfor %} | ||
| {% endif -%} | ||
|
|
||
| {% endif %} |
49 changes: 49 additions & 0 deletions
49
...ups/servers/databases/schemas/functions/templates/functions/pg/sql/13_plus/properties.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,49 @@ | ||
| SELECT | ||
| pr.oid, pr.xmin, | ||
| CASE WHEN pr.prokind = 'w' THEN true ELSE false END AS proiswindow, | ||
| pr.prosrc, pr.prosrc AS prosrc_c, pr.pronamespace, pr.prolang, pr.procost, pr.prorows, pr.prokind, | ||
| pr.prosecdef, pr.proleakproof, pr.proisstrict, pr.proretset, pr.provolatile, pr.proparallel, | ||
| pr.pronargs, pr.prorettype, pr.proallargtypes, pr.proargmodes, pr.probin, pr.proacl, | ||
| pr.proname, pr.proname AS name, pg_catalog.pg_get_function_result(pr.oid) AS prorettypename, | ||
| typns.nspname AS typnsp, lanname, proargnames, pg_catalog.oidvectortypes(proargtypes) AS proargtypenames, | ||
| pg_catalog.pg_get_expr(proargdefaults, 'pg_catalog.pg_class'::regclass) AS proargdefaultvals, | ||
| pr.pronargdefaults, proconfig, pg_catalog.pg_get_userbyid(proowner) AS funcowner, description, | ||
| ( | ||
| SELECT array_agg(DISTINCT e.extname) | ||
| FROM pg_depend d | ||
| JOIN pg_extension e ON d.refobjid = e.oid | ||
| WHERE d.objid = pr.oid | ||
| ) AS dependsonextensions, | ||
| CASE WHEN prosupport = 0::oid THEN '' | ||
| ELSE ( | ||
| SELECT pg_catalog.quote_ident(nspname) || '.' || pg_catalog.quote_ident(proname) AS tfunctions | ||
| FROM pg_catalog.pg_proc p, pg_catalog.pg_namespace n | ||
| WHERE p.pronamespace = n.oid | ||
| AND p.oid = pr.prosupport::OID | ||
| ) END AS prosupportfunc, | ||
| (SELECT | ||
| pg_catalog.array_agg(provider || '=' || label) | ||
| FROM | ||
| pg_catalog.pg_seclabel sl1 | ||
| WHERE | ||
| sl1.objoid=pr.oid) AS seclabels | ||
| FROM | ||
| pg_catalog.pg_proc pr | ||
| JOIN | ||
| pg_catalog.pg_type typ ON typ.oid=prorettype | ||
| JOIN | ||
| pg_catalog.pg_namespace typns ON typns.oid=typ.typnamespace | ||
| JOIN | ||
| pg_catalog.pg_language lng ON lng.oid=prolang | ||
| LEFT OUTER JOIN | ||
| pg_catalog.pg_description des ON (des.objoid=pr.oid AND des.classoid='pg_proc'::regclass and des.objsubid = 0) | ||
| WHERE | ||
| pr.prokind IN ('f', 'w') | ||
| AND typname NOT IN ('trigger', 'event_trigger') | ||
| {% if fnid %} | ||
| AND pr.oid = {{fnid}}::oid | ||
| {% else %} | ||
| AND pronamespace = {{scid}}::oid | ||
| {% endif %} | ||
| ORDER BY | ||
| proname; |
146 changes: 146 additions & 0 deletions
146
..._groups/servers/databases/schemas/functions/templates/functions/pg/sql/13_plus/update.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,146 @@ | ||
| {% import 'macros/functions/security.macros' as SECLABEL %} | ||
| {% import 'macros/functions/privilege.macros' as PRIVILEGE %} | ||
| {% import 'macros/functions/variable.macros' as VARIABLE %}{% if data %} | ||
| {% set name = o_data.name %} | ||
| {% set exclude_quoting = ['search_path'] %} | ||
| {% set set_variables = [] %} | ||
| {% if 'merged_variables' in data and data.merged_variables|length > 0 %} | ||
| {% set set_variables = data.merged_variables %} | ||
| {% elif 'variables' in o_data and o_data.variables|length > 0 %} | ||
| {% set set_variables = o_data.variables %} | ||
| {% endif %} | ||
| {% if data.name %} | ||
| {% if data.name != o_data.name %} | ||
| ALTER FUNCTION {{ conn|qtIdent(o_data.pronamespace, o_data.name) }}({{ | ||
| o_data.proargtypenames }}) | ||
| RENAME TO {{ conn|qtIdent(data.name) }}; | ||
| {% set name = data.name %} | ||
| {% endif %} | ||
| {% endif -%} | ||
| {% if data.change_func %} | ||
|
|
||
| CREATE OR REPLACE FUNCTION {{ conn|qtIdent(o_data.pronamespace, name) }}({% if data.arguments %} | ||
| {% for p in data.arguments %}{% if p.argmode %}{{p.argmode}} {% endif %}{% if p.argname %}{{ conn|qtIdent(p.argname) }} {% endif %}{% if p.argtype %}{{ p.argtype }}{% endif %}{% if p.argdefval %} DEFAULT {{p.argdefval}}{% endif %} | ||
| {% if not loop.last %},{% endif %} | ||
| {% endfor %} | ||
| {% endif -%} | ||
| ) | ||
| RETURNS {% if 'prorettypename' in data %}{{ data.prorettypename }}{% else %}{{ o_data.prorettypename }}{% endif %} | ||
|
|
||
| {% if 'lanname' in data %} | ||
| LANGUAGE {{ data.lanname|qtLiteral(conn) }} {% else %} | ||
| LANGUAGE {{ o_data.lanname|qtLiteral(conn) }} | ||
| {% endif %}{% if 'provolatile' in data and data.provolatile %}{{ data.provolatile }} {% elif 'provolatile' not in data and o_data.provolatile %}{{ o_data.provolatile }}{% endif %} | ||
| {% if ('proleakproof' in data and data.proleakproof) or ('proleakproof' not in data and o_data.proleakproof) %} LEAKPROOF{% elif 'proleakproof' in data and not data.proleakproof %} NOT LEAKPROOF{% endif %} | ||
| {% if ('proisstrict' in data and data.proisstrict) or ('proisstrict' not in data and o_data.proisstrict) %} STRICT{% endif %} | ||
| {% if ('prosecdef' in data and data.prosecdef) or ('prosecdef' not in data and o_data.prosecdef) %} SECURITY DEFINER{% endif %} | ||
| {% if ('proiswindow' in data and data.proiswindow) or ('proiswindow' not in data and o_data.proiswindow) %} WINDOW{% endif %} | ||
|
|
||
| {% if 'proparallel' in data and data.proparallel %}PARALLEL {{ data.proparallel }}{% elif 'proparallel' not in data and o_data.proparallel %}PARALLEL {{ o_data.proparallel }}{% endif %} | ||
|
|
||
| {% if data.procost %}COST {{data.procost}}{% elif o_data.procost %}COST {{o_data.procost}}{% endif %}{% if data.prorows and data.prorows != '0' %} | ||
|
|
||
| ROWS {{data.prorows}}{% elif data.prorows is not defined and o_data.prorows and o_data.prorows != '0' %} ROWS {{o_data.prorows}} {%endif %} | ||
|
|
||
| {% if data.prosupportfunc %}SUPPORT {{ data.prosupportfunc }}{% elif data.prosupportfunc is not defined and o_data.prosupportfunc %}SUPPORT {{ o_data.prosupportfunc }}{% endif -%}{% if set_variables and set_variables|length > 0 %}{% for v in set_variables %} | ||
|
|
||
| SET {{ conn|qtIdent(v.name) }}={% if v.name in exclude_quoting %}{{ v.value }}{% else %}{{ v.value|qtLiteral(conn) }}{% endif %}{% endfor -%} | ||
| {% endif %} | ||
|
|
||
| AS {% if (data.lanname == 'c' or o_data.lanname == 'c') and ('probin' in data or 'prosrc_c' in data) %} | ||
| {% if 'probin' in data %}{{ data.probin|qtLiteral(conn) }}{% else %}{{ o_data.probin|qtLiteral(conn) }}{% endif %}, {% if 'prosrc_c' in data %}{{ data.prosrc_c|qtLiteral(conn) }}{% else %}{{ o_data.prosrc_c|qtLiteral(conn) }}{% endif %}{% elif 'prosrc' in data %} | ||
| $BODY${{ data.prosrc }}$BODY${% elif o_data.lanname == 'c' %} | ||
| {{ o_data.probin|qtLiteral(conn) }}, {{ o_data.prosrc_c|qtLiteral(conn) }}{% else %} | ||
| $BODY${{ o_data.prosrc }}$BODY${% endif -%}; | ||
| {% endif -%} | ||
| {% if data.funcowner %} | ||
|
|
||
| ALTER FUNCTION {{ conn|qtIdent(o_data.pronamespace, name) }}({{o_data.proargtypenames }}) | ||
| OWNER TO {{ conn|qtIdent(data.funcowner) }}; | ||
| {% endif -%} | ||
| {# The SQL generated below will change priviledges #} | ||
| {% if data.acl %} | ||
| {% if 'deleted' in data.acl %} | ||
| {% for priv in data.acl.deleted %} | ||
|
|
||
| {{ PRIVILEGE.UNSETALL(conn, 'FUNCTION', priv.grantee, name, o_data.pronamespace, o_data.proargtypenames) }} | ||
| {% endfor %} | ||
| {% endif -%} | ||
| {% if 'changed' in data.acl %} | ||
| {% for priv in data.acl.changed %} | ||
|
|
||
| {% if priv.grantee != priv.old_grantee %} | ||
| {{ PRIVILEGE.UNSETALL(conn, 'FUNCTION', priv.old_grantee, name, o_data.pronamespace, o_data.proargtypenames) }} | ||
| {% else %} | ||
| {{ PRIVILEGE.UNSETALL(conn, 'FUNCTION', priv.grantee, name, o_data.pronamespace, o_data.proargtypenames) }} | ||
| {% endif %} | ||
|
|
||
| {{ PRIVILEGE.SET(conn, 'FUNCTION', priv.grantee, name, priv.without_grant, priv.with_grant, o_data.pronamespace, o_data.proargtypenames) }} | ||
| {% endfor %} | ||
| {% endif -%} | ||
| {% if 'added' in data.acl %} | ||
| {% for priv in data.acl.added %} | ||
|
|
||
| {{ PRIVILEGE.SET(conn, 'FUNCTION', priv.grantee, name, priv.without_grant, priv.with_grant, o_data.pronamespace, o_data.proargtypenames) }} | ||
| {% endfor %}{% endif -%} | ||
| {% endif -%} | ||
| {% if data.change_func == False %} | ||
| {% if data.variables %} | ||
| {% if 'deleted' in data.variables and data.variables.deleted|length > 0 %} | ||
|
|
||
| {{ VARIABLE.UNSET(conn, 'FUNCTION', name, data.variables.deleted, o_data.pronamespace, o_data.proargtypenames) }} | ||
| {% endif -%} | ||
| {% if 'merged_variables' in data and data.merged_variables|length > 0 %} | ||
|
|
||
| {{ VARIABLE.SET(conn, 'FUNCTION', name, data.merged_variables, o_data.pronamespace, o_data.proargtypenames) }} | ||
| {% endif -%} | ||
| {% endif -%} | ||
| {% endif -%} | ||
| {% set seclabels = data.seclabels %} | ||
| {% if 'deleted' in seclabels and seclabels.deleted|length > 0 %} | ||
| {% for r in seclabels.deleted %} | ||
|
|
||
| {{ SECLABEL.UNSET(conn, 'FUNCTION', name, r.provider, o_data.pronamespace, o_data.proargtypenames) }} | ||
| {% endfor %} | ||
| {% endif -%} | ||
| {% if 'added' in seclabels and seclabels.added|length > 0 %} | ||
| {% for r in seclabels.added %} | ||
|
|
||
| {{ SECLABEL.SET(conn, 'FUNCTION', name, r.provider, r.label, o_data.pronamespace, o_data.proargtypenames) }} | ||
| {% endfor %} | ||
| {% endif -%} | ||
| {% if 'changed' in seclabels and seclabels.changed|length > 0 %} | ||
| {% for r in seclabels.changed %} | ||
|
|
||
| {{ SECLABEL.SET(conn, 'FUNCTION', name, r.provider, r.label, o_data.pronamespace, o_data.proargtypenames) }} | ||
| {% endfor %} | ||
| {% endif -%} | ||
| {% if data.description is defined and data.description != o_data.description%} | ||
|
|
||
| COMMENT ON FUNCTION {{ conn|qtIdent(o_data.pronamespace, name) }}({{o_data.proargtypenames }}) | ||
| IS {{ data.description|qtLiteral(conn) }}; | ||
| {% endif -%} | ||
|
|
||
| {% if data.pronamespace %} | ||
|
|
||
| ALTER FUNCTION {{ conn|qtIdent(o_data.pronamespace, name) }}({{o_data.proargtypenames }}) | ||
| SET SCHEMA {{ conn|qtIdent(data.pronamespace) }}; | ||
| {% endif -%} | ||
|
|
||
| {% set old_exts = (o_data.dependsonextensions or []) | list %} | ||
| {% set new_exts = data.dependsonextensions if 'dependsonextensions' in data else None %} | ||
|
|
||
| {% if new_exts is not none and old_exts != new_exts %} | ||
| {% for ext in (old_exts + new_exts) | unique %} | ||
|
|
||
| {% if ext in new_exts and ext not in old_exts %} | ||
| ALTER FUNCTION {{ conn|qtIdent(o_data.pronamespace, name) }}({{ o_data.proargtypenames }}) | ||
| DEPENDS ON EXTENSION {{ conn|qtIdent(ext) }}; | ||
| {% elif ext in old_exts and ext not in new_exts %} | ||
| ALTER FUNCTION {{ conn|qtIdent(o_data.pronamespace, name) }}({{ o_data.proargtypenames }}) | ||
| NO DEPENDS ON EXTENSION {{ conn|qtIdent(ext) }}; | ||
| {% endif %} | ||
| {% endfor %} | ||
| {% endif %} | ||
|
|
||
| {% endif %} |
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
Oops, something went wrong.
Oops, something went wrong.
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.