Add support of DEPENDS/NO DEPENDS ON EXTENSION for ALTER FUNCTION. #6385

pull/9210/head
Rohit Bhati 2025-10-01 13:49:03 +05:30 committed by GitHub
parent 5c9acc1c3d
commit 9e6ab295df
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
33 changed files with 1850 additions and 13 deletions

View File

@ -41,6 +41,9 @@ Use the fields in the *Definition* tab to define the function:
will change to an input text field.
* Use the drop-down listbox next to *Language* to select the implementation
language. The default is *sql*.
* Use the drop-down listbox next to *Depends on extensions* to select the extension that this function
depends on (for example, plpgsql). If set, dropping the extension will automatically drop the
function as well.
* Use the fields in the *Arguments* to define an argument. Click the *Add*
icon (+) to set parameters and values for the argument:

Binary file not shown.

Before

Width:  |  Height:  |  Size: 88 KiB

After

Width:  |  Height:  |  Size: 89 KiB

View File

@ -260,7 +260,7 @@ class FunctionView(PGChildNodeView, DataTypeReader, SchemaDiffObjectCompare):
list_params = []
if request.method == 'GET':
list_params = ['arguments', 'variables', 'proacl',
'seclabels', 'acl', 'args']
'seclabels', 'acl', 'args', 'dependsonextensions']
if key in list_params and req[key] != '' and req[key] is not None:
# Coverts string into python list as expected.
@ -1171,6 +1171,10 @@ class FunctionView(PGChildNodeView, DataTypeReader, SchemaDiffObjectCompare):
old_data['proparallel'] = \
parallel_dict[old_data['proparallel']]
if self.node_type == 'function' and \
old_data['dependsonextensions'] is None:
old_data['dependsonextensions'] = []
# If any of the below argument is changed,
# then CREATE OR REPLACE SQL statement should be called
fun_change_args = ['lanname', 'prosrc', 'probin', 'prosrc_c',

View File

@ -76,6 +76,7 @@ define('pgadmin.node.function', [
},
getSchema: function(treeNodeInfo, itemNodeData) {
let nodeObj = pgBrowser.Nodes['extension'];
return new FunctionSchema(
(privileges)=>getNodePrivilegeRoleSchema(this, treeNodeInfo, itemNodeData, privileges),
()=>getNodeVariableSchema(this, treeNodeInfo, itemNodeData, false, false),
@ -85,6 +86,16 @@ define('pgadmin.node.function', [
cacheLevel: 'database'
}
),
extensionsList:()=>getNodeAjaxOptions('nodes', nodeObj, treeNodeInfo, itemNodeData, { cacheLevel: 'server'},
(data)=>{
let res = [];
if (data && _.isArray(data)) {
_.each(data, function(d) {
res.push({label: d.label, value: d.label, data: d});
});
}
return res;
}),
getTypes: ()=>getNodeAjaxOptions('get_types', this, treeNodeInfo, itemNodeData),
getLanguage: ()=>getNodeAjaxOptions('get_languages', this, treeNodeInfo, itemNodeData),
getSupportFunctions: ()=>getNodeAjaxOptions('get_support_functions', this, treeNodeInfo, itemNodeData, {

View File

@ -137,6 +137,7 @@ export default class FunctionSchema extends BaseUISchema {
role: [],
schema: [],
getTypes: [],
extensionsList: [],
...fieldOptions,
};
}
@ -274,8 +275,21 @@ export default class FunctionSchema extends BaseUISchema {
return this.node_info && 'catalog' in this.node_info;
}
},
{
},{
id: 'dependsonextensions',
label: gettext('Depends on extensions'),
group: gettext('Definition'),
type: 'select',
options: this.fieldOptions.extensionsList,
controlProps: {
multiple: true,
allowClear: true,
allowSelectAll: true,
placeholder: gettext('Select the Depends on extensions...'),
},
min_version: 130000,
mode: ['create', 'edit', 'properties'],
},{
id: 'probin', label: gettext('Object file'), cell: 'string',
type: 'text', group: gettext('Definition'), deps: ['lanname'], visible:
function(state) {

View File

@ -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 %}

View File

@ -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;

View File

@ -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 %}

View File

@ -50,6 +50,15 @@ $BODY${{ data.prosrc }}$BODY${% endif -%};
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 %}

View File

@ -10,6 +10,12 @@ SELECT
pg_catalog.pg_get_function_sqlbody(pr.oid) AS prosrc_sql,
CASE WHEN pr.prosqlbody IS NOT NULL THEN true ELSE false END as is_pure_sql,
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

View File

@ -130,4 +130,20 @@ ALTER FUNCTION {{ conn|qtIdent(o_data.pronamespace, name) }}({{o_data.proargtype
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 %}

View File

@ -0,0 +1,83 @@
{% 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 %}

View File

@ -0,0 +1,43 @@
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 prosupport::text 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;

View File

@ -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 %}

View File

@ -50,6 +50,15 @@ $BODY${{ data.prosrc }}$BODY${% endif -%};
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 %}

View File

@ -8,6 +8,12 @@ SELECT
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,
pg_catalog.pg_get_function_sqlbody(pr.oid) AS prosrc_sql,
CASE WHEN pr.prosqlbody IS NOT NULL THEN true ELSE false END as is_pure_sql,
CASE WHEN prosupport = 0::oid THEN '' ELSE prosupport::text END AS prosupportfunc,

View File

@ -130,4 +130,20 @@ ALTER FUNCTION {{ conn|qtIdent(o_data.pronamespace, name) }}({{o_data.proargtype
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 %}

View File

@ -0,0 +1,2 @@
ALTER FUNCTION public."Function1_$%{}[]()&*^!@""'`\/#"(character varying)
NO DEPENDS ON EXTENSION postgres_fdw;

View File

@ -0,0 +1,22 @@
-- FUNCTION: public.Function1_$%{}[]()&*^!@"'`\/#(character varying)
-- DROP FUNCTION IF EXISTS public."Function1_$%{}[]()&*^!@""'`\/#"(character varying);
CREATE OR REPLACE FUNCTION public."Function1_$%{}[]()&*^!@""'`\/#"(
param character varying DEFAULT '1'::character varying)
RETURNS character varying
LANGUAGE 'plpgsql'
COST 100
VOLATILE LEAKPROOF STRICT SECURITY DEFINER WINDOW PARALLEL UNSAFE
SET enable_sort='true'
AS $BODY$
begin
select '1';
end
$BODY$;
ALTER FUNCTION public."Function1_$%{}[]()&*^!@""'`\/#"(character varying)
OWNER TO postgres;
ALTER FUNCTION public."Function1_$%{}[]()&*^!@""'`\/#"(character varying)
DEPENDS ON EXTENSION plpgsql;

View File

@ -0,0 +1,20 @@
CREATE FUNCTION public."Function1_$%{}[]()&*^!@""'`\/#"(IN param character varying DEFAULT '1')
RETURNS character varying
LANGUAGE 'plpgsql'
COST 100
VOLATILE LEAKPROOF STRICT SECURITY DEFINER WINDOW PARALLEL UNSAFE
SET enable_sort=true
AS $BODY$
begin
select '1';
end
$BODY$;
ALTER FUNCTION public."Function1_$%{}[]()&*^!@""'`\/#"(character varying)
OWNER TO postgres;
ALTER FUNCTION public."Function1_$%{}[]()&*^!@""'`\/#"(character varying)
DEPENDS ON EXTENSION plpgsql;
ALTER FUNCTION public."Function1_$%{}[]()&*^!@""'`\/#"(character varying)
DEPENDS ON EXTENSION postgres_fdw;

View File

@ -0,0 +1,25 @@
-- FUNCTION: public.Function1_$%{}[]()&*^!@"'`\/#(character varying)
-- DROP FUNCTION IF EXISTS public."Function1_$%{}[]()&*^!@""'`\/#"(character varying);
CREATE OR REPLACE FUNCTION public."Function1_$%{}[]()&*^!@""'`\/#"(
param character varying DEFAULT '1'::character varying)
RETURNS character varying
LANGUAGE 'plpgsql'
COST 100
VOLATILE LEAKPROOF STRICT SECURITY DEFINER WINDOW PARALLEL UNSAFE
SET enable_sort='true'
AS $BODY$
begin
select '1';
end
$BODY$;
ALTER FUNCTION public."Function1_$%{}[]()&*^!@""'`\/#"(character varying)
OWNER TO postgres;
ALTER FUNCTION public."Function1_$%{}[]()&*^!@""'`\/#"(character varying)
DEPENDS ON EXTENSION plpgsql;
ALTER FUNCTION public."Function1_$%{}[]()&*^!@""'`\/#"(character varying)
DEPENDS ON EXTENSION postgres_fdw;

View File

@ -0,0 +1,434 @@
{
"scenarios": [
{
"type": "create",
"name": "Create Extension",
"endpoint": "NODE-extension.obj",
"sql_endpoint": "NODE-extension.sql_id",
"data": {
"name": "postgres_fdw",
"version": "",
"relocatable": true
}
},
{
"type": "create",
"name": "Create function with extensions.",
"endpoint": "NODE-function.obj",
"msql_endpoint": "NODE-function.msql",
"sql_endpoint": "NODE-function.sql_id",
"data": {
"name": "Function1_$%{}[]()&*^!@\"'`\\/#",
"funcowner": "postgres",
"pronamespace": 2200,
"prorettypename": "character varying",
"lanname": "plpgsql",
"provolatile": "v",
"proretset": false,
"proisstrict": true,
"prosecdef": true,
"proiswindow": true,
"proparallel": "u",
"procost": "100",
"prorows": "0",
"proleakproof": true,
"arguments": [
{
"argtype": "character varying",
"argmode": "IN",
"argname": "param",
"argdefval": "'1'"
}
],
"prosrc": "begin\nselect '1';\nend",
"probin": "$libdir/",
"options": [],
"variables": [
{
"name": "enable_sort",
"value": true
}
],
"seclabels": [],
"acl": [],
"dependsonextensions": ["plpgsql", "postgres_fdw"],
"schema": "public"
},
"expected_sql_file": "create_function_on_depends.sql",
"expected_msql_file": "create_function_on_depends.msql"
},
{
"type": "alter",
"name": "Alter function with NO DEPENDS ON",
"endpoint": "NODE-function.obj_id",
"msql_endpoint": "NODE-function.msql_id",
"sql_endpoint": "NODE-function.sql_id",
"data": {
"dependsonextensions": ["plpgsql"]
},
"expected_sql_file": "alter_function_no_depends.sql",
"expected_msql_file": "alter_function_no_depends.msql"
},
{
"type": "delete",
"name": "Drop function",
"endpoint": "NODE-function.delete_id",
"data": {
}
},
{
"type": "create",
"name": "Create function with all options.",
"endpoint": "NODE-function.obj",
"msql_endpoint": "NODE-function.msql",
"sql_endpoint": "NODE-function.sql_id",
"data": {
"name": "Function1_$%{}[]()&*^!@\"'`\\/#",
"funcowner": "postgres",
"pronamespace": 2200,
"prorettypename": "character varying",
"lanname": "plpgsql",
"provolatile": "v",
"proretset": false,
"proisstrict": true,
"prosecdef": true,
"proiswindow": true,
"proparallel": "u",
"procost": "100",
"prorows": "0",
"proleakproof": true,
"arguments": [
{
"argtype": "character varying",
"argmode": "IN",
"argname": "param",
"argdefval": "'1'"
}
],
"prosrc": "begin\nselect '1';\nend",
"probin": "$libdir/",
"options": [],
"variables": [
{
"name": "enable_sort",
"value": true
}
],
"seclabels": [],
"acl": [],
"schema": "public"
},
"expected_sql_file": "create_function.sql",
"expected_msql_file": "create_function.msql"
},
{
"type": "alter",
"name": "Alter function comment",
"endpoint": "NODE-function.obj_id",
"msql_endpoint": "NODE-function.msql_id",
"sql_endpoint": "NODE-function.sql_id",
"data": {
"description": "Some comment"
},
"expected_sql_file": "alter_function_comment.sql",
"expected_msql_file": "alter_function_comment.msql"
},
{
"type": "delete",
"name": "Drop function",
"endpoint": "NODE-function.delete_id",
"data": {
}
},
{
"type": "create",
"name": "Create function for alter.",
"endpoint": "NODE-function.obj",
"msql_endpoint": "NODE-function.msql",
"sql_endpoint": "NODE-function.sql_id",
"data": {
"name": "Function2_$%{}[]()&*^!@\"'`\\/#",
"funcowner": "postgres",
"pronamespace": 2200,
"prorettypename": "character varying",
"lanname": "plpgsql",
"provolatile": "v",
"proparallel": "u",
"arguments": [],
"procost": "100",
"prosrc": "begin\nselect '1';\nend",
"probin": "$libdir/",
"options": [],
"variables": [
{
"name": "enable_sort",
"value": true
}
],
"seclabels": [],
"acl": [],
"schema": "public"
},
"expected_sql_file": "create_function_for_alter.sql",
"expected_msql_file": "create_function_for_alter.msql"
},
{
"type": "alter",
"name": "Alter function rename.",
"endpoint": "NODE-function.obj_id",
"msql_endpoint": "NODE-function.msql_id",
"sql_endpoint": "NODE-function.sql_id",
"data": {
"name":"Function3_$%{}[]()&*^!@\"'`\\/#"
},
"expected_sql_file": "alter_function_rename.sql",
"expected_msql_file": "alter_function_rename.msql"
},
{
"type": "alter",
"name": "Alter function code and add parameters.",
"endpoint": "NODE-function.obj_id",
"msql_endpoint": "NODE-function.msql_id",
"sql_endpoint": "NODE-function.sql_id",
"data": {
"prosrc": "begin\nselect '2';\nend\n",
"variables": {
"added": [
{
"name": "application_name",
"value": "appname"
}
]
}
},
"expected_sql_file": "alter_function_add_parameter.sql",
"expected_msql_file": "alter_function_add_parameter.msql"
},
{
"type": "alter",
"name": "Alter function delete parameters.",
"endpoint": "NODE-function.obj_id",
"msql_endpoint": "NODE-function.msql_id",
"sql_endpoint": "NODE-function.sql_id",
"data": {
"variables": {
"deleted": [
{
"name": "application_name",
"value": true
}
]
}
},
"expected_sql_file": "alter_function_delete_parameter.sql",
"expected_msql_file": "alter_function_delete_parameter.msql"
},
{
"type": "delete",
"name": "Drop function",
"endpoint": "NODE-function.delete_id",
"data": {
}
},
{
"type": "create",
"name": "Create function for acl.",
"endpoint": "NODE-function.obj",
"msql_endpoint": "NODE-function.msql",
"sql_endpoint": "NODE-function.sql_id",
"data": {
"name": "Function2_$%{}[]()&*^!@\"'`\\/#",
"funcowner": "postgres",
"pronamespace": 2200,
"prorettypename": "character varying",
"lanname": "plpgsql",
"provolatile": "v",
"proparallel": "u",
"arguments": [],
"procost": "100",
"prosrc": "begin\nselect '1';\nend",
"probin": "$libdir/",
"options": [],
"variables": [
{
"name": "enable_sort",
"value": true
}
],
"seclabels": [],
"acl": [],
"schema": "public"
},
"expected_sql_file": "create_function_for_alter.sql",
"expected_msql_file": "create_function_for_alter.msql"
},
{
"type": "alter",
"name": "Alter function add acl.",
"endpoint": "NODE-function.obj_id",
"msql_endpoint": "NODE-function.msql_id",
"sql_endpoint": "NODE-function.sql_id",
"data": {
"acl": {
"added": [
{
"grantee": "postgres",
"grantor": "postgres",
"privileges": [
{
"privilege_type": "X",
"privilege": true,
"with_grant": false
}
]
}
]
}
},
"expected_sql_file": "alter_function_add_acl.sql",
"expected_msql_file": "alter_function_add_acl.msql"
},
{
"type": "alter",
"name": "Alter function remove partial privileges.",
"endpoint": "NODE-function.obj_id",
"msql_endpoint": "NODE-function.msql_id",
"sql_endpoint": "NODE-function.sql_id",
"data": {
"acl": {
"deleted": [
{
"grantee": "PUBLIC",
"grantor": "postgres",
"privileges": [
{
"privilege_type": "X",
"privilege": true,
"with_grant": false
}
]
}
]
}
}
},
{
"type": "alter",
"name": "Alter function change grantee in privileges.",
"endpoint": "NODE-function.obj_id",
"msql_endpoint": "NODE-function.msql_id",
"sql_endpoint": "NODE-function.sql_id",
"data": {
"acl": {
"changed": [
{
"grantee": "PUBLIC",
"grantor": "postgres",
"old_grantee": "postgres",
"privileges": [
{
"privilege_type": "X",
"privilege": true,
"with_grant": false
}
]
}
]
}
},
"expected_sql_file": "alter_function_change_grantee_acl.sql",
"expected_msql_file": "alter_function_change_grantee_acl.msql"
},
{
"type": "alter",
"name": "Alter function delete acl.",
"endpoint": "NODE-function.obj_id",
"msql_endpoint": "NODE-function.msql_id",
"sql_endpoint": "NODE-function.sql_id",
"data": {
"acl": {
"deleted": [
{
"grantee": "PUBLIC",
"grantor": "postgres",
"privileges": [
{
"privilege_type": "X",
"privilege": true,
"with_grant": false
}
]
},
{
"grantee": "postgres",
"grantor": "postgres",
"privileges": [
{
"privilege_type": "X",
"privilege": true,
"with_grant": false
}
]
}
]
}
},
"expected_sql_file": "alter_function_delete_acl.sql",
"expected_msql_file": "alter_function_delete_acl.msql"
},
{
"type": "delete",
"name": "Drop function",
"endpoint": "NODE-function.delete_id",
"data": {
}
},
{
"type": "create",
"endpoint": "NODE-function.obj",
"msql_endpoint": "NODE-function.msql",
"sql_endpoint": "NODE-function.sql_id",
"name": "Create function with custom return type.",
"data": {
"name": "Function3_$%{}[]()&*^!@\"'`\\/#",
"funcowner": "postgres",
"pronamespace": 2200,
"prorettypename": "table(val character varying)",
"lanname": "plpgsql",
"provolatile": "v",
"proretset": false,
"proisstrict": true,
"prosecdef": true,
"proiswindow": true,
"proparallel": "u",
"procost": "100",
"prorows": "0",
"proleakproof": true,
"arguments": [
{
"argtype": "character varying",
"argmode": "IN",
"argname": "param",
"argdefval": "'1'"
}
],
"prosrc": "begin\n return query select '1'::character varying;\nend",
"probin": "$libdir/",
"options": [],
"variables": [],
"seclabels": [],
"acl": [],
"schema": "public"
},
"expected_sql_file": "create_function_with_custom_return.sql",
"expected_msql_file": "create_function_with_custom_return.msql"
},
{
"type": "delete",
"name": "Drop function",
"endpoint": "NODE-function.delete_id",
"data": {
}
}
]
}

View File

@ -1,5 +1,81 @@
{
"scenarios": [
{
"type": "create",
"name": "Create Extension",
"endpoint": "NODE-extension.obj",
"sql_endpoint": "NODE-extension.sql_id",
"data": {
"name": "postgres_fdw",
"version": "",
"relocatable": true
}
},
{
"type": "create",
"name": "Create function with extensions.",
"endpoint": "NODE-function.obj",
"msql_endpoint": "NODE-function.msql",
"sql_endpoint": "NODE-function.sql_id",
"data": {
"name": "Function1_$%{}[]()&*^!@\"'`\\/#",
"funcowner": "postgres",
"pronamespace": 2200,
"prorettypename": "character varying",
"lanname": "plpgsql",
"provolatile": "v",
"proretset": false,
"proisstrict": true,
"prosecdef": true,
"proiswindow": true,
"proparallel": "u",
"procost": "100",
"prorows": "0",
"proleakproof": true,
"arguments": [
{
"argtype": "character varying",
"argmode": "IN",
"argname": "param",
"argdefval": "'1'"
}
],
"prosrc": "begin\nselect '1';\nend",
"probin": "$libdir/",
"options": [],
"variables": [
{
"name": "enable_sort",
"value": true
}
],
"seclabels": [],
"acl": [],
"dependsonextensions": ["plpgsql", "postgres_fdw"],
"schema": "public"
},
"expected_sql_file": "create_function_on_depends.sql",
"expected_msql_file": "create_function_on_depends.msql"
},
{
"type": "alter",
"name": "Alter function with NO DEPENDS ON",
"endpoint": "NODE-function.obj_id",
"msql_endpoint": "NODE-function.msql_id",
"sql_endpoint": "NODE-function.sql_id",
"data": {
"dependsonextensions": ["plpgsql"]
},
"expected_sql_file": "alter_function_no_depends.sql",
"expected_msql_file": "alter_function_no_depends.msql"
},
{
"type": "delete",
"name": "Drop function",
"endpoint": "NODE-function.delete_id",
"data": {
}
},
{
"type": "create",
"name": "Create function with all options.",

View File

@ -0,0 +1,2 @@
ALTER FUNCTION public."Function1_$%{}[]()&*^!@""'`\/#"(character varying)
NO DEPENDS ON EXTENSION postgres_fdw;

View File

@ -0,0 +1,22 @@
-- FUNCTION: public.Function1_$%{}[]()&*^!@"'`\/#(character varying)
-- DROP FUNCTION IF EXISTS public."Function1_$%{}[]()&*^!@""'`\/#"(character varying);
CREATE OR REPLACE FUNCTION public."Function1_$%{}[]()&*^!@""'`\/#"(
param character varying DEFAULT '1'::character varying)
RETURNS character varying
LANGUAGE 'plpgsql'
COST 100
VOLATILE LEAKPROOF STRICT SECURITY DEFINER WINDOW PARALLEL UNSAFE
SET enable_sort='true'
AS $BODY$
begin
select '1';
end
$BODY$;
ALTER FUNCTION public."Function1_$%{}[]()&*^!@""'`\/#"(character varying)
OWNER TO enterprisedb;
ALTER FUNCTION public."Function1_$%{}[]()&*^!@""'`\/#"(character varying)
DEPENDS ON EXTENSION plpgsql;

View File

@ -0,0 +1,20 @@
CREATE FUNCTION public."Function1_$%{}[]()&*^!@""'`\/#"(IN param character varying DEFAULT '1')
RETURNS character varying
LANGUAGE 'plpgsql'
COST 100
VOLATILE LEAKPROOF STRICT SECURITY DEFINER WINDOW PARALLEL UNSAFE
SET enable_sort=true
AS $BODY$
begin
select '1';
end
$BODY$;
ALTER FUNCTION public."Function1_$%{}[]()&*^!@""'`\/#"(character varying)
OWNER TO enterprisedb;
ALTER FUNCTION public."Function1_$%{}[]()&*^!@""'`\/#"(character varying)
DEPENDS ON EXTENSION plpgsql;
ALTER FUNCTION public."Function1_$%{}[]()&*^!@""'`\/#"(character varying)
DEPENDS ON EXTENSION postgres_fdw;

View File

@ -0,0 +1,25 @@
-- FUNCTION: public.Function1_$%{}[]()&*^!@"'`\/#(character varying)
-- DROP FUNCTION IF EXISTS public."Function1_$%{}[]()&*^!@""'`\/#"(character varying);
CREATE OR REPLACE FUNCTION public."Function1_$%{}[]()&*^!@""'`\/#"(
param character varying DEFAULT '1'::character varying)
RETURNS character varying
LANGUAGE 'plpgsql'
COST 100
VOLATILE LEAKPROOF STRICT SECURITY DEFINER WINDOW PARALLEL UNSAFE
SET enable_sort='true'
AS $BODY$
begin
select '1';
end
$BODY$;
ALTER FUNCTION public."Function1_$%{}[]()&*^!@""'`\/#"(character varying)
OWNER TO enterprisedb;
ALTER FUNCTION public."Function1_$%{}[]()&*^!@""'`\/#"(character varying)
DEPENDS ON EXTENSION plpgsql;
ALTER FUNCTION public."Function1_$%{}[]()&*^!@""'`\/#"(character varying)
DEPENDS ON EXTENSION postgres_fdw;

View File

@ -0,0 +1,446 @@
{
"scenarios": [
{
"type": "create",
"name": "Create Extension",
"endpoint": "NODE-extension.obj",
"sql_endpoint": "NODE-extension.sql_id",
"data": {
"name": "postgres_fdw",
"version": "",
"relocatable": true
}
},
{
"type": "create",
"name": "Create function with extensions.",
"endpoint": "NODE-function.obj",
"msql_endpoint": "NODE-function.msql",
"sql_endpoint": "NODE-function.sql_id",
"data": {
"name": "Function1_$%{}[]()&*^!@\"'`\\/#",
"funcowner": "enterprisedb",
"pronamespace": 2200,
"prorettypename": "character varying",
"lanname": "plpgsql",
"provolatile": "v",
"proretset": false,
"proisstrict": true,
"prosecdef": true,
"proiswindow": true,
"proparallel": "u",
"procost": "100",
"prorows": "0",
"proleakproof": true,
"arguments": [
{
"argtype": "character varying",
"argmode": "IN",
"argname": "param",
"argdefval": "'1'"
}
],
"prosrc": "begin\nselect '1';\nend",
"probin": "$libdir/",
"options": [],
"variables": [
{
"name": "enable_sort",
"value": true
}
],
"seclabels": [],
"acl": [],
"dependsonextensions": ["plpgsql", "postgres_fdw"],
"schema": "public"
},
"expected_sql_file": "create_function_on_depends.sql",
"expected_msql_file": "create_function_on_depends.msql"
},
{
"type": "alter",
"name": "Alter function with NO DEPENDS ON",
"endpoint": "NODE-function.obj_id",
"msql_endpoint": "NODE-function.msql_id",
"sql_endpoint": "NODE-function.sql_id",
"data": {
"dependsonextensions": ["plpgsql"]
},
"expected_sql_file": "alter_function_no_depends.sql",
"expected_msql_file": "alter_function_no_depends.msql"
},
{
"type": "delete",
"name": "Drop function",
"endpoint": "NODE-function.delete_id",
"data": {
}
},
{
"type": "create",
"name": "Create function with all options.",
"endpoint": "NODE-function.obj",
"msql_endpoint": "NODE-function.msql",
"sql_endpoint": "NODE-function.sql_id",
"data": {
"name": "Function1_$%{}[]()&*^!@\"'`\\/#",
"funcowner": "enterprisedb",
"pronamespace": 2200,
"prorettypename": "character varying",
"lanname": "plpgsql",
"provolatile": "v",
"proretset": false,
"proisstrict": true,
"prosecdef": true,
"proiswindow": true,
"proparallel": "u",
"procost": "100",
"prorows": "0",
"proleakproof": true,
"arguments": [
{
"argtype": "character varying",
"argmode": "IN",
"argname": "param",
"argdefval": "'1'"
}
],
"prosrc": "begin\nselect '1';\nend",
"probin": "$libdir/",
"options": [],
"variables": [
{
"name": "enable_sort",
"value": true
}
],
"seclabels": [],
"acl": [],
"schema": "public"
},
"expected_sql_file": "create_function.sql",
"expected_msql_file": "create_function.msql"
},
{
"type": "alter",
"name": "Alter function comment",
"endpoint": "NODE-function.obj_id",
"msql_endpoint": "NODE-function.msql_id",
"sql_endpoint": "NODE-function.sql_id",
"data": {
"description": "Some comment"
},
"expected_sql_file": "alter_function_comment.sql",
"expected_msql_file": "alter_function_comment.msql"
},
{
"type": "delete",
"name": "Drop function",
"endpoint": "NODE-function.delete_id",
"data": {
}
},
{
"type": "create",
"name": "Create function for alter.",
"endpoint": "NODE-function.obj",
"msql_endpoint": "NODE-function.msql",
"sql_endpoint": "NODE-function.sql_id",
"data": {
"name": "Function2_$%{}[]()&*^!@\"'`\\/#",
"funcowner": "enterprisedb",
"pronamespace": 2200,
"prorettypename": "character varying",
"lanname": "plpgsql",
"provolatile": "v",
"proparallel": "u",
"prosecdef": true,
"arguments": [],
"procost": "100",
"prosrc": "begin\nselect '1';\nend",
"probin": "$libdir/",
"options": [],
"variables": [
{
"name": "enable_sort",
"value": true
}
],
"seclabels": [],
"acl": [],
"schema": "public"
},
"expected_sql_file": "create_function_for_alter.sql",
"expected_msql_file": "create_function_for_alter.msql"
},
{
"type": "alter",
"name": "Alter function rename.",
"endpoint": "NODE-function.obj_id",
"msql_endpoint": "NODE-function.msql_id",
"sql_endpoint": "NODE-function.sql_id",
"data": {
"name": "Function3_$%{}[]()&*^!@\"'`\\/#"
},
"expected_sql_file": "alter_function_rename.sql",
"expected_msql_file": "alter_function_rename.msql"
},
{
"type": "alter",
"name": "Alter function code and add parameters.",
"endpoint": "NODE-function.obj_id",
"msql_endpoint": "NODE-function.msql_id",
"sql_endpoint": "NODE-function.sql_id",
"data": {
"prosrc": "begin\nselect '2';\nend\n",
"variables": {
"added": [
{
"name": "application_name",
"value": "appname"
}
]
}
},
"expected_sql_file": "alter_function_add_parameter.sql"
},
{
"type": "alter",
"name": "Alter function delete parameters.",
"endpoint": "NODE-function.obj_id",
"msql_endpoint": "NODE-function.msql_id",
"sql_endpoint": "NODE-function.sql_id",
"data": {
"variables": {
"deleted": [
{
"name": "application_name",
"value": true
}
]
}
},
"expected_sql_file": "alter_function_delete_parameter.sql",
"expected_msql_file": "alter_function_delete_parameter.msql"
},
{
"type": "delete",
"name": "Drop function",
"endpoint": "NODE-function.delete_id",
"data": {
}
},
{
"type": "create",
"name": "Create function for acl.",
"endpoint": "NODE-function.obj",
"msql_endpoint": "NODE-function.msql",
"sql_endpoint": "NODE-function.sql_id",
"data": {
"name": "Function2_$%{}[]()&*^!@\"'`\\/#",
"funcowner": "enterprisedb",
"pronamespace": 2200,
"prorettypename": "character varying",
"lanname": "plpgsql",
"provolatile": "v",
"proparallel": "u",
"prosecdef": true,
"arguments": [],
"procost": "100",
"prosrc": "begin\nselect '1';\nend",
"probin": "$libdir/",
"options": [],
"variables": [
{
"name": "enable_sort",
"value": true
}
],
"seclabels": [],
"acl": [],
"schema": "public"
},
"expected_sql_file": "create_function_for_alter.sql",
"expected_msql_file": "create_function_for_alter.msql"
},
{
"type": "alter",
"name": "Alter function add acl.",
"endpoint": "NODE-function.obj_id",
"msql_endpoint": "NODE-function.msql_id",
"sql_endpoint": "NODE-function.sql_id",
"data": {
"acl": {
"added": [
{
"grantee": "PUBLIC",
"grantor": "enterprisedb",
"privileges": [
{
"privilege_type": "X",
"privilege": true,
"with_grant": false
}
]
},
{
"grantee": "enterprisedb",
"grantor": "enterprisedb",
"privileges": [
{
"privilege_type": "X",
"privilege": true,
"with_grant": false
}
]
}
]
}
},
"expected_sql_file": "alter_function_add_acl.sql",
"expected_msql_file": "alter_function_add_acl.msql"
},
{
"type": "alter",
"name": "Alter function remove partial privileges.",
"endpoint": "NODE-function.obj_id",
"msql_endpoint": "NODE-function.msql_id",
"sql_endpoint": "NODE-function.sql_id",
"data": {
"acl": {
"deleted": [
{
"grantee": "PUBLIC",
"grantor": "enterprisedb",
"privileges": [
{
"privilege_type": "X",
"privilege": true,
"with_grant": false
}
]
}
]
}
}
},
{
"type": "alter",
"name": "Alter function change grantee in privileges.",
"endpoint": "NODE-function.obj_id",
"msql_endpoint": "NODE-function.msql_id",
"sql_endpoint": "NODE-function.sql_id",
"data": {
"acl": {
"changed": [
{
"grantee": "PUBLIC",
"grantor": "enterprisedb",
"old_grantee": "enterprisedb",
"privileges": [
{
"privilege_type": "X",
"privilege": true,
"with_grant": false
}
]
}
]
}
},
"expected_sql_file": "alter_function_change_grantee_acl.sql",
"expected_msql_file": "alter_function_change_grantee_acl.msql"
},
{
"type": "alter",
"name": "Alter function delete acl.",
"endpoint": "NODE-function.obj_id",
"msql_endpoint": "NODE-function.msql_id",
"sql_endpoint": "NODE-function.sql_id",
"data": {
"acl": {
"deleted": [
{
"grantee": "PUBLIC",
"grantor": "enterprisedb",
"privileges": [
{
"privilege_type": "X",
"privilege": true,
"with_grant": false
}
]
},
{
"grantee": "enterprisedb",
"grantor": "enterprisedb",
"privileges": [
{
"privilege_type": "X",
"privilege": true,
"with_grant": false
}
]
}
]
}
},
"expected_sql_file": "alter_function_delete_acl.sql",
"expected_msql_file": "alter_function_delete_acl.msql"
},
{
"type": "delete",
"name": "Drop function",
"endpoint": "NODE-function.delete_id",
"data": {
}
},
{
"type": "create",
"endpoint": "NODE-function.obj",
"msql_endpoint": "NODE-function.msql",
"sql_endpoint": "NODE-function.sql_id",
"name": "Create function with custom return type.",
"data": {
"name": "Function3_$%{}[]()&*^!@\"'`\\/#",
"funcowner": "enterprisedb",
"pronamespace": 2200,
"prorettypename": "table(val character varying)",
"lanname": "plpgsql",
"provolatile": "v",
"proretset": false,
"proisstrict": true,
"prosecdef": true,
"proiswindow": true,
"proparallel": "u",
"procost": "100",
"prorows": "0",
"proleakproof": true,
"arguments": [
{
"argtype": "character varying",
"argmode": "IN",
"argname": "param",
"argdefval": "'1'"
}
],
"prosrc": "begin\n return query select '1'::character varying;\nend",
"probin": "$libdir/",
"options": [],
"variables": [],
"seclabels": [],
"acl": [],
"schema": "public"
},
"expected_sql_file": "create_function_with_custom_return.sql",
"expected_msql_file": "create_function_with_custom_return.msql"
},
{
"type": "delete",
"name": "Drop function",
"endpoint": "NODE-function.delete_id",
"data": {
}
}
]
}

View File

@ -1,5 +1,81 @@
{
"scenarios": [
{
"type": "create",
"name": "Create Extension",
"endpoint": "NODE-extension.obj",
"sql_endpoint": "NODE-extension.sql_id",
"data": {
"name": "postgres_fdw",
"version": "",
"relocatable": true
}
},
{
"type": "create",
"name": "Create function with extensions.",
"endpoint": "NODE-function.obj",
"msql_endpoint": "NODE-function.msql",
"sql_endpoint": "NODE-function.sql_id",
"data": {
"name": "Function1_$%{}[]()&*^!@\"'`\\/#",
"funcowner": "enterprisedb",
"pronamespace": 2200,
"prorettypename": "character varying",
"lanname": "plpgsql",
"provolatile": "v",
"proretset": false,
"proisstrict": true,
"prosecdef": true,
"proiswindow": true,
"proparallel": "u",
"procost": "100",
"prorows": "0",
"proleakproof": true,
"arguments": [
{
"argtype": "character varying",
"argmode": "IN",
"argname": "param",
"argdefval": "'1'"
}
],
"prosrc": "begin\nselect '1';\nend",
"probin": "$libdir/",
"options": [],
"variables": [
{
"name": "enable_sort",
"value": true
}
],
"seclabels": [],
"acl": [],
"dependsonextensions": ["plpgsql", "postgres_fdw"],
"schema": "public"
},
"expected_sql_file": "create_function_on_depends.sql",
"expected_msql_file": "create_function_on_depends.msql"
},
{
"type": "alter",
"name": "Alter function with NO DEPENDS ON",
"endpoint": "NODE-function.obj_id",
"msql_endpoint": "NODE-function.msql_id",
"sql_endpoint": "NODE-function.sql_id",
"data": {
"dependsonextensions": ["plpgsql"]
},
"expected_sql_file": "alter_function_no_depends.sql",
"expected_msql_file": "alter_function_no_depends.msql"
},
{
"type": "delete",
"name": "Drop function",
"endpoint": "NODE-function.delete_id",
"data": {
}
},
{
"type": "create",
"name": "Create function with all options.",

View File

@ -76,6 +76,19 @@ class FunctionAddTestCase(BaseTestGenerator):
"status_code": 500
}
)),
('Create Function With Invalid Depends On Extension Fail', dict(
url='/browser/function/obj/',
is_positive_test=False,
mocking_required=True,
is_mock_function=True,
mock_data={
"function_name": "_get_sql",
"return_value": "(False, 'Invalid extension specified')"
},
expected_data={
"status_code": 500
}
))
]
def create_function(self, data):
@ -113,6 +126,7 @@ class FunctionAddTestCase(BaseTestGenerator):
"lanname": "sql",
"name": "test_function",
"options": [],
"dependsonextensions": ["plpgsql"],
"proleakproof": True,
"pronamespace": 2200,
"prorettypename": "integer",
@ -143,10 +157,13 @@ class FunctionAddTestCase(BaseTestGenerator):
)
data['prosupportfuc'] = support_function_name
if self.is_positive_test:
response = self.create_function(data)
else:
if "Invalid Depends On Extension" in getattr(
self, 'scenario_name', ''
):
data["dependsonextensions"] = ["non_existing_extensions"]
if hasattr(self, 'is_mock_function'):
def _get_sql(self, **kwargs):
return False, ''

View File

@ -35,6 +35,7 @@ class FunctionGetmsqlTestCase(BaseTestGenerator):
"funcowner": "",
"pronamespace": 2200,
"prorettypename": "character varying",
"dependsonextensions": [],
"lanname": "sql",
"arguments": [],
"prosrc": "select '1'",
@ -67,7 +68,8 @@ class FunctionGetmsqlTestCase(BaseTestGenerator):
"probin": "$libdir/",
"variables": [],
"seclabels": [],
"acl": []
"acl": [],
"dependsonextensions": ["non_existing_extension"]
},
mock_data={
"function_name": '_get_sql',
@ -178,7 +180,6 @@ class FunctionGetmsqlTestCase(BaseTestGenerator):
func_name = "test_function_delete_%s" % str(uuid.uuid4())[1:8]
function_info = funcs_utils.create_function(
self.server, self.db_name, self.schema_name, func_name)
func_id = function_info[0]
self.test_data['oid'] = func_id
self.test_data['name'] = func_name
@ -187,6 +188,7 @@ class FunctionGetmsqlTestCase(BaseTestGenerator):
self.schema_id) + '/' + str(func_id) + '?' + (
urlencode(self.test_data))
else:
self.test_data['dependsonextensions'] = json.dumps(["plpgsql"])
url = self.url + str(utils.SERVER_GROUP) + '/' + str(
self.server_id) + '/' + str(self.db_id) + '/' + str(
self.schema_id) + '/?' + (urlencode(self.test_data))

View File

@ -75,7 +75,7 @@ class FunctionPutTestCase(BaseTestGenerator):
}
)),
(
'Fetch Function update with arguments',
'Fetch Function update with arguments and depends on exxtensions.',
dict(
url='/browser/function/obj/',
is_positive_test=True,
@ -155,7 +155,8 @@ class FunctionPutTestCase(BaseTestGenerator):
data = {
"description": "This is a procedure update comment",
"id": func_id
"id": func_id,
"dependsonextensions": ["plpgsql"]
}
if hasattr(self, "is_add_argument") and self.is_add_argument:

View File

@ -70,6 +70,7 @@ describe('FunctionSchema', ()=>{
getLanguage: [],
getTypes: [],
getSupportFunctions: [],
extensionsList: [],
},
{
node_info: {
@ -109,10 +110,6 @@ describe('FunctionSchema', ()=>{
let schemaObj = createSchemaObj();
let getInitData = ()=>Promise.resolve({});
beforeEach(()=>{
genericBeforeEach();
});
@ -133,6 +130,13 @@ describe('FunctionSchema', ()=>{
await getPropertiesView(createSchemaObj(), getInitData);
});
it('dependsonextensions field exists', ()=>{
let field = _.find(schemaObj.fields, (f)=>f.id=='dependsonextensions');
expect(field).toBeTruthy();
expect(field.type).toBe('select');
expect(field.controlProps.multiple).toBe(true);
});
it('proiswindow visible', async ()=>{
@ -449,7 +453,7 @@ describe('FunctionSchema', ()=>{
schemaObj.validate(state, setError);
expect(setError).toHaveBeenCalledWith('prosrc_c', null);
});
it('validate', ()=>{
let state = {prorettypename: 'char'};
let setError = jest.fn();