Ensure the properties dialogues create objects in a single transaction/statement. Fixes #1107

pull/3/head
Sanket Mehta 2016-06-10 16:07:24 +01:00 committed by Dave Page
parent 085f8e198e
commit d5a91c969c
32 changed files with 199 additions and 309 deletions

View File

@ -506,6 +506,7 @@ It may have been removed by another user.
)
)
try:
self.format_request_acls(data, specific=['nspacl'])
SQL = render_template(
"/".join([self.template_path, 'sql/create.sql']),
data=data, conn=self.conn, _=gettext
@ -518,22 +519,6 @@ It may have been removed by another user.
errormsg=res + '\n' +
'Operation failed while running create statement'
)
self.format_request_acls(data, specific=['nspacl'])
SQL = render_template(
"/".join([self.template_path, 'sql/alter.sql']),
data=data, conn=self.conn, _=gettext
)
# Checking if we are not executing empty query
if SQL and SQL.strip('\n') and SQL.strip(' '):
status, res = self.conn.execute_scalar(SQL)
if not status:
return make_json_response(
status=410,
success=0,
errormsg=res + '\n' +
'Operation failed while running alter statement'
)
# we need oid to to add object in tree at browser,
# below sql will gives the same
@ -727,11 +712,6 @@ It may have been removed by another user.
"/".join([self.template_path, 'sql/create.sql']),
data=data, conn=self.conn, _=gettext
)
SQL += "\n"
SQL += render_template(
"/".join([self.template_path, 'sql/alter.sql']),
_=gettext, data=data, conn=self.conn
)
return SQL
@ -774,11 +754,6 @@ It may have been removed by another user.
"/".join([self.template_path, 'sql/create.sql']),
_=gettext, data=data, conn=self.conn
)
SQL += "\n"
SQL += render_template(
"/".join([self.template_path, 'sql/alter.sql']),
_=gettext, data=data, conn=self.conn
)
sql_header = """
-- SCHEMA: {0}
@ -867,7 +842,6 @@ It may have been removed by another user.
return make_json_response(data=nodes)
class CatalogView(SchemaView):
"""
This class is responsible for generating routes for catalog schema node.
@ -965,11 +939,6 @@ It may have been removed by another user.
"/".join([self.template_path, 'sql/create.sql']),
_=gettext, data=old_data, conn=self.conn
)
SQL += "\n"
SQL += render_template(
"/".join([self.template_path, 'sql/alter.sql']),
_=gettext, data=old_data, conn=self.conn
)
sql_header = """
-- CATALOG: {0}

View File

@ -1747,14 +1747,6 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
if ctype == 'p' else 'UNIQUE'
).strip('\n')
)
# sql to update comments
sql.append(
render_template(
"/".join([self.index_constraint_template_path,
'alter.sql']),
data=c, conn=self.conn
).strip('\n')
)
else:
sql.append(
gettext(
@ -1871,14 +1863,6 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
data=c, conn=self.conn
).strip('\n')
)
# sql to update comments
sql.append(
render_template(
"/".join([self.foreign_key_template_path,
'alter.sql']),
data=c, conn=self.conn
).strip('\n')
)
if c['autoindex']:
sql.append(
@ -1963,14 +1947,6 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
data=c, conn=self.conn
).strip('\n')
)
# sql to update comments
sql.append(
render_template(
"/".join([self.check_constraint_template_path,
'alter.sql']),
data=c, conn=self.conn
).strip('\n')
)
if len(sql) > 0:
# Join all the sql(s) as single string
@ -2047,14 +2023,6 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
data=c, conn=self.conn
).strip('\n')
)
# sql to update comments
sql.append(
render_template(
"/".join([self.exclusion_constraint_template_path,
'alter.sql']),
data=c, conn=self.conn
).strip('\n')
)
if len(sql) > 0:
# Join all the sql(s) as single string

View File

@ -465,17 +465,6 @@ class CheckConstraintView(PGChildNodeView):
icon = "icon-check_constraints"
valid = True
sql = render_template("/".join([self.template_path, 'alter.sql']),
data=data,
conn=self.conn)
sql = sql.strip('\n').strip(' ')
if sql != '':
status, result = self.conn.execute_scalar(sql)
if not status:
self.end_transaction()
return internal_server_error(errormsg=result)
return jsonify(
node=self.blueprint.generate_browser_node(
res['rows'][0]['oid'],
@ -638,10 +627,6 @@ class CheckConstraintView(PGChildNodeView):
SQL = render_template("/".join([self.template_path,
'create.sql']),
data=data)
SQL += "\n"
SQL += render_template(
"/".join([self.template_path, 'alter.sql']),
data=data)
sql_header = "-- Constraint: {0}\n\n-- ".format(data['name'])
@ -735,9 +720,6 @@ class CheckConstraintView(PGChildNodeView):
SQL = render_template("/".join([self.template_path,
'create.sql']),
data=data)
SQL += "\n"
SQL += render_template("/".join([self.template_path, 'alter.sql']),
data=data)
return SQL
except Exception as e:

View File

@ -506,15 +506,6 @@ class ExclusionConstraintView(PGChildNodeView):
if not status:
self.end_transaction()
return internal_server_error(errormsg=res)
if 'name' in data and data['name'] != '':
sql = render_template("/".join([self.template_path, 'alter.sql']), data=data, conn=self.conn)
sql = sql.strip('\n').strip(' ')
if sql != '':
status, result = self.conn.execute_scalar(sql)
if not status:
self.end_transaction()
return internal_server_error(errormsg=result)
return jsonify(
node=self.blueprint.generate_browser_node(
@ -728,9 +719,6 @@ class ExclusionConstraintView(PGChildNodeView):
sql = render_template("/".join([self.template_path, 'create.sql']),
data=data, conn=self.conn)
sql += "\n"
sql += render_template("/".join([self.template_path, 'alter.sql']),
data=data, conn=self.conn)
return sql
@ -795,10 +783,6 @@ class ExclusionConstraintView(PGChildNodeView):
SQL = render_template(
"/".join([self.template_path, 'create.sql']), data=data)
SQL += "\n"
SQL += render_template(
"/".join([self.template_path, 'alter.sql']),
data=data, conn=self.conn)
sql_header = "-- Constraint: {0}\n\n-- ".format(data['name'])

View File

@ -547,15 +547,6 @@ class ForeignKeyConstraintView(PGChildNodeView):
icon = "icon-foreign_key"
valid = True
sql = render_template("/".join([self.template_path, 'alter.sql']), data=data, conn=self.conn)
sql = sql.strip('\n').strip(' ')
if sql != '':
status, result = self.conn.execute_scalar(sql)
if not status:
self.end_transaction()
return internal_server_error(errormsg=result)
if data['autoindex']:
sql = render_template(
"/".join([self.template_path, 'create_index.sql']),
@ -827,9 +818,6 @@ class ForeignKeyConstraintView(PGChildNodeView):
sql = render_template("/".join([self.template_path, 'create.sql']),
data=data, conn=self.conn)
sql += "\n"
sql += render_template("/".join([self.template_path, 'alter.sql']),
data=data, conn=self.conn)
if data['autoindex']:
sql += render_template(
@ -898,10 +886,6 @@ class ForeignKeyConstraintView(PGChildNodeView):
SQL = render_template(
"/".join([self.template_path, 'create.sql']), data=data)
SQL += "\n"
SQL += render_template(
"/".join([self.template_path, 'alter.sql']),
data=data, conn=self.conn)
sql_header = "-- Constraint: {0}\n\n-- ".format(data['name'])

View File

@ -526,17 +526,6 @@ class IndexConstraintView(PGChildNodeView):
self.end_transaction()
return internal_server_error(errormsg=res)
sql = render_template("/".join([self.template_path, 'alter.sql']),
data=data,
conn=self.conn)
sql = sql.strip('\n').strip(' ')
if sql != '':
status, result = self.conn.execute_scalar(sql)
if not status:
self.end_transaction()
return internal_server_error(errormsg=result)
return jsonify(
node=self.blueprint.generate_browser_node(
res['rows'][0]['oid'],
@ -768,10 +757,6 @@ class IndexConstraintView(PGChildNodeView):
data=data,
conn=self.conn,
constraint_name=self.constraint_name)
sql += "\n"
sql += render_template("/".join([self.template_path, 'alter.sql']),
data=data,
conn=self.conn)
return sql
@ -826,10 +811,6 @@ class IndexConstraintView(PGChildNodeView):
"/".join([self.template_path, 'create.sql']),
data=data,
constraint_name=self.constraint_name)
SQL += "\n"
SQL += render_template(
"/".join([self.template_path, 'alter.sql']),
data=data, conn=self.conn)
sql_header = "-- Constraint: {0}\n\n-- ".format(data['name'])

View File

@ -557,15 +557,19 @@ class IndexesView(PGChildNodeView):
data['table'] = self.table
try:
# Start transaction.
self.conn.execute_scalar("BEGIN;")
SQL = render_template("/".join([self.template_path,
'create.sql']),
data=data, conn=self.conn, mode='create')
status, res = self.conn.execute_scalar(SQL)
if not status:
# End transaction.
self.conn.execute_scalar("END;")
return internal_server_error(errormsg=res)
# If user chooses concurrent index then we can not run it along
# with other alter statments so we will separate alter index part
# with other alter statements so we will separate alter index part
SQL = render_template("/".join([self.template_path,
'alter.sql']),
data=data, conn=self.conn)
@ -573,6 +577,8 @@ class IndexesView(PGChildNodeView):
if SQL != '':
status, res = self.conn.execute_scalar(SQL)
if not status:
# End transaction.
self.conn.execute_scalar("END;")
return internal_server_error(errormsg=res)
# we need oid to to add object in tree at browser
@ -581,8 +587,12 @@ class IndexesView(PGChildNodeView):
tid=tid, data=data)
status, idx = self.conn.execute_scalar(SQL)
if not status:
# End transaction.
self.conn.execute_scalar("END;")
return internal_server_error(errormsg=tid)
# End transaction.
self.conn.execute_scalar("END;")
return jsonify(
node=self.blueprint.generate_browser_node(
idx,
@ -592,6 +602,8 @@ class IndexesView(PGChildNodeView):
)
)
except Exception as e:
# End transaction.
self.conn.execute_scalar("END;")
return internal_server_error(errormsg=str(e))
@check_precondition

View File

@ -1,4 +0,0 @@
{% if data.comment %}
COMMENT ON CONSTRAINT {{ conn|qtIdent(data.name) }} ON {{ conn|qtIdent(data.schema, data.table) }}
IS {{ data.comment|qtLiteral }};
{% endif %}

View File

@ -2,3 +2,8 @@
ALTER TABLE {{ conn|qtIdent(data.schema, data.table) }}
ADD{% if data.name %} CONSTRAINT {{ conn|qtIdent(data.name) }}{% endif%} CHECK ({{ data.consrc }});
{% endif %}
{% if data.comment %}
COMMENT ON CONSTRAINT {{ conn|qtIdent(data.name) }} ON {{ conn|qtIdent(data.schema, data.table) }}
IS {{ data.comment|qtLiteral }};
{% endif %}

View File

@ -1,4 +0,0 @@
{% if data.comment %}
COMMENT ON CONSTRAINT {{ conn|qtIdent(data.name) }} ON {{ conn|qtIdent(data.schema, data.table) }}
IS {{ data.comment|qtLiteral }};
{% endif %}

View File

@ -4,3 +4,8 @@ ALTER TABLE {{ conn|qtIdent(data.schema, data.table) }}
NOT VALID{% endif %}{% if data.connoinherit %} NO INHERIT{% endif %};
{% endif %}
{% if data.comment %}
COMMENT ON CONSTRAINT {{ conn|qtIdent(data.name) }} ON {{ conn|qtIdent(data.schema, data.table) }}
IS {{ data.comment|qtLiteral }};
{% endif %}

View File

@ -1,4 +0,0 @@
{% if data.comment %}
COMMENT ON CONSTRAINT {{ conn|qtIdent(data.name) }} ON {{ conn|qtIdent(data.schema, data.table) }}
IS {{ data.comment|qtLiteral }};
{% endif %}

View File

@ -9,4 +9,9 @@ ALTER TABLE {{ conn|qtIdent(data.schema, data.table) }}
DEFERRABLE{% if data.condeferred %}
INITIALLY DEFERRED{% endif%}
{% endif%}{% if data.constraint %} WHERE ({{data.constraint}}){% endif%};
{% endif%}{% if data.constraint %} WHERE ({{data.constraint}}){% endif%};
{% if data.comment and data.name %}
COMMENT ON CONSTRAINT {{ conn|qtIdent(data.name) }} ON {{ conn|qtIdent(data.schema, data.table) }}
IS {{ data.comment|qtLiteral }};
{% endif %}

View File

@ -1,4 +0,0 @@
{% if data.comment %}
COMMENT ON CONSTRAINT {{ conn|qtIdent(data.name) }} ON {{ conn|qtIdent(data.schema, data.table) }}
IS {{ data.comment|qtLiteral }};
{% endif %}

View File

@ -9,4 +9,9 @@ ALTER TABLE {{ conn|qtIdent(data.schema, data.table) }}
DEFERRABLE{% if data.condeferred %}
INITIALLY DEFERRED{% endif%}
{% endif%}{% if data.constraint %} WHERE ({{data.constraint}}){% endif%};
{% endif%}{% if data.constraint %} WHERE ({{data.constraint}}){% endif%};
{% if data.comment and data.name %}
COMMENT ON CONSTRAINT {{ conn|qtIdent(data.name) }} ON {{ conn|qtIdent(data.schema, data.table) }}
IS {{ data.comment|qtLiteral }};
{% endif %}

View File

@ -1,4 +0,0 @@
{% if data.comment %}
COMMENT ON CONSTRAINT {{ conn|qtIdent(data.name) }} ON {{ conn|qtIdent(data.schema, data.table) }}
IS {{ data.comment|qtLiteral }};
{% endif %}

View File

@ -24,4 +24,9 @@ ALTER TABLE {{ conn|qtIdent(data.schema, data.table) }}
{% endif%}
{% if data.convalidated %}
NOT VALID{% endif%};
NOT VALID{% endif%};
{% if data.comment and data.name %}
COMMENT ON CONSTRAINT {{ conn|qtIdent(data.name) }} ON {{ conn|qtIdent(data.schema, data.table) }}
IS {{ data.comment|qtLiteral }};
{% endif %}

View File

@ -1,4 +0,0 @@
{% if data.comment %}
COMMENT ON CONSTRAINT {{ conn|qtIdent(data.name) }} ON {{ conn|qtIdent(data.schema, data.table) }}
IS {{ data.comment|qtLiteral }};
{% endif %}

View File

@ -9,4 +9,9 @@ ALTER TABLE {{ conn|qtIdent(data.schema, data.table) }}
DEFERRABLE{% if data.condeferred %}
INITIALLY DEFERRED{% endif%}
{% endif%};
{% endif%};
{% if data.comment and data.name %}
COMMENT ON CONSTRAINT {{ conn|qtIdent(data.name) }} ON {{ conn|qtIdent(data.schema, data.table) }}
IS {{ data.comment|qtLiteral }};
{% endif %}

View File

@ -1 +0,0 @@
{# We have nothing to alter in the catalog #}

View File

@ -1 +0,0 @@
{# We have nothing to alter in the catalog #}

View File

@ -1 +0,0 @@
{# We have nothing to alter in the catalog #}

View File

@ -1 +0,0 @@
{# We have nothing to alter in the catalog #}

View File

@ -1,35 +0,0 @@
{% import 'macros/security.macros' as SECLABLE %}
{% import 'macros/privilege.macros' as PRIVILEGE %}
{% import 'macros/default_privilege.macros' as DEFAULT_PRIVILEGE %}
{# Alter the comment/description #}
{% if data.description %}
COMMENT ON SCHEMA {{ conn|qtIdent(data.name) }}
IS {{ data.description|qtLiteral }};
{% endif %}
{# ACL for the schema #}
{% if data.nspacl %}
{% for priv in data.nspacl %}
{{ PRIVILEGE.APPLY(conn, 'SCHEMA', priv.grantee, data.name, priv.without_grant, priv.with_grant) }}{% endfor %}
{% endif %}
{# Default privileges on tables #}
{% for defacl, type in [
('deftblacl', 'TABLES'), ('defseqacl', 'SEQUENCES'),
('deffuncacl', 'FUNCTIONS')]
%}
{% if data[defacl] %}{% set acl = data[defacl] %}
{% for priv in data.deftblacl %}
{{ DEFAULT_PRIVILEGE.SET(
conn, 'SCHEMA', data.name, type, priv.grantee,
priv.without_grant, priv.with_grant
) }}{% endfor %}
{% endif %}
{% endfor %}
{# Security Labels on schema #}
{% if data.seclabels and data.seclabels|length > 0 %}
{% for r in data.seclabels %}
{{ SECLABLE.APPLY(conn, 'SCHEMA', data.name, r.provider, r.label) }}
{% endfor %}
{% endif %}

View File

@ -1,7 +1,44 @@
{% import 'macros/security.macros' as SECLABLE %}
{% import 'macros/privilege.macros' as PRIVILEGE %}
{% import 'macros/default_privilege.macros' as DEFAULT_PRIVILEGE %}
{% if data.name %}
CREATE SCHEMA {{ conn|qtIdent(data.name) }}{% if data.namespaceowner %}
AUTHORIZATION {{ conn|qtIdent(data.namespaceowner) }}{% endif %};
{# Alter the comment/description #}
{% if data.description %}
COMMENT ON SCHEMA {{ conn|qtIdent(data.name) }}
IS {{ data.description|qtLiteral }};
{% endif %}
{# ACL for the schema #}
{% if data.nspacl %}
{% for priv in data.nspacl %}
{{ PRIVILEGE.APPLY(conn, 'SCHEMA', priv.grantee, data.name, priv.without_grant, priv.with_grant) }}{% endfor %}
{% endif %}
{# Default privileges on tables #}
{% for defacl, type in [
('deftblacl', 'TABLES'), ('defseqacl', 'SEQUENCES'),
('deffuncacl', 'FUNCTIONS')]
%}
{% if data[defacl] %}{% set acl = data[defacl] %}
{% for priv in data.deftblacl %}
{{ DEFAULT_PRIVILEGE.SET(
conn, 'SCHEMA', data.name, type, priv.grantee,
priv.without_grant, priv.with_grant
) }}{% endfor %}
{% endif %}
{% endfor %}
{# Security Labels on schema #}
{% if data.seclabels and data.seclabels|length > 0 %}
{% for r in data.seclabels %}
{{ SECLABLE.APPLY(conn, 'SCHEMA', data.name, r.provider, r.label) }}
{% endfor %}
{% endif %}
{% else %}
{{ -- _('Incomplete definition') }}
{% endif %}

View File

@ -1,35 +0,0 @@
{% import 'macros/security.macros' as SECLABEL %}
{% import 'macros/privilege.macros' as PRIVILEGE %}
{% import 'macros/default_privilege.macros' as DEFAULT_PRIVILEGE %}
{# Alter the comment/description #}
{% if data.description %}
COMMENT ON SCHEMA {{ conn|qtIdent(data.name) }}
IS {{ data.description|qtLiteral }};
{% endif %}
{# ACL for the schema #}
{% if data.nspacl %}
{% for priv in data.nspacl %}
{{ PRIVILEGE.APPLY(conn, 'SCHEMA', priv.grantee, data.name, priv.without_grant, priv.with_grant) }}{% endfor %}
{% endif %}
{# Default privileges on tables #}
{% for defacl, type in [
('deftblacl', 'TABLES'), ('defseqacl', 'SEQUENCES'),
('deffuncacl', 'FUNCTIONS'), ('deftypeacl', 'TYPES')]
%}
{% if data[defacl] %}{% set acl = data[defacl] %}
{% for priv in data.deftblacl %}
{{ DEFAULT_PRIVILEGE.SET(
conn, 'SCHEMA', data.name, type, priv.grantee,
priv.without_grant, priv.with_grant
) }}{% endfor %}
{% endif %}
{% endfor %}
{# Security Labels on schema #}
{% if data.seclabels and data.seclabels|length > 0 %}
{% for r in data.seclabels %}
{{ SECLABEL.APPLY(conn, 'SCHEMA', data.name, r.provider, r.label) }}
{% endfor %}
{% endif %}

View File

@ -1,7 +1,44 @@
{% import 'macros/security.macros' as SECLABEL %}
{% import 'macros/privilege.macros' as PRIVILEGE %}
{% import 'macros/default_privilege.macros' as DEFAULT_PRIVILEGE %}
{% if data.name %}
CREATE SCHEMA {{ conn|qtIdent(data.name) }}{% if data.namespaceowner %}
AUTHORIZATION {{ conn|qtIdent(data.namespaceowner) }}{% endif %};
{# Alter the comment/description #}
{% if data.description %}
COMMENT ON SCHEMA {{ conn|qtIdent(data.name) }}
IS {{ data.description|qtLiteral }};
{% endif %}
{# ACL for the schema #}
{% if data.nspacl %}
{% for priv in data.nspacl %}
{{ PRIVILEGE.APPLY(conn, 'SCHEMA', priv.grantee, data.name, priv.without_grant, priv.with_grant) }}{% endfor %}
{% endif %}
{# Default privileges on tables #}
{% for defacl, type in [
('deftblacl', 'TABLES'), ('defseqacl', 'SEQUENCES'),
('deffuncacl', 'FUNCTIONS'), ('deftypeacl', 'TYPES')]
%}
{% if data[defacl] %}{% set acl = data[defacl] %}
{% for priv in data.deftblacl %}
{{ DEFAULT_PRIVILEGE.SET(
conn, 'SCHEMA', data.name, type, priv.grantee,
priv.without_grant, priv.with_grant
) }}{% endfor %}
{% endif %}
{% endfor %}
{# Security Labels on schema #}
{% if data.seclabels and data.seclabels|length > 0 %}
{% for r in data.seclabels %}
{{ SECLABEL.APPLY(conn, 'SCHEMA', data.name, r.provider, r.label) }}
{% endfor %}
{% endif %}
{% else %}
{{ -- _('Incomplete definition') }}
{% endif %}

View File

@ -1,35 +0,0 @@
{% import 'macros/security.macros' as SECLABEL %}
{% import 'macros/privilege.macros' as PRIVILEGE %}
{% import 'macros/default_privilege.macros' as DEFAULT_PRIVILEGE %}
{# Alter the comment/description #}
{% if data.description %}
COMMENT ON SCHEMA {{ conn|qtIdent(data.name) }}
IS {{ data.description|qtLiteral }};
{% endif %}
{# ACL for the schema #}
{% if data.nspacl %}
{% for priv in data.nspacl %}
{{ PRIVILEGE.APPLY(conn, 'SCHEMA', priv.grantee, data.name, priv.without_grant, priv.with_grant) }}{% endfor %}
{% endif %}
{# Default privileges on tables #}
{% for defacl, type in [
('deftblacl', 'TABLES'), ('defseqacl', 'SEQUENCES'),
('deffuncacl', 'FUNCTIONS')]
%}
{% if data[defacl] %}{% set acl = data[defacl] %}
{% for priv in data.deftblacl %}
{{ DEFAULT_PRIVILEGE.SET(
conn, 'SCHEMA', data.name, type, priv.grantee,
priv.without_grant, priv.with_grant
) }}{% endfor %}
{% endif %}
{% endfor %}
{# Security Labels on schema #}
{% if data.seclabels and data.seclabels|length > 0 %}
{% for r in data.seclabels %}
{{ SECLABEL.APPLY(conn, 'SCHEMA', data.name, r.provider, r.label) }}
{% endfor %}
{% endif %}

View File

@ -1,7 +1,44 @@
{% import 'macros/security.macros' as SECLABEL %}
{% import 'macros/privilege.macros' as PRIVILEGE %}
{% import 'macros/default_privilege.macros' as DEFAULT_PRIVILEGE %}
{% if data.name %}
CREATE SCHEMA {{ conn|qtIdent(data.name) }}{% if data.namespaceowner %}
AUTHORIZATION {{ conn|qtIdent(data.namespaceowner) }}{% endif %};
{# Alter the comment/description #}
{% if data.description %}
COMMENT ON SCHEMA {{ conn|qtIdent(data.name) }}
IS {{ data.description|qtLiteral }};
{% endif %}
{# ACL for the schema #}
{% if data.nspacl %}
{% for priv in data.nspacl %}
{{ PRIVILEGE.APPLY(conn, 'SCHEMA', priv.grantee, data.name, priv.without_grant, priv.with_grant) }}{% endfor %}
{% endif %}
{# Default privileges on tables #}
{% for defacl, type in [
('deftblacl', 'TABLES'), ('defseqacl', 'SEQUENCES'),
('deffuncacl', 'FUNCTIONS')]
%}
{% if data[defacl] %}{% set acl = data[defacl] %}
{% for priv in data.deftblacl %}
{{ DEFAULT_PRIVILEGE.SET(
conn, 'SCHEMA', data.name, type, priv.grantee,
priv.without_grant, priv.with_grant
) }}{% endfor %}
{% endif %}
{% endfor %}
{# Security Labels on schema #}
{% if data.seclabels and data.seclabels|length > 0 %}
{% for r in data.seclabels %}
{{ SECLABEL.APPLY(conn, 'SCHEMA', data.name, r.provider, r.label) }}
{% endfor %}
{% endif %}
{% else %}
{{ -- _('Incomplete definition') }}
{% endif %}

View File

@ -1,35 +0,0 @@
{% import 'macros/security.macros' as SECLABEL %}
{% import 'macros/privilege.macros' as PRIVILEGE %}
{% import 'macros/default_privilege.macros' as DEFAULT_PRIVILEGE %}
{# Alter the comment/description #}
{% if data.description %}
COMMENT ON SCHEMA {{ conn|qtIdent(data.name) }}
IS {{ data.description|qtLiteral }};
{% endif %}
{# ACL for the schema #}
{% if data.nspacl %}
{% for priv in data.nspacl %}
{{ PRIVILEGE.APPLY(conn, 'SCHEMA', priv.grantee, data.name, priv.without_grant, priv.with_grant) }}{% endfor %}
{% endif %}
{# Default privileges on tables #}
{% for defacl, type in [
('deftblacl', 'TABLES'), ('defseqacl', 'SEQUENCES'),
('deffuncacl', 'FUNCTIONS'), ('deftypeacl', 'TYPES')]
%}
{% if data[defacl] %}{% set acl = data[defacl] %}
{% for priv in data.deftblacl %}
{{ DEFAULT_PRIVILEGE.SET(
conn, 'SCHEMA', data.name, type, priv.grantee,
priv.without_grant, priv.with_grant
) }}{% endfor %}
{% endif %}
{% endfor %}
{# Security Labels on schema #}
{% if data.seclabels and data.seclabels|length > 0 %}
{% for r in data.seclabels %}
{{ SECLABEL.APPLY(conn, 'SCHEMA', data.name, r.provider, r.label) }}
{% endfor %}
{% endif %}

View File

@ -1,7 +1,44 @@
{% import 'macros/security.macros' as SECLABEL %}
{% import 'macros/privilege.macros' as PRIVILEGE %}
{% import 'macros/default_privilege.macros' as DEFAULT_PRIVILEGE %}
{% if data.name %}
CREATE SCHEMA {{ conn|qtIdent(data.name) }}{% if data.namespaceowner %}
AUTHORIZATION {{ conn|qtIdent(data.namespaceowner) }}{% endif %};
{# Alter the comment/description #}
{% if data.description %}
COMMENT ON SCHEMA {{ conn|qtIdent(data.name) }}
IS {{ data.description|qtLiteral }};
{% endif %}
{# ACL for the schema #}
{% if data.nspacl %}
{% for priv in data.nspacl %}
{{ PRIVILEGE.APPLY(conn, 'SCHEMA', priv.grantee, data.name, priv.without_grant, priv.with_grant) }}{% endfor %}
{% endif %}
{# Default privileges on tables #}
{% for defacl, type in [
('deftblacl', 'TABLES'), ('defseqacl', 'SEQUENCES'),
('deffuncacl', 'FUNCTIONS'), ('deftypeacl', 'TYPES')]
%}
{% if data[defacl] %}{% set acl = data[defacl] %}
{% for priv in data.deftblacl %}
{{ DEFAULT_PRIVILEGE.SET(
conn, 'SCHEMA', data.name, type, priv.grantee,
priv.without_grant, priv.with_grant
) }}{% endfor %}
{% endif %}
{% endfor %}
{# Security Labels on schema #}
{% if data.seclabels and data.seclabels|length > 0 %}
{% for r in data.seclabels %}
{{ SECLABEL.APPLY(conn, 'SCHEMA', data.name, r.provider, r.label) }}
{% endfor %}
{% endif %}
{% else %}
{{ -- _('Incomplete definition') }}
{% endif %}

View File

@ -1,7 +1,7 @@
{#
# CREATE DATABSE does not allow us to run any
# other sql statments along with it, so we wrote
# seprate sql for rest alter sql statments here
# CREATE DATABASE does not allow us to run any
# other sql statements along with it, so we wrote
# separate sql for rest alter sql statements here
#}
{% import 'macros/security.macros' as SECLABEL %}
{% import 'macros/variable.macros' as VARIABLE %}