Fixes #1207 - Unable to comments on materialized view with Postgres Plus

Advanced Server.

Made changes in the query templates for create, view-id, and update to
make it work properly with it.
This commit is contained in:
Surinder Kumar
2016-05-25 00:48:19 +05:30
committed by Ashesh Vashi
parent c0ab396fad
commit 05dde57651
6 changed files with 76 additions and 51 deletions

View File

@@ -14,10 +14,9 @@ WITH (
{% endif %} {% endif %}
{% for field in data['vacuum_data'] %} {% for field in data['vacuum_data'] %}
{% if field.value is defined and field.value != '' and field.value != none %} {% if field.value is defined and field.value != '' and field.value != none %}
{% if loop.index > 1%}, {% if loop.index > 1 %},
{% endif %} {{ field.name }} = {{ field.value|lower }}{% endif %} {% endif %} {{ field.name }} = {{ field.value|lower }}{% endif %}
{% endfor %} {% endfor %}{{ '\r' }}
) )
{% endif %} {% endif %}
{% if data.spcname %}TABLESPACE {{ data.spcname }} {% if data.spcname %}TABLESPACE {{ data.spcname }}
@@ -35,7 +34,7 @@ ALTER TABLE {{ conn|qtIdent(data.schema, data.name) }}
{% endif %} {% endif %}
{% if data.comment %} {% if data.comment %}
COMMENT ON VIEW {{ conn|qtIdent(data.schema, data.name) }} COMMENT ON MATERIALIZED VIEW {{ conn|qtIdent(data.schema, data.name) }}
IS {{ data.comment|qtLiteral }}; IS {{ data.comment|qtLiteral }};
{% endif %} {% endif %}
{% endif %} {% endif %}

View File

@@ -156,7 +156,6 @@ SET(
{% endif %} {% endif %}
{% endfor %} {% endfor %}
); );
{% endif %} {% endif %}
{% if data['vacuum_data']['reset']|length > 0 %} {% if data['vacuum_data']['reset']|length > 0 %}
ALTER MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }} ALTER MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }}
@@ -166,7 +165,6 @@ RESET(
{% endfor %} {% endfor %}
); );
{% endif %} {% endif %}
{% endif %}{# ===== End check for custom autovaccum ===== #} {% endif %}{# ===== End check for custom autovaccum ===== #}
{% endif %}{# ===== End block for check data definition ===== #} {% endif %}{# ===== End block for check data definition ===== #}
{% set old_comment = o_data.comment|default('', true) %} {% set old_comment = o_data.comment|default('', true) %}

View File

@@ -7,23 +7,16 @@
{% endif %} {% endif %}
{% if data.name and data.schema and data.definition %} {% if data.name and data.schema and data.definition %}
CREATE MATERIALIZED VIEW {{ conn|qtIdent(data.schema, data.name) }} CREATE MATERIALIZED VIEW {{ conn|qtIdent(data.schema, data.name) }}
{% if(data.fillfactor or data['autovacuum_enabled'] or data['toast_autovacuum_enabled']) %} {% if(data.fillfactor or data['vacuum_data']|length > 0) %}
WITH ( WITH (
{% if data.fillfactor %} {% if data.fillfactor %}
FILLFACTOR = {{ data.fillfactor }}{% if data['autovacuum_enabled'] or data['toast_autovacuum_enabled'] or data['vacuum_data']|length > 0 %},{{ '\r' }}{% endif %} FILLFACTOR = {{ data.fillfactor }}{% if data['autovacuum_enabled'] or data['toast_autovacuum_enabled'] or data['vacuum_data']|length > 0 %},{{ '\r' }}{% endif %}
{% endif %} {% endif %}
{% if data['autovacuum_enabled'] %}
autovacuum_enabled = {{ data['autovacuum_enabled']|lower }}{% if data['toast_autovacuum_enabled'] or data['vacuum_data']|length > 0 %},{{ '\r' }}{% endif %}
{% endif %}
{% if data['toast_autovacuum_enabled'] %}
{{ 'toast.autovacuum_enabled' }} = {{ data['toast_autovacuum_enabled']|lower }}{% if data['vacuum_data']|length > 0 %},{{ '\r' }}{% endif %}
{% endif %}
{% for field in data['vacuum_data'] %} {% for field in data['vacuum_data'] %}
{% if field.value is defined and field.value != '' and field.value != none %} {% if field.value is defined and field.value != '' and field.value != none %}
{% if loop.index > 1%}, {% if loop.index > 1 %},
{% endif %} {{ field.name }} = {{ field.value|lower }}{% endif %} {% endif %} {{ field.name }} = {{ field.value|lower }}{% endif %}
{% endfor %} {% endfor %}{{ '\r' }}
) )
{% endif %} {% endif %}
{% if data.spcname %}TABLESPACE {{ data.spcname }} {% if data.spcname %}TABLESPACE {{ data.spcname }}
@@ -41,7 +34,7 @@ ALTER TABLE {{ conn|qtIdent(data.schema, data.name) }}
{% endif %} {% endif %}
{% if data.comment %} {% if data.comment %}
COMMENT ON VIEW {{ conn|qtIdent(data.schema, data.name) }} COMMENT ON MATERIALIZED VIEW {{ conn|qtIdent(data.schema, data.name) }}
IS {{ data.comment|qtLiteral }}; IS {{ data.comment|qtLiteral }};
{% endif %} {% endif %}
{% endif %} {% endif %}

View File

@@ -1,6 +1,6 @@
{# ===== fetch schema name =====#} {# ===== fetch schema name =====#}
SELECT SELECT
nspname nspname
FROM FROM
pg_namespace pg_namespace
WHERE WHERE

View File

@@ -22,30 +22,12 @@ ALTER MATERIALIZED VIEW {{ conn|qtIdent(o_data.schema, view_name ) }}
ALTER TABLE {{ conn|qtIdent(view_schema, view_name) }} ALTER TABLE {{ conn|qtIdent(view_schema, view_name) }}
OWNER TO {{ conn|qtIdent(data.owner) }}; OWNER TO {{ conn|qtIdent(data.owner) }};
{% endif %}
{% if data['vacuum_data']['reset']|length == 0 and
data['vacuum_data']['changed']|length == 0 and data['settings']|length > 0 %}
ALTER MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }}
SET(
{% for field in data['settings'] %}
{{ field }} = {{ data['settings'][field]|lower }}{% if not loop.last %},{% endif %}{{ '\r' }}
{% endfor %}
);
{% endif %}
{% if data['vacuum_data']['reset']|length > 0 %}
ALTER MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }}
RESET(
{% for field in data['vacuum_data']['reset'] %}
{{ field.name }}{% if not loop.last %},{% endif %}{{ '\r' }}
{% endfor %}
);
{% endif %} {% endif %}
{# ===== First Drop and then create mat view ===== #} {# ===== First Drop and then create mat view ===== #}
{% if def and def != o_data.definition.rstrip(';') %} {% if def and def != o_data.definition.rstrip(';') %}
{% if data.fillfactor or ( data['vacuum_data']['changed']|length > 0 ) %}
DROP MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }}; DROP MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }};
CREATE MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }} CREATE MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }}
{% if data.fillfactor or (data['vacuum_data']['changed']|length > 0 ) %}
WITH( WITH(
{% if data.fillfactor %} {% if data.fillfactor %}
FILLFACTOR = {{ data.fillfactor }}{% if data['vacuum_data']['changed']|length > 0 %},{% endif %}{{ '\r' }} FILLFACTOR = {{ data.fillfactor }}{% if data['vacuum_data']['changed']|length > 0 %},{% endif %}{{ '\r' }}
@@ -56,15 +38,15 @@ WITH(
{% endfor %} {% endfor %}
{% endif %} {% endif %}
) )
{% endif %}
AS AS
{{ def }} {{ def }}
{% if data.with_data %} {% if data.with_data is defined %}
WITH DATA; WITH {{ 'DATA' if data.with_data else 'NO DATA' }};
{% else %} {% elif o_data.with_data %}
WITH NO DATA; WITH {{ 'DATA' if o_data.with_data else 'NO DATA' }};
{% endif %}
{% endif %} {% endif %}
{% else %} {% else %}
{# ======= Alter Tablespace ========= #} {# ======= Alter Tablespace ========= #}
@@ -76,9 +58,11 @@ ALTER MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }}
{# ======= SET/RESET Fillfactor ========= #} {# ======= SET/RESET Fillfactor ========= #}
{% if data.fillfactor and o_data.fillfactor != data.fillfactor %} {% if data.fillfactor and o_data.fillfactor != data.fillfactor %}
ALTER MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }} ALTER MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }}
SET(FILLFACTOR = {{ data.fillfactor }}); SET(
FILLFACTOR = {{ data.fillfactor }}
);
{% elif data.fillfactor == '' %} {% elif data.fillfactor == '' and o_data.fillfactor|default('', 'true') != data.fillfactor %}
ALTER MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }} ALTER MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }}
RESET( RESET(
FILLFACTOR FILLFACTOR
@@ -94,9 +78,10 @@ REFRESH MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }} WITH{{ ' NO
{% if ((data.autovacuum_custom is defined and data.autovacuum_custom|lower == 'false') or {% if ((data.autovacuum_custom is defined and data.autovacuum_custom|lower == 'false') or
(data.toast_autovacuum is defined and data.toast_autovacuum|lower == 'false') (data.toast_autovacuum is defined and data.toast_autovacuum|lower == 'false')
) %} ) %}
{% if data.autovacuum_custom is defined %} {% if data.autovacuum_custom|lower == 'false' %}
ALTER MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }} ALTER MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }}
RESET( RESET(
autovacuum_enabled,
autovacuum_vacuum_threshold, autovacuum_vacuum_threshold,
autovacuum_analyze_threshold, autovacuum_analyze_threshold,
autovacuum_vacuum_scale_factor, autovacuum_vacuum_scale_factor,
@@ -107,10 +92,25 @@ RESET(
autovacuum_freeze_max_age, autovacuum_freeze_max_age,
autovacuum_freeze_table_age autovacuum_freeze_table_age
); );
{% if data.toast_autovacuum is defined and data.toast_autovacuum|lower != 'false' %}
{% if('vacuum_toast' in data and data['vacuum_toast']['changed']|length > 0) %}
ALTER MATERIALIZED VIEW {{ conn|qtIdent(data.schema, data.name) }} SET(
{% for field in data['vacuum_toast']['changed'] %}
{% if field.value != None %}
{{ field.name }} = {{ field.value|lower }}{% if not loop.last %},{% endif %}{{ '\r' }}
{% endif %} {% endif %}
{% if data.toast_autovacuum is defined %} {% endfor %}
);
{% endif %}
{% endif %}
{% endif %}
{% if data.toast_autovacuum|lower == 'false' %}
ALTER MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }} ALTER MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }}
RESET( RESET(
toast.autovacuum_enabled,
toast.autovacuum_vacuum_threshold, toast.autovacuum_vacuum_threshold,
toast.autovacuum_analyze_threshold, toast.autovacuum_analyze_threshold,
toast.autovacuum_vacuum_scale_factor, toast.autovacuum_vacuum_scale_factor,
@@ -121,19 +121,54 @@ RESET(
toast.autovacuum_freeze_max_age, toast.autovacuum_freeze_max_age,
toast.autovacuum_freeze_table_age toast.autovacuum_freeze_table_age
); );
{% endif %}
{% elif(data['vacuum_data']['changed']|length > 0) %} {% if data.autovacuum_custom is defined and data.autovacuum_custom|lower != 'false' %}
{% if('vacuum_table' in data and data['vacuum_table']['changed']|length > 0) %}
ALTER MATERIALIZED VIEW {{ conn|qtIdent(data.schema, data.name) }} SET( ALTER MATERIALIZED VIEW {{ conn|qtIdent(data.schema, data.name) }} SET(
{% for field in data['vacuum_data']['changed'] %} {% for field in data['vacuum_table']['changed'] %}
{% if field.value != None %} {% if field.value != None %}
{{ field.name }} = {{ field.value|lower }}{% if not loop.last %},{% endif %}{{ '\r' }} {{ field.name }} = {{ field.value|lower }}{% if not loop.last %},{% endif %}{{ '\r' }}
{% endif %} {% endif %}
{% endfor %} {% endfor %}
); );
{% endif %}
{% endif %}
{% endif %}{#-- toast_endif ends --#}
{% else %}
{% if data['vacuum_data']['reset']|length == 0 and
data['vacuum_data']['changed']|length == 0 and data['settings']|length > 0 %}
ALTER MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }}
SET(
{% for field in data['settings'] %}
{{ field }} = {{ data['settings'][field]|lower }}{% if not loop.last %},{% endif %}{{ '\r' }}
{% endfor %}
);
{% endif %}
{% if(data['vacuum_data']['changed']|length > 0) %}
ALTER MATERIALIZED VIEW {{ conn|qtIdent(data.schema, data.name) }}
SET(
{% for field in data['vacuum_data']['changed'] %}
{% if field.value != None %}
{{ field.name }} = {{ field.value|lower }}{% if not loop.last %},{% endif %}{{ '\r' }}
{% endif %}
{% endfor %}
);
{% endif %}
{% if data['vacuum_data']['reset']|length > 0 %}
ALTER MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }}
RESET(
{% for field in data['vacuum_data']['reset'] %}
{{ field.name }}{% if not loop.last %},{% endif %}{{ '\r' }}
{% endfor %}
);
{% endif %}
{% endif %}{# ===== End check for custom autovaccum ===== #} {% endif %}{# ===== End check for custom autovaccum ===== #}
{% endif %}{# ===== End block for check data definition ===== #} {% endif %}{# ===== End block for check data definition ===== #}
{% if data.comment and data.comment != o_data.comment %} {% set old_comment = o_data.comment|default('', true) %}
{% if (data.comment is defined and (data.comment != old_comment)) %}
COMMENT ON MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }} COMMENT ON MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }}
IS {{ data.comment|qtLiteral }}; IS {{ data.comment|qtLiteral }};

View File

@@ -1,4 +1,4 @@
{# ===== Below will provide view id for last created view ==== #} {# ===== Below will provide view id for last created view ==== #}
{% if data %} {% if data %}
SELECT c.oid FROM pg_class c WHERE c.relname = '{{ data.name }}'; SELECT c.oid, c.relname FROM pg_class c WHERE c.relname = '{{ data.name }}';
{% endif %} {% endif %}