mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Showing consitent reversed engineered SQL for the database node.
This commit is contained in:
parent
a6466c091c
commit
1cb2a054ff
@ -1,35 +1,35 @@
|
|||||||
SELECT
|
SELECT
|
||||||
'datacl' AS deftype, COALESCE(gt.rolname, 'public') AS grantee,
|
'datacl' AS deftype, COALESCE(gt.rolname, 'public') AS grantee,
|
||||||
g.rolname AS grantor, array_agg(privilege_type) AS privileges,
|
g.rolname AS grantor, array_agg(privilege_type) AS privileges,
|
||||||
array_agg(is_grantable) AS grantable
|
array_agg(is_grantable) AS grantable
|
||||||
FROM
|
FROM
|
||||||
(SELECT
|
(SELECT
|
||||||
d.grantee, d.grantor, d.is_grantable,
|
d.grantee, d.grantor, d.is_grantable,
|
||||||
CASE d.privilege_type
|
CASE d.privilege_type
|
||||||
WHEN 'CONNECT' THEN 'c'
|
WHEN 'CONNECT' THEN 'c'
|
||||||
WHEN 'CREATE' THEN 'C'
|
WHEN 'CREATE' THEN 'C'
|
||||||
WHEN 'DELETE' THEN 'd'
|
WHEN 'DELETE' THEN 'd'
|
||||||
WHEN 'EXECUTE' THEN 'X'
|
WHEN 'EXECUTE' THEN 'X'
|
||||||
WHEN 'INSERT' THEN 'a'
|
WHEN 'INSERT' THEN 'a'
|
||||||
WHEN 'REFERENCES' THEN 'x'
|
WHEN 'REFERENCES' THEN 'x'
|
||||||
WHEN 'SELECT' THEN 'r'
|
WHEN 'SELECT' THEN 'r'
|
||||||
WHEN 'TEMPORARY' THEN 'T'
|
WHEN 'TEMPORARY' THEN 'T'
|
||||||
WHEN 'TRIGGER' THEN 't'
|
WHEN 'TRIGGER' THEN 't'
|
||||||
WHEN 'TRUNCATE' THEN 'D'
|
WHEN 'TRUNCATE' THEN 'D'
|
||||||
WHEN 'UPDATE' THEN 'w'
|
WHEN 'UPDATE' THEN 'w'
|
||||||
WHEN 'USAGE' THEN 'U'
|
WHEN 'USAGE' THEN 'U'
|
||||||
ELSE 'UNKNOWN'
|
ELSE 'UNKNOWN'
|
||||||
END AS privilege_type
|
END AS privilege_type
|
||||||
FROM
|
FROM
|
||||||
(SELECT
|
(SELECT
|
||||||
(d).grantee AS grantee, (d).grantor AS grantor,
|
(d).grantee AS grantee, (d).grantor AS grantor,
|
||||||
(d).is_grantable AS is_grantable,
|
(d).is_grantable AS is_grantable,
|
||||||
(d).privilege_type AS privilege_type
|
(d).privilege_type AS privilege_type
|
||||||
FROM
|
FROM
|
||||||
(SELECT aclexplode(db.datacl) AS d FROM pg_database db
|
(SELECT aclexplode(db.datacl) AS d FROM pg_database db
|
||||||
WHERE db.oid = {{ did|qtLiteral }}::OID) a
|
WHERE db.oid = {{ did|qtLiteral }}::OID) a
|
||||||
) d
|
) d
|
||||||
) d
|
) d
|
||||||
LEFT JOIN pg_catalog.pg_roles g ON (d.grantor = g.oid)
|
LEFT JOIN pg_catalog.pg_roles g ON (d.grantor = g.oid)
|
||||||
LEFT JOIN pg_catalog.pg_roles gt ON (d.grantee = gt.oid)
|
LEFT JOIN pg_catalog.pg_roles gt ON (d.grantee = gt.oid)
|
||||||
GROUP BY g.rolname, gt.rolname;
|
GROUP BY g.rolname, gt.rolname;
|
||||||
|
@ -2,20 +2,20 @@
|
|||||||
{% import 'macros/privilege.macros' as PRIVILEGE %}
|
{% import 'macros/privilege.macros' as PRIVILEGE %}
|
||||||
{% import 'macros/default_privilege.macros' as DEFAULT_PRIVILEGE %}
|
{% import 'macros/default_privilege.macros' as DEFAULT_PRIVILEGE %}
|
||||||
{% if data %}
|
{% if data %}
|
||||||
{# To change owner #}
|
{# Change the owner #}
|
||||||
{% if data.datowner %}
|
{% if data.datowner %}
|
||||||
ALTER DATABASE {{ conn|qtIdent(data.name) }} OWNER TO {{ conn|qtIdent(data.datowner) }};
|
ALTER DATABASE {{ conn|qtIdent(data.name) }} OWNER TO {{ conn|qtIdent(data.datowner) }};
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{# To change comments #}
|
{# Change the comments/description #}
|
||||||
{% if data.comments %}
|
{% if data.comments %}
|
||||||
COMMENT ON DATABASE {{ conn|qtIdent(data.name) }}
|
COMMENT ON DATABASE {{ conn|qtIdent(data.name) }}
|
||||||
IS {{ data.comments|qtLiteral }};
|
IS {{ data.comments|qtLiteral }};
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{# To change conn limit #}
|
{# Change the connection limit #}
|
||||||
{% if data.datconnlimit %}
|
{% if data.datconnlimit %}
|
||||||
ALTER DATABASE {{ conn|qtIdent(data.name) }} WITH CONNECTION LIMIT = {{ data.datconnlimit }};
|
ALTER DATABASE {{ conn|qtIdent(data.name) }} WITH CONNECTION LIMIT = {{ data.datconnlimit }};
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{# To change Variables #}
|
{# Change the variables/options #}
|
||||||
{% if data.variables and data.variables|length > 0 %}
|
{% if data.variables and data.variables|length > 0 %}
|
||||||
{% set variables = data.variables %}
|
{% set variables = data.variables %}
|
||||||
{% if 'deleted' in variables and variables.deleted|length > 0 %}
|
{% if 'deleted' in variables and variables.deleted|length > 0 %}
|
||||||
@ -47,7 +47,7 @@ ALTER DATABASE {{ conn|qtIdent(data.name) }} WITH CONNECTION LIMIT = {{ data.dat
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{# To change priviledges #}
|
{# Change the priviledges/ACLs #}
|
||||||
{% if data.datacl %}
|
{% if data.datacl %}
|
||||||
{% if 'deleted' in data.datacl %}
|
{% if 'deleted' in data.datacl %}
|
||||||
{% for priv in data.datacl.deleted %}
|
{% for priv in data.datacl.deleted %}
|
||||||
@ -67,7 +67,7 @@ ALTER DATABASE {{ conn|qtIdent(data.name) }} WITH CONNECTION LIMIT = {{ data.dat
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{# To change default priviledges #}
|
{# Change the default priviledges for the tables #}
|
||||||
{% if data.deftblacl %}
|
{% if data.deftblacl %}
|
||||||
{% if 'deleted' in data.deftblacl %}
|
{% if 'deleted' in data.deftblacl %}
|
||||||
{% for priv in data.deftblacl.deleted %}
|
{% for priv in data.deftblacl.deleted %}
|
||||||
@ -86,7 +86,8 @@ ALTER DATABASE {{ conn|qtIdent(data.name) }} WITH CONNECTION LIMIT = {{ data.dat
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{# To change default priviledges #}
|
{# Change the default priviledges for the sequences #}
|
||||||
|
{% if data.deftblacl %}
|
||||||
{% if data.defseqacl %}
|
{% if data.defseqacl %}
|
||||||
{% if 'deleted' in data.defseqacl %}
|
{% if 'deleted' in data.defseqacl %}
|
||||||
{% for priv in data.defseqacl.deleted %}
|
{% for priv in data.defseqacl.deleted %}
|
||||||
@ -106,7 +107,7 @@ ALTER DATABASE {{ conn|qtIdent(data.name) }} WITH CONNECTION LIMIT = {{ data.dat
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{# To change default priviledges #}
|
{# Change the default priviledges for the functions #}
|
||||||
{% if data.deffuncacl %}
|
{% if data.deffuncacl %}
|
||||||
{% if 'deleted' in data.deffuncacl %}
|
{% if 'deleted' in data.deffuncacl %}
|
||||||
{% for priv in data.deffuncacl.deleted %}
|
{% for priv in data.deffuncacl.deleted %}
|
||||||
@ -126,4 +127,4 @@ ALTER DATABASE {{ conn|qtIdent(data.name) }} WITH CONNECTION LIMIT = {{ data.dat
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -1,19 +1,19 @@
|
|||||||
{% if data %}
|
{% if data %}
|
||||||
CREATE DATABASE {{ conn|qtIdent(data.name) }}
|
CREATE DATABASE {{ conn|qtIdent(data.name) }}
|
||||||
{% if data.datowner %}
|
{% if data.datowner %}
|
||||||
WITH {% endif %}{% if data.datowner %}
|
WITH {% endif %}{% if data.datowner %}
|
||||||
|
|
||||||
OWNER = {{ conn|qtIdent(data.datowner) }}{% endif %}{% if data.template %}
|
OWNER = {{ conn|qtIdent(data.datowner) }}{% endif %}{% if data.template %}
|
||||||
|
|
||||||
TEMPLATE = {{ conn|qtIdent(data.template) }}{% endif %}{% if data.encoding %}
|
TEMPLATE = {{ conn|qtIdent(data.template) }}{% endif %}{% if data.encoding %}
|
||||||
|
|
||||||
ENCODING = {{ data.encoding|qtLiteral }}{% endif %}{% if data.datcollate %}
|
ENCODING = {{ data.encoding|qtLiteral }}{% endif %}{% if data.datcollate %}
|
||||||
|
|
||||||
LC_COLLATE = {{ data.datcollate|qtLiteral }}{% endif %}{% if data.datctype %}
|
LC_COLLATE = {{ data.datcollate|qtLiteral }}{% endif %}{% if data.datctype %}
|
||||||
|
|
||||||
LC_CTYPE = {{ data.datctype|qtLiteral }}{% endif %}{% if data.spcname %}
|
LC_CTYPE = {{ data.datctype|qtLiteral }}{% endif %}{% if data.spcname %}
|
||||||
|
|
||||||
TABLESPACE = {{ conn|qtIdent(data.spcname) }}{% endif %}{% if data.datconnlimit %}
|
TABLESPACE = {{ conn|qtIdent(data.spcname) }}{% endif %}{% if data.datconnlimit %}
|
||||||
|
|
||||||
CONNECTION LIMIT = {{ data.datconnlimit }}{% endif %};
|
CONNECTION LIMIT = {{ data.datconnlimit }}{% endif %};
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -1,34 +1,34 @@
|
|||||||
SELECT
|
SELECT
|
||||||
CASE (a.deftype)
|
CASE (a.deftype)
|
||||||
WHEN 'r' THEN 'deftblacl'
|
WHEN 'r' THEN 'deftblacl'
|
||||||
WHEN 'S' THEN 'defseqacl'
|
WHEN 'S' THEN 'defseqacl'
|
||||||
WHEN 'f' THEN 'deffuncacl'
|
WHEN 'f' THEN 'deffuncacl'
|
||||||
WHEN 'T' THEN 'deftypeacl'
|
WHEN 'T' THEN 'deftypeacl'
|
||||||
END AS deftype,
|
END AS deftype,
|
||||||
COALESCE(gt.rolname, 'public') grantee, g.rolname grantor, array_agg(a.privilege_type) as privileges, array_agg(a.is_grantable) as grantable
|
COALESCE(gt.rolname, 'public') grantee, g.rolname grantor, array_agg(a.privilege_type) as privileges, array_agg(a.is_grantable) as grantable
|
||||||
FROM
|
FROM
|
||||||
(SELECT
|
(SELECT
|
||||||
(acl).grantee as grantee, (acl).grantor AS grantor, (acl).is_grantable AS is_grantable,
|
(acl).grantee as grantee, (acl).grantor AS grantor, (acl).is_grantable AS is_grantable,
|
||||||
CASE (acl).privilege_type
|
CASE (acl).privilege_type
|
||||||
WHEN 'CONNECT' THEN 'c'
|
WHEN 'CONNECT' THEN 'c'
|
||||||
WHEN 'CREATE' THEN 'C'
|
WHEN 'CREATE' THEN 'C'
|
||||||
WHEN 'DELETE' THEN 'd'
|
WHEN 'DELETE' THEN 'd'
|
||||||
WHEN 'EXECUTE' THEN 'X'
|
WHEN 'EXECUTE' THEN 'X'
|
||||||
WHEN 'INSERT' THEN 'a'
|
WHEN 'INSERT' THEN 'a'
|
||||||
WHEN 'REFERENCES' THEN 'x'
|
WHEN 'REFERENCES' THEN 'x'
|
||||||
WHEN 'SELECT' THEN 'r'
|
WHEN 'SELECT' THEN 'r'
|
||||||
WHEN 'TEMPORARY' THEN 'T'
|
WHEN 'TEMPORARY' THEN 'T'
|
||||||
WHEN 'TRIGGER' THEN 't'
|
WHEN 'TRIGGER' THEN 't'
|
||||||
WHEN 'TRUNCATE' THEN 'D'
|
WHEN 'TRUNCATE' THEN 'D'
|
||||||
WHEN 'UPDATE' THEN 'w'
|
WHEN 'UPDATE' THEN 'w'
|
||||||
WHEN 'USAGE' THEN 'U'
|
WHEN 'USAGE' THEN 'U'
|
||||||
ELSE 'UNKNOWN'
|
ELSE 'UNKNOWN'
|
||||||
END AS privilege_type,
|
END AS privilege_type,
|
||||||
defaclobjtype as deftype
|
defaclobjtype as deftype
|
||||||
FROM
|
FROM
|
||||||
(SELECT defaclobjtype, aclexplode(defaclacl) as acl FROM pg_catalog.pg_default_acl dacl
|
(SELECT defaclobjtype, aclexplode(defaclacl) as acl FROM pg_catalog.pg_default_acl dacl
|
||||||
WHERE dacl.defaclnamespace = 0::OID) d) a
|
WHERE dacl.defaclnamespace = 0::OID) d) a
|
||||||
LEFT JOIN pg_catalog.pg_roles g ON (a.grantor = g.oid)
|
LEFT JOIN pg_catalog.pg_roles g ON (a.grantor = g.oid)
|
||||||
LEFT JOIN pg_catalog.pg_roles gt ON (a.grantee = gt.oid)
|
LEFT JOIN pg_catalog.pg_roles gt ON (a.grantee = gt.oid)
|
||||||
GROUP BY g.rolname, gt.rolname, a.deftype
|
GROUP BY g.rolname, gt.rolname, a.deftype
|
||||||
ORDER BY a.deftype
|
ORDER BY a.deftype
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
#}
|
#}
|
||||||
SELECT * FROM
|
SELECT * FROM
|
||||||
(SELECT pg_encoding_to_char(s.i) AS encoding
|
(SELECT pg_encoding_to_char(s.i) AS encoding
|
||||||
FROM (SELECT generate_series(0, 100, 1) as i) s) a
|
FROM (SELECT generate_series(0, 100, 1) as i) s) a
|
||||||
WHERE encoding != '';
|
WHERE encoding != '';
|
||||||
|
|
||||||
{#
|
{#
|
||||||
@ -14,4 +14,4 @@ WHERE encoding != '';
|
|||||||
-- as encoding
|
-- as encoding
|
||||||
-- FROM (SELECT generate_series(0, 100, 1) as i) s) a
|
-- FROM (SELECT generate_series(0, 100, 1) as i) s) a
|
||||||
--WHERE encoding != ''
|
--WHERE encoding != ''
|
||||||
#}
|
#}
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
{% import 'macros/default_privilege.macros' as DEFAULT_PRIVILEGE %}
|
{% import 'macros/default_privilege.macros' as DEFAULT_PRIVILEGE %}
|
||||||
{% if data.comments %}
|
{% if data.comments %}
|
||||||
COMMENT ON DATABASE {{ conn|qtIdent(data.name) }}
|
COMMENT ON DATABASE {{ conn|qtIdent(data.name) }}
|
||||||
IS {{ data.comments|qtLiteral }};
|
IS {{ data.comments|qtLiteral }};
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{# TO generate Variable SQL using macro #}
|
{# TO generate Variable SQL using macro #}
|
||||||
@ -42,4 +42,4 @@ COMMENT ON DATABASE {{ conn|qtIdent(data.name) }}
|
|||||||
{% for priv in data.deffuncacl %}
|
{% for priv in data.deffuncacl %}
|
||||||
{{ DEFAULT_PRIVILEGE.APPLY(conn, 'FUNCTIONS', priv.grantee, priv.without_grant, priv.with_grant) }}
|
{{ DEFAULT_PRIVILEGE.APPLY(conn, 'FUNCTIONS', priv.grantee, priv.without_grant, priv.with_grant) }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
SELECT name, vartype, min_val, max_val, enumvals
|
SELECT name, vartype, min_val, max_val, enumvals
|
||||||
FROM pg_settings WHERE context in ('user', 'superuser')
|
FROM pg_settings WHERE context in ('user', 'superuser')
|
||||||
|
@ -1,35 +1,35 @@
|
|||||||
SELECT
|
SELECT
|
||||||
'datacl' AS deftype, COALESCE(gt.rolname, 'public') AS grantee,
|
'datacl' AS deftype, COALESCE(gt.rolname, 'public') AS grantee,
|
||||||
g.rolname grantor, array_agg(privilege_type) AS privileges,
|
g.rolname grantor, array_agg(privilege_type) AS privileges,
|
||||||
array_agg(is_grantable) AS grantable
|
array_agg(is_grantable) AS grantable
|
||||||
FROM
|
FROM
|
||||||
(SELECT
|
(SELECT
|
||||||
d.grantee, d.grantor, d.is_grantable,
|
d.grantee, d.grantor, d.is_grantable,
|
||||||
CASE d.privilege_type
|
CASE d.privilege_type
|
||||||
WHEN 'CONNECT' THEN 'c'
|
WHEN 'CONNECT' THEN 'c'
|
||||||
WHEN 'CREATE' THEN 'C'
|
WHEN 'CREATE' THEN 'C'
|
||||||
WHEN 'DELETE' THEN 'd'
|
WHEN 'DELETE' THEN 'd'
|
||||||
WHEN 'EXECUTE' THEN 'X'
|
WHEN 'EXECUTE' THEN 'X'
|
||||||
WHEN 'INSERT' THEN 'a'
|
WHEN 'INSERT' THEN 'a'
|
||||||
WHEN 'REFERENCES' THEN 'x'
|
WHEN 'REFERENCES' THEN 'x'
|
||||||
WHEN 'SELECT' THEN 'r'
|
WHEN 'SELECT' THEN 'r'
|
||||||
WHEN 'TEMPORARY' THEN 'T'
|
WHEN 'TEMPORARY' THEN 'T'
|
||||||
WHEN 'TRIGGER' THEN 't'
|
WHEN 'TRIGGER' THEN 't'
|
||||||
WHEN 'TRUNCATE' THEN 'D'
|
WHEN 'TRUNCATE' THEN 'D'
|
||||||
WHEN 'UPDATE' THEN 'w'
|
WHEN 'UPDATE' THEN 'w'
|
||||||
WHEN 'USAGE' THEN 'U'
|
WHEN 'USAGE' THEN 'U'
|
||||||
ELSE 'UNKNOWN'
|
ELSE 'UNKNOWN'
|
||||||
END AS privilege_type
|
END AS privilege_type
|
||||||
FROM
|
FROM
|
||||||
(SELECT
|
(SELECT
|
||||||
(d).grantee AS grantee, (d).grantor AS grantor,
|
(d).grantee AS grantee, (d).grantor AS grantor,
|
||||||
(d).is_grantable AS is_grantable,
|
(d).is_grantable AS is_grantable,
|
||||||
(d).privilege_type AS privilege_type
|
(d).privilege_type AS privilege_type
|
||||||
FROM
|
FROM
|
||||||
(SELECT aclexplode(db.datacl) AS d FROM pg_database db
|
(SELECT aclexplode(db.datacl) AS d FROM pg_database db
|
||||||
WHERE db.oid = {{ did|qtLiteral }}::OID) a
|
WHERE db.oid = {{ did|qtLiteral }}::OID) a
|
||||||
) d
|
) d
|
||||||
) d
|
) d
|
||||||
LEFT JOIN pg_catalog.pg_roles g ON (d.grantor = g.oid)
|
LEFT JOIN pg_catalog.pg_roles g ON (d.grantor = g.oid)
|
||||||
LEFT JOIN pg_catalog.pg_roles gt ON (d.grantee = gt.oid)
|
LEFT JOIN pg_catalog.pg_roles gt ON (d.grantee = gt.oid)
|
||||||
GROUP BY g.rolname, gt.rolname;
|
GROUP BY g.rolname, gt.rolname;
|
||||||
|
@ -3,20 +3,20 @@
|
|||||||
{% import 'macros/privilege.macros' as PRIVILEGE %}
|
{% import 'macros/privilege.macros' as PRIVILEGE %}
|
||||||
{% import 'macros/default_privilege.macros' as DEFAULT_PRIVILEGE %}
|
{% import 'macros/default_privilege.macros' as DEFAULT_PRIVILEGE %}
|
||||||
{% if data %}
|
{% if data %}
|
||||||
{# To change owner #}
|
{# Change the owner #}
|
||||||
{% if data.datowner %}
|
{% if data.datowner %}
|
||||||
ALTER DATABASE {{ conn|qtIdent(data.name) }} OWNER TO {{ conn|qtIdent(data.datowner) }};
|
ALTER DATABASE {{ conn|qtIdent(data.name) }} OWNER TO {{ conn|qtIdent(data.datowner) }};
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{# TO change comments #}
|
{# Change the comments/description #}
|
||||||
{% if data.comments %}
|
{% if data.comments %}
|
||||||
COMMENT ON DATABASE {{ conn|qtIdent(data.name) }}
|
COMMENT ON DATABASE {{ conn|qtIdent(data.name) }}
|
||||||
IS {{ data.comments|qtLiteral }};
|
IS {{ data.comments|qtLiteral }};
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{# TO change conn limit #}
|
{# Change the connection limit #}
|
||||||
{% if data.datconnlimit %}
|
{% if data.datconnlimit %}
|
||||||
ALTER DATABASE {{ conn|qtIdent(data.name) }} WITH CONNECTION LIMIT = {{ data.datconnlimit }};
|
ALTER DATABASE {{ conn|qtIdent(data.name) }} WITH CONNECTION LIMIT = {{ data.datconnlimit }};
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{# To change Security Label #}
|
{# Change the security labels #}
|
||||||
{% if data.seclabels and data.seclabels|length > 0 %}
|
{% if data.seclabels and data.seclabels|length > 0 %}
|
||||||
{% set seclabels = data.seclabels %}
|
{% set seclabels = data.seclabels %}
|
||||||
{% if 'deleted' in seclabels and seclabels.deleted|length > 0 %}
|
{% if 'deleted' in seclabels and seclabels.deleted|length > 0 %}
|
||||||
@ -35,7 +35,7 @@ ALTER DATABASE {{ conn|qtIdent(data.name) }} WITH CONNECTION LIMIT = {{ data.dat
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{# To change Variables #}
|
{# Change the variables/options #}
|
||||||
{% if data.variables and data.variables|length > 0 %}
|
{% if data.variables and data.variables|length > 0 %}
|
||||||
{% set variables = data.variables %}
|
{% set variables = data.variables %}
|
||||||
{% if 'deleted' in variables and variables.deleted|length > 0 %}
|
{% if 'deleted' in variables and variables.deleted|length > 0 %}
|
||||||
@ -67,7 +67,7 @@ ALTER DATABASE {{ conn|qtIdent(data.name) }} WITH CONNECTION LIMIT = {{ data.dat
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{# To change priviledges #}
|
{# Change the priviledges/ACLs #}
|
||||||
{% if data.datacl %}
|
{% if data.datacl %}
|
||||||
{% if 'deleted' in data.datacl %}
|
{% if 'deleted' in data.datacl %}
|
||||||
{% for priv in data.datacl.deleted %}
|
{% for priv in data.datacl.deleted %}
|
||||||
@ -87,7 +87,7 @@ ALTER DATABASE {{ conn|qtIdent(data.name) }} WITH CONNECTION LIMIT = {{ data.dat
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{# To change default priviledges #}
|
{# Change the default priviledges/ACLs for the tables #}
|
||||||
{% if data.deftblacl %}
|
{% if data.deftblacl %}
|
||||||
{% if 'deleted' in data.deftblacl %}
|
{% if 'deleted' in data.deftblacl %}
|
||||||
{% for priv in data.deftblacl.deleted %}
|
{% for priv in data.deftblacl.deleted %}
|
||||||
@ -107,7 +107,7 @@ ALTER DATABASE {{ conn|qtIdent(data.name) }} WITH CONNECTION LIMIT = {{ data.dat
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{# To change default priviledges #}
|
{# Change the default priviledges/ACLs for the sequences #}
|
||||||
{% if data.defseqacl %}
|
{% if data.defseqacl %}
|
||||||
{% if 'deleted' in data.defseqacl %}
|
{% if 'deleted' in data.defseqacl %}
|
||||||
{% for priv in data.defseqacl.deleted %}
|
{% for priv in data.defseqacl.deleted %}
|
||||||
@ -127,7 +127,7 @@ ALTER DATABASE {{ conn|qtIdent(data.name) }} WITH CONNECTION LIMIT = {{ data.dat
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{# To change default priviledges #}
|
{# Change the default priviledges/ACLs for the functions #}
|
||||||
{% if data.deffuncacl %}
|
{% if data.deffuncacl %}
|
||||||
{% if 'deleted' in data.deffuncacl %}
|
{% if 'deleted' in data.deffuncacl %}
|
||||||
{% for priv in data.deffuncacl.deleted %}
|
{% for priv in data.deffuncacl.deleted %}
|
||||||
@ -147,7 +147,7 @@ ALTER DATABASE {{ conn|qtIdent(data.name) }} WITH CONNECTION LIMIT = {{ data.dat
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{# To change default priviledges #}
|
{# Change the default priviledges/ACLs for the types #}
|
||||||
{% if data.deftypeacl %}
|
{% if data.deftypeacl %}
|
||||||
{% if 'deleted' in data.deftypeacl %}
|
{% if 'deleted' in data.deftypeacl %}
|
||||||
{% for priv in data.deftypeacl.deleted %}
|
{% for priv in data.deftypeacl.deleted %}
|
||||||
|
@ -1,19 +1,19 @@
|
|||||||
{% if data %}
|
{% if data %}
|
||||||
CREATE DATABASE {{ conn|qtIdent(data.name) }}
|
CREATE DATABASE {{ conn|qtIdent(data.name) }}
|
||||||
{% if data.datowner %}
|
{% if data.datowner %}
|
||||||
WITH {% endif %}{% if data.datowner %}
|
WITH {% endif %}{% if data.datowner %}
|
||||||
|
|
||||||
OWNER = {{ conn|qtIdent(data.datowner) }}{% endif %}{% if data.template %}
|
OWNER = {{ conn|qtIdent(data.datowner) }}{% endif %}{% if data.template %}
|
||||||
|
|
||||||
TEMPLATE = {{ conn|qtIdent(data.template) }}{% endif %}{% if data.encoding %}
|
TEMPLATE = {{ conn|qtIdent(data.template) }}{% endif %}{% if data.encoding %}
|
||||||
|
|
||||||
ENCODING = {{ data.encoding|qtLiteral }}{% endif %}{% if data.datcollate %}
|
ENCODING = {{ data.encoding|qtLiteral }}{% endif %}{% if data.datcollate %}
|
||||||
|
|
||||||
LC_COLLATE = {{ data.datcollate|qtLiteral }}{% endif %}{% if data.datctype %}
|
LC_COLLATE = {{ data.datcollate|qtLiteral }}{% endif %}{% if data.datctype %}
|
||||||
|
|
||||||
LC_CTYPE = {{ data.datctype|qtLiteral }}{% endif %}{% if data.spcname %}
|
LC_CTYPE = {{ data.datctype|qtLiteral }}{% endif %}{% if data.spcname %}
|
||||||
|
|
||||||
TABLESPACE = {{ conn|qtIdent(data.spcname) }}{% endif %}{% if data.datconnlimit %}
|
TABLESPACE = {{ conn|qtIdent(data.spcname) }}{% endif %}{% if data.datconnlimit %}
|
||||||
|
|
||||||
CONNECTION LIMIT = {{ data.datconnlimit }}{% endif %};
|
CONNECTION LIMIT = {{ data.datconnlimit }}{% endif %};
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -1,34 +1,34 @@
|
|||||||
SELECT
|
SELECT
|
||||||
CASE (a.deftype)
|
CASE (a.deftype)
|
||||||
WHEN 'r' THEN 'deftblacl'
|
WHEN 'r' THEN 'deftblacl'
|
||||||
WHEN 'S' THEN 'defseqacl'
|
WHEN 'S' THEN 'defseqacl'
|
||||||
WHEN 'f' THEN 'deffuncacl'
|
WHEN 'f' THEN 'deffuncacl'
|
||||||
WHEN 'T' THEN 'deftypeacl'
|
WHEN 'T' THEN 'deftypeacl'
|
||||||
END AS deftype,
|
END AS deftype,
|
||||||
COALESCE(gt.rolname, 'public') grantee, g.rolname grantor, array_agg(a.privilege_type) as privileges, array_agg(a.is_grantable) as grantable
|
COALESCE(gt.rolname, 'public') grantee, g.rolname grantor, array_agg(a.privilege_type) as privileges, array_agg(a.is_grantable) as grantable
|
||||||
FROM
|
FROM
|
||||||
(SELECT
|
(SELECT
|
||||||
(acl).grantee as grantee, (acl).grantor AS grantor, (acl).is_grantable AS is_grantable,
|
(acl).grantee as grantee, (acl).grantor AS grantor, (acl).is_grantable AS is_grantable,
|
||||||
CASE (acl).privilege_type
|
CASE (acl).privilege_type
|
||||||
WHEN 'CONNECT' THEN 'c'
|
WHEN 'CONNECT' THEN 'c'
|
||||||
WHEN 'CREATE' THEN 'C'
|
WHEN 'CREATE' THEN 'C'
|
||||||
WHEN 'DELETE' THEN 'd'
|
WHEN 'DELETE' THEN 'd'
|
||||||
WHEN 'EXECUTE' THEN 'X'
|
WHEN 'EXECUTE' THEN 'X'
|
||||||
WHEN 'INSERT' THEN 'a'
|
WHEN 'INSERT' THEN 'a'
|
||||||
WHEN 'REFERENCES' THEN 'x'
|
WHEN 'REFERENCES' THEN 'x'
|
||||||
WHEN 'SELECT' THEN 'r'
|
WHEN 'SELECT' THEN 'r'
|
||||||
WHEN 'TEMPORARY' THEN 'T'
|
WHEN 'TEMPORARY' THEN 'T'
|
||||||
WHEN 'TRIGGER' THEN 't'
|
WHEN 'TRIGGER' THEN 't'
|
||||||
WHEN 'TRUNCATE' THEN 'D'
|
WHEN 'TRUNCATE' THEN 'D'
|
||||||
WHEN 'UPDATE' THEN 'w'
|
WHEN 'UPDATE' THEN 'w'
|
||||||
WHEN 'USAGE' THEN 'U'
|
WHEN 'USAGE' THEN 'U'
|
||||||
ELSE 'UNKNOWN'
|
ELSE 'UNKNOWN'
|
||||||
END AS privilege_type,
|
END AS privilege_type,
|
||||||
defaclobjtype as deftype
|
defaclobjtype as deftype
|
||||||
FROM
|
FROM
|
||||||
(SELECT defaclobjtype, aclexplode(defaclacl) as acl FROM pg_catalog.pg_default_acl dacl
|
(SELECT defaclobjtype, aclexplode(defaclacl) as acl FROM pg_catalog.pg_default_acl dacl
|
||||||
WHERE dacl.defaclnamespace = 0::OID) d) a
|
WHERE dacl.defaclnamespace = 0::OID) d) a
|
||||||
LEFT JOIN pg_catalog.pg_roles g ON (a.grantor = g.oid)
|
LEFT JOIN pg_catalog.pg_roles g ON (a.grantor = g.oid)
|
||||||
LEFT JOIN pg_catalog.pg_roles gt ON (a.grantee = gt.oid)
|
LEFT JOIN pg_catalog.pg_roles gt ON (a.grantee = gt.oid)
|
||||||
GROUP BY g.rolname, gt.rolname, a.deftype
|
GROUP BY g.rolname, gt.rolname, a.deftype
|
||||||
ORDER BY a.deftype
|
ORDER BY a.deftype
|
||||||
|
@ -4,5 +4,5 @@ SELECT db.datname as name FROM pg_database as db WHERE db.oid = {{did}}
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{# Using name from above query we will drop the database #}
|
{# Using name from above query we will drop the database #}
|
||||||
{% if datname %}
|
{% if datname %}
|
||||||
DROP DATABASE {{ conn|qtIdent(datname) }};
|
DROP DATABASE {{ conn|qtIdent(datname) }};
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -2,9 +2,10 @@
|
|||||||
-- Given SQL is workaround
|
-- Given SQL is workaround
|
||||||
-- We need to implement a mechanism to check for valid supported server encoding
|
-- We need to implement a mechanism to check for valid supported server encoding
|
||||||
#}
|
#}
|
||||||
SELECT * FROM
|
SELECT *
|
||||||
(SELECT pg_encoding_to_char(s.i) AS encoding
|
FROM
|
||||||
FROM (SELECT generate_series(0, 100, 1) as i) s) a
|
(SELECT pg_encoding_to_char(s.i) AS encoding
|
||||||
|
FROM (SELECT generate_series(0, 100, 1) as i) s) a
|
||||||
WHERE encoding != '';
|
WHERE encoding != '';
|
||||||
|
|
||||||
{#
|
{#
|
||||||
@ -14,4 +15,4 @@ WHERE encoding != '';
|
|||||||
-- as encoding
|
-- as encoding
|
||||||
-- FROM (SELECT generate_series(0, 100, 1) as i) s) a
|
-- FROM (SELECT generate_series(0, 100, 1) as i) s) a
|
||||||
--WHERE encoding != ''
|
--WHERE encoding != ''
|
||||||
#}
|
#}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
SELECT rl.*, r.rolname AS user_name, db.datname as db_name
|
SELECT
|
||||||
FROM pg_db_role_setting AS rl
|
rl.*, r.rolname AS user_name, db.datname as db_name
|
||||||
LEFT JOIN pg_roles AS r ON rl.setrole = r.oid
|
FROM
|
||||||
LEFT JOIN pg_database AS db ON rl.setdatabase = db.oid
|
pg_db_role_setting AS rl
|
||||||
WHERE setdatabase = {{did}}
|
LEFT JOIN pg_roles AS r ON rl.setrole = r.oid
|
||||||
|
LEFT JOIN pg_database AS db ON rl.setdatabase = db.oid
|
||||||
|
WHERE setdatabase = {{did}};
|
||||||
|
@ -9,16 +9,16 @@
|
|||||||
{% import 'macros/default_privilege.macros' as DEFAULT_PRIVILEGE %}
|
{% import 'macros/default_privilege.macros' as DEFAULT_PRIVILEGE %}
|
||||||
{% if data.comments %}
|
{% if data.comments %}
|
||||||
COMMENT ON DATABASE {{ conn|qtIdent(data.name) }}
|
COMMENT ON DATABASE {{ conn|qtIdent(data.name) }}
|
||||||
IS {{ data.comments|qtLiteral }};
|
IS {{ data.comments|qtLiteral }};
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{# To generate Security Label SQL using macro #}
|
{# Generate the security labels #}
|
||||||
{% if data.securities %}
|
{% if data.securities %}
|
||||||
{% for r in data.securities %}
|
{% for r in data.securities %}
|
||||||
{{ SECLABEL.APPLY(conn, 'DATABASE', data.name, r.provider, r.securitylabel) }}
|
{{ SECLABEL.APPLY(conn, 'DATABASE', data.name, r.provider, r.securitylabel) }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{# To generate Variable SQL using macro #}
|
{# Generate the variable/options #}
|
||||||
{% if data.variables %}
|
{% if data.variables %}
|
||||||
{% for var in data.variables %}
|
{% for var in data.variables %}
|
||||||
{% if var.value == True %}
|
{% if var.value == True %}
|
||||||
@ -30,6 +30,7 @@ COMMENT ON DATABASE {{ conn|qtIdent(data.name) }}
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{# Generate the privileges/ACLs #}
|
||||||
{% if data.datacl %}
|
{% if data.datacl %}
|
||||||
{% for priv in data.datacl %}
|
{% for priv in data.datacl %}
|
||||||
{{ PRIVILEGE.APPLY(conn, 'DATABASE', priv.grantee, data.name, priv.without_grant, priv.with_grant) }}
|
{{ PRIVILEGE.APPLY(conn, 'DATABASE', priv.grantee, data.name, priv.without_grant, priv.with_grant) }}
|
||||||
|
@ -1 +1,4 @@
|
|||||||
SELECT name, vartype, min_val, max_val, enumvals FROM pg_settings WHERE context in ('user', 'superuser')
|
SELECT
|
||||||
|
name, vartype, min_val, max_val, enumvals
|
||||||
|
FROM pg_settings
|
||||||
|
WHERE context in ('user', 'superuser');
|
||||||
|
@ -1,35 +1,35 @@
|
|||||||
SELECT
|
SELECT
|
||||||
'datacl' AS deftype, COALESCE(gt.rolname, 'public') AS grantee,
|
'datacl' AS deftype, COALESCE(gt.rolname, 'public') AS grantee,
|
||||||
g.rolname AS grantor, array_agg(privilege_type) AS privileges,
|
g.rolname AS grantor, array_agg(privilege_type) AS privileges,
|
||||||
array_agg(is_grantable) AS grantable
|
array_agg(is_grantable) AS grantable
|
||||||
FROM
|
FROM
|
||||||
(SELECT
|
(SELECT
|
||||||
d.grantee, d.grantor, d.is_grantable,
|
d.grantee, d.grantor, d.is_grantable,
|
||||||
CASE d.privilege_type
|
CASE d.privilege_type
|
||||||
WHEN 'CONNECT' THEN 'c'
|
WHEN 'CONNECT' THEN 'c'
|
||||||
WHEN 'CREATE' THEN 'C'
|
WHEN 'CREATE' THEN 'C'
|
||||||
WHEN 'DELETE' THEN 'd'
|
WHEN 'DELETE' THEN 'd'
|
||||||
WHEN 'EXECUTE' THEN 'X'
|
WHEN 'EXECUTE' THEN 'X'
|
||||||
WHEN 'INSERT' THEN 'a'
|
WHEN 'INSERT' THEN 'a'
|
||||||
WHEN 'REFERENCES' THEN 'x'
|
WHEN 'REFERENCES' THEN 'x'
|
||||||
WHEN 'SELECT' THEN 'r'
|
WHEN 'SELECT' THEN 'r'
|
||||||
WHEN 'TEMPORARY' THEN 'T'
|
WHEN 'TEMPORARY' THEN 'T'
|
||||||
WHEN 'TRIGGER' THEN 't'
|
WHEN 'TRIGGER' THEN 't'
|
||||||
WHEN 'TRUNCATE' THEN 'D'
|
WHEN 'TRUNCATE' THEN 'D'
|
||||||
WHEN 'UPDATE' THEN 'w'
|
WHEN 'UPDATE' THEN 'w'
|
||||||
WHEN 'USAGE' THEN 'U'
|
WHEN 'USAGE' THEN 'U'
|
||||||
ELSE 'UNKNOWN'
|
ELSE 'UNKNOWN'
|
||||||
END AS privilege_type
|
END AS privilege_type
|
||||||
FROM
|
FROM
|
||||||
(SELECT
|
(SELECT
|
||||||
(d).grantee AS grantee, (d).grantor AS grantor,
|
(d).grantee AS grantee, (d).grantor AS grantor,
|
||||||
(d).is_grantable AS is_grantable,
|
(d).is_grantable AS is_grantable,
|
||||||
(d).privilege_type AS privilege_type
|
(d).privilege_type AS privilege_type
|
||||||
FROM
|
FROM
|
||||||
(SELECT aclexplode(db.datacl) AS d FROM pg_database db
|
(SELECT aclexplode(db.datacl) AS d FROM pg_database db
|
||||||
WHERE db.oid = {{ did|qtLiteral }}::OID) a
|
WHERE db.oid = {{ did|qtLiteral }}::OID) a
|
||||||
) d
|
) d
|
||||||
) d
|
) d
|
||||||
LEFT JOIN pg_catalog.pg_roles g ON (d.grantor = g.oid)
|
LEFT JOIN pg_catalog.pg_roles g ON (d.grantor = g.oid)
|
||||||
LEFT JOIN pg_catalog.pg_roles gt ON (d.grantee = gt.oid)
|
LEFT JOIN pg_catalog.pg_roles gt ON (d.grantee = gt.oid)
|
||||||
GROUP BY g.rolname, gt.rolname;
|
GROUP BY g.rolname, gt.rolname;
|
||||||
|
@ -3,20 +3,20 @@
|
|||||||
{% import 'macros/privilege.macros' as PRIVILEGE %}
|
{% import 'macros/privilege.macros' as PRIVILEGE %}
|
||||||
{% import 'macros/default_privilege.macros' as DEFAULT_PRIVILEGE %}
|
{% import 'macros/default_privilege.macros' as DEFAULT_PRIVILEGE %}
|
||||||
{% if data %}
|
{% if data %}
|
||||||
{# The SQL generated below will change owner #}
|
{# Change the owner #}
|
||||||
{% if data.datowner %}
|
{% if data.datowner %}
|
||||||
ALTER DATABASE {{ conn|qtIdent(data.name) }} OWNER TO {{ conn|qtIdent(data.datowner) }};
|
ALTER DATABASE {{ conn|qtIdent(data.name) }} OWNER TO {{ conn|qtIdent(data.datowner) }};
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{# The SQL generated below will change comments #}
|
{# Change the comments/description #}
|
||||||
{% if data.comments %}
|
{% if data.comments %}
|
||||||
COMMENT ON DATABASE {{ conn|qtIdent(data.name) }}
|
COMMENT ON DATABASE {{ conn|qtIdent(data.name) }}
|
||||||
IS {{ data.comments|qtLiteral }};
|
IS {{ data.comments|qtLiteral }};
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{# The SQL generated below will change conn limit #}
|
{# Change the connection limit #}
|
||||||
{% if data.datconnlimit %}
|
{% if data.datconnlimit %}
|
||||||
ALTER DATABASE {{ conn|qtIdent(data.name) }} WITH CONNECTION LIMIT = {{ data.datconnlimit }};
|
ALTER DATABASE {{ conn|qtIdent(data.name) }} WITH CONNECTION LIMIT = {{ data.datconnlimit }};
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{# The SQL generated below will change Security Label #}
|
{# Change the security labels #}
|
||||||
{% if data.seclabels and data.seclabels|length > 0 %}
|
{% if data.seclabels and data.seclabels|length > 0 %}
|
||||||
{% set seclabels = data.seclabels %}
|
{% set seclabels = data.seclabels %}
|
||||||
{% if 'deleted' in seclabels and seclabels.deleted|length > 0 %}
|
{% if 'deleted' in seclabels and seclabels.deleted|length > 0 %}
|
||||||
@ -35,7 +35,7 @@ ALTER DATABASE {{ conn|qtIdent(data.name) }} WITH CONNECTION LIMIT = {{ data.dat
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{# The SQL generated below will change Variables #}
|
{# Change the variables/options #}
|
||||||
{% if data.variables and data.variables|length > 0 %}
|
{% if data.variables and data.variables|length > 0 %}
|
||||||
{% set variables = data.variables %}
|
{% set variables = data.variables %}
|
||||||
{% if 'deleted' in variables and variables.deleted|length > 0 %}
|
{% if 'deleted' in variables and variables.deleted|length > 0 %}
|
||||||
@ -67,7 +67,7 @@ ALTER DATABASE {{ conn|qtIdent(data.name) }} WITH CONNECTION LIMIT = {{ data.dat
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{# The SQL generated below will change priviledges #}
|
{# Change the priviledges/ACLs #}
|
||||||
{% if data.datacl %}
|
{% if data.datacl %}
|
||||||
{% if 'deleted' in data.datacl %}
|
{% if 'deleted' in data.datacl %}
|
||||||
{% for priv in data.datacl.deleted %}
|
{% for priv in data.datacl.deleted %}
|
||||||
@ -87,6 +87,7 @@ ALTER DATABASE {{ conn|qtIdent(data.name) }} WITH CONNECTION LIMIT = {{ data.dat
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{# Change the default priviledges/ACLs for tables #}
|
||||||
{% if data.deftblacl %}
|
{% if data.deftblacl %}
|
||||||
{% if 'deleted' in data.deftblacl %}
|
{% if 'deleted' in data.deftblacl %}
|
||||||
{% for priv in data.deftblacl.deleted %}
|
{% for priv in data.deftblacl.deleted %}
|
||||||
@ -106,6 +107,7 @@ ALTER DATABASE {{ conn|qtIdent(data.name) }} WITH CONNECTION LIMIT = {{ data.dat
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{# Change the default priviledges/ACLs for sequences #}
|
||||||
{% if data.defseqacl %}
|
{% if data.defseqacl %}
|
||||||
{% if 'deleted' in data.defseqacl %}
|
{% if 'deleted' in data.defseqacl %}
|
||||||
{% for priv in data.defseqacl.deleted %}
|
{% for priv in data.defseqacl.deleted %}
|
||||||
@ -125,6 +127,7 @@ ALTER DATABASE {{ conn|qtIdent(data.name) }} WITH CONNECTION LIMIT = {{ data.dat
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{# Change the default priviledges/ACLs for functions #}
|
||||||
{% if data.deffuncacl %}
|
{% if data.deffuncacl %}
|
||||||
{% if 'deleted' in data.deffuncacl %}
|
{% if 'deleted' in data.deffuncacl %}
|
||||||
{% for priv in data.deffuncacl.deleted %}
|
{% for priv in data.deffuncacl.deleted %}
|
||||||
@ -144,6 +147,7 @@ ALTER DATABASE {{ conn|qtIdent(data.name) }} WITH CONNECTION LIMIT = {{ data.dat
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{# Change the default priviledges/ACLs for types #}
|
||||||
{% if data.deftypeacl %}
|
{% if data.deftypeacl %}
|
||||||
{% if 'deleted' in data.deftypeacl %}
|
{% if 'deleted' in data.deftypeacl %}
|
||||||
{% for priv in data.deftypeacl.deleted %}
|
{% for priv in data.deftypeacl.deleted %}
|
||||||
|
@ -1,19 +1,19 @@
|
|||||||
{% if data %}
|
{% if data %}
|
||||||
CREATE DATABASE {{ conn|qtIdent(data.name) }}
|
CREATE DATABASE {{ conn|qtIdent(data.name) }}
|
||||||
{% if data.datowner %}
|
{% if data.datowner %}
|
||||||
WITH {% endif %}{% if data.datowner %}
|
WITH {% endif %}{% if data.datowner %}
|
||||||
|
|
||||||
OWNER = {{ conn|qtIdent(data.datowner) }}{% endif %}{% if data.template %}
|
OWNER = {{ conn|qtIdent(data.datowner) }}{% endif %}{% if data.template %}
|
||||||
|
|
||||||
TEMPLATE = {{ conn|qtIdent(data.template) }}{% endif %}{% if data.encoding %}
|
TEMPLATE = {{ conn|qtIdent(data.template) }}{% endif %}{% if data.encoding %}
|
||||||
|
|
||||||
ENCODING = {{ data.encoding|qtLiteral }}{% endif %}{% if data.datcollate %}
|
ENCODING = {{ data.encoding|qtLiteral }}{% endif %}{% if data.datcollate %}
|
||||||
|
|
||||||
LC_COLLATE = {{ data.datcollate|qtLiteral }}{% endif %}{% if data.datctype %}
|
LC_COLLATE = {{ data.datcollate|qtLiteral }}{% endif %}{% if data.datctype %}
|
||||||
|
|
||||||
LC_CTYPE = {{ data.datctype|qtLiteral }}{% endif %}{% if data.spcname %}
|
LC_CTYPE = {{ data.datctype|qtLiteral }}{% endif %}{% if data.spcname %}
|
||||||
|
|
||||||
TABLESPACE = {{ conn|qtIdent(data.spcname) }}{% endif %}{% if data.datconnlimit %}
|
TABLESPACE = {{ conn|qtIdent(data.spcname) }}{% endif %}{% if data.datconnlimit %}
|
||||||
|
|
||||||
CONNECTION LIMIT = {{ data.datconnlimit }}{% endif %};
|
CONNECTION LIMIT = {{ data.datconnlimit }}{% endif %};
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -1,34 +1,34 @@
|
|||||||
SELECT
|
SELECT
|
||||||
CASE (a.deftype)
|
CASE (a.deftype)
|
||||||
WHEN 'r' THEN 'deftblacl'
|
WHEN 'r' THEN 'deftblacl'
|
||||||
WHEN 'S' THEN 'defseqacl'
|
WHEN 'S' THEN 'defseqacl'
|
||||||
WHEN 'f' THEN 'deffuncacl'
|
WHEN 'f' THEN 'deffuncacl'
|
||||||
WHEN 'T' THEN 'deftypeacl'
|
WHEN 'T' THEN 'deftypeacl'
|
||||||
END AS deftype,
|
END AS deftype,
|
||||||
COALESCE(gt.rolname, 'public') AS grantee, g.rolname AS grantor, array_agg(a.privilege_type) as privileges, array_agg(a.is_grantable) as grantable
|
COALESCE(gt.rolname, 'public') AS grantee, g.rolname AS grantor, array_agg(a.privilege_type) as privileges, array_agg(a.is_grantable) as grantable
|
||||||
FROM
|
FROM
|
||||||
(SELECT
|
(SELECT
|
||||||
(acl).grantee as grantee, (acl).grantor AS grantor, (acl).is_grantable AS is_grantable,
|
(acl).grantee as grantee, (acl).grantor AS grantor, (acl).is_grantable AS is_grantable,
|
||||||
CASE (acl).privilege_type
|
CASE (acl).privilege_type
|
||||||
WHEN 'CONNECT' THEN 'c'
|
WHEN 'CONNECT' THEN 'c'
|
||||||
WHEN 'CREATE' THEN 'C'
|
WHEN 'CREATE' THEN 'C'
|
||||||
WHEN 'DELETE' THEN 'd'
|
WHEN 'DELETE' THEN 'd'
|
||||||
WHEN 'EXECUTE' THEN 'X'
|
WHEN 'EXECUTE' THEN 'X'
|
||||||
WHEN 'INSERT' THEN 'a'
|
WHEN 'INSERT' THEN 'a'
|
||||||
WHEN 'REFERENCES' THEN 'x'
|
WHEN 'REFERENCES' THEN 'x'
|
||||||
WHEN 'SELECT' THEN 'r'
|
WHEN 'SELECT' THEN 'r'
|
||||||
WHEN 'TEMPORARY' THEN 'T'
|
WHEN 'TEMPORARY' THEN 'T'
|
||||||
WHEN 'TRIGGER' THEN 't'
|
WHEN 'TRIGGER' THEN 't'
|
||||||
WHEN 'TRUNCATE' THEN 'D'
|
WHEN 'TRUNCATE' THEN 'D'
|
||||||
WHEN 'UPDATE' THEN 'w'
|
WHEN 'UPDATE' THEN 'w'
|
||||||
WHEN 'USAGE' THEN 'U'
|
WHEN 'USAGE' THEN 'U'
|
||||||
ELSE 'UNKNOWN'
|
ELSE 'UNKNOWN'
|
||||||
END AS privilege_type,
|
END AS privilege_type,
|
||||||
defaclobjtype as deftype
|
defaclobjtype as deftype
|
||||||
FROM
|
FROM
|
||||||
(SELECT defaclobjtype, aclexplode(defaclacl) as acl FROM pg_catalog.pg_default_acl dacl
|
(SELECT defaclobjtype, aclexplode(defaclacl) as acl FROM pg_catalog.pg_default_acl dacl
|
||||||
WHERE dacl.defaclnamespace = 0::OID) d) a
|
WHERE dacl.defaclnamespace = 0::OID) d) a
|
||||||
LEFT JOIN pg_catalog.pg_roles g ON (a.grantor = g.oid)
|
LEFT JOIN pg_catalog.pg_roles g ON (a.grantor = g.oid)
|
||||||
LEFT JOIN pg_catalog.pg_roles gt ON (a.grantee = gt.oid)
|
LEFT JOIN pg_catalog.pg_roles gt ON (a.grantee = gt.oid)
|
||||||
GROUP BY g.rolname, gt.rolname, a.deftype
|
GROUP BY g.rolname, gt.rolname, a.deftype
|
||||||
ORDER BY a.deftype
|
ORDER BY a.deftype
|
||||||
|
@ -4,5 +4,5 @@ SELECT db.datname as name FROM pg_database as db WHERE db.oid = {{did}}
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{# Using name from above query we will drop the database #}
|
{# Using name from above query we will drop the database #}
|
||||||
{% if datname %}
|
{% if datname %}
|
||||||
DROP DATABASE {{ conn|qtIdent(datname) }};
|
DROP DATABASE {{ conn|qtIdent(datname) }};
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -2,9 +2,10 @@
|
|||||||
-- Given SQL is workaround
|
-- Given SQL is workaround
|
||||||
-- We need to implement a mechanism to check for valid supported server encoding
|
-- We need to implement a mechanism to check for valid supported server encoding
|
||||||
#}
|
#}
|
||||||
SELECT * FROM
|
SELECT *
|
||||||
(SELECT pg_encoding_to_char(s.i) AS encoding
|
FROM
|
||||||
FROM (SELECT generate_series(0, 100, 1) as i) s) a
|
(SELECT pg_encoding_to_char(s.i) AS encoding
|
||||||
|
FROM (SELECT generate_series(0, 100, 1) as i) s) a
|
||||||
WHERE encoding != '';
|
WHERE encoding != '';
|
||||||
|
|
||||||
{#
|
{#
|
||||||
@ -14,4 +15,4 @@ WHERE encoding != '';
|
|||||||
-- as encoding
|
-- as encoding
|
||||||
-- FROM (SELECT generate_series(0, 100, 1) as i) s) a
|
-- FROM (SELECT generate_series(0, 100, 1) as i) s) a
|
||||||
--WHERE encoding != ''
|
--WHERE encoding != ''
|
||||||
#}
|
#}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
SELECT rl.*, r.rolname AS user_name, db.datname as db_name
|
SELECT
|
||||||
|
rl.*, r.rolname AS user_name, db.datname as db_name
|
||||||
FROM pg_db_role_setting AS rl
|
FROM pg_db_role_setting AS rl
|
||||||
LEFT JOIN pg_roles AS r ON rl.setrole = r.oid
|
LEFT JOIN pg_roles AS r ON rl.setrole = r.oid
|
||||||
LEFT JOIN pg_database AS db ON rl.setdatabase = db.oid
|
LEFT JOIN pg_database AS db ON rl.setdatabase = db.oid
|
||||||
WHERE setdatabase = {{did}}
|
WHERE setdatabase = {{did}}
|
||||||
|
@ -9,16 +9,16 @@
|
|||||||
{% import 'macros/default_privilege.macros' as DEFAULT_PRIVILEGE %}
|
{% import 'macros/default_privilege.macros' as DEFAULT_PRIVILEGE %}
|
||||||
{% if data.comments %}
|
{% if data.comments %}
|
||||||
COMMENT ON DATABASE {{ conn|qtIdent(data.name) }}
|
COMMENT ON DATABASE {{ conn|qtIdent(data.name) }}
|
||||||
IS {{ data.comments|qtLiteral }};
|
IS {{ data.comments|qtLiteral }};
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{# We will generate Security Label SQL's using macro #}
|
{# Change the security labels #}
|
||||||
{% if data.securities %}
|
{% if data.securities %}
|
||||||
{% for r in data.securities %}
|
{% for r in data.securities %}
|
||||||
{{ SECLABEL.APPLY(conn, 'DATABASE', data.name, r.provider, r.securitylabel) }}
|
{{ SECLABEL.APPLY(conn, 'DATABASE', data.name, r.provider, r.securitylabel) }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{# We will generate Variable SQL's using macro #}
|
{# Variables/options #}
|
||||||
{% if data.variables %}
|
{% if data.variables %}
|
||||||
{% for var in data.variables %}
|
{% for var in data.variables %}
|
||||||
{% if var.value == True %}
|
{% if var.value == True %}
|
||||||
@ -30,26 +30,33 @@ COMMENT ON DATABASE {{ conn|qtIdent(data.name) }}
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{# Privileges/ACLs #}
|
||||||
{% if data.datacl %}
|
{% if data.datacl %}
|
||||||
{% for priv in data.datacl %}
|
{% for priv in data.datacl %}
|
||||||
{{ PRIVILEGE.APPLY(conn, 'DATABASE', priv.grantee, data.name, priv.without_grant, priv.with_grant) }}
|
{{ PRIVILEGE.APPLY(conn, 'DATABASE', priv.grantee, data.name, priv.without_grant, priv.with_grant) }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{# Default privileges/ACLs for tables #}
|
||||||
{% if data.deftblacl %}
|
{% if data.deftblacl %}
|
||||||
{% for priv in data.deftblacl %}
|
{% for priv in data.deftblacl %}
|
||||||
{{ DEFAULT_PRIVILEGE.APPLY(conn, 'TABLES', priv.grantee, priv.without_grant, priv.with_grant) }}
|
{{ DEFAULT_PRIVILEGE.APPLY(conn, 'TABLES', priv.grantee, priv.without_grant, priv.with_grant) }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{# Default privileges/ACLs for sequences #}
|
||||||
{% if data.defseqacl %}
|
{% if data.defseqacl %}
|
||||||
{% for priv in data.defseqacl %}
|
{% for priv in data.defseqacl %}
|
||||||
{{ DEFAULT_PRIVILEGE.APPLY(conn, 'SEQUENCES', priv.grantee, priv.without_grant, priv.with_grant) }}
|
{{ DEFAULT_PRIVILEGE.APPLY(conn, 'SEQUENCES', priv.grantee, priv.without_grant, priv.with_grant) }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{# Default privileges/ACLs for functions #}
|
||||||
{% if data.deffuncacl %}
|
{% if data.deffuncacl %}
|
||||||
{% for priv in data.deffuncacl %}
|
{% for priv in data.deffuncacl %}
|
||||||
{{ DEFAULT_PRIVILEGE.APPLY(conn, 'FUNCTIONS', priv.grantee, priv.without_grant, priv.with_grant) }}
|
{{ DEFAULT_PRIVILEGE.APPLY(conn, 'FUNCTIONS', priv.grantee, priv.without_grant, priv.with_grant) }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{# Default privileges/ACLs for types #}
|
||||||
{% if data.deftypeacl %}
|
{% if data.deftypeacl %}
|
||||||
{% for priv in data.deftypeacl %}
|
{% for priv in data.deftypeacl %}
|
||||||
{{ DEFAULT_PRIVILEGE.APPLY(conn, 'TYPES', priv.grantee, priv.without_grant, priv.with_grant) }}
|
{{ DEFAULT_PRIVILEGE.APPLY(conn, 'TYPES', priv.grantee, priv.without_grant, priv.with_grant) }}
|
||||||
|
@ -1 +1,4 @@
|
|||||||
SELECT name, vartype, min_val, max_val, enumvals FROM pg_settings WHERE context in ('user', 'superuser')
|
SELECT
|
||||||
|
name, vartype, min_val, max_val, enumvals
|
||||||
|
FROM pg_settings
|
||||||
|
WHERE context in ('user', 'superuser');
|
||||||
|
Loading…
Reference in New Issue
Block a user