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.
pull/3/head
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 %}
{% for field in data['vacuum_data'] %}
{% 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 %}
{% endfor %}
{% endfor %}{{ '\r' }}
)
{% endif %}
{% if data.spcname %}TABLESPACE {{ data.spcname }}
@ -35,7 +34,7 @@ ALTER TABLE {{ conn|qtIdent(data.schema, data.name) }}
{% endif %}
{% 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 }};
{% endif %}
{% endif %}

View File

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

View File

@ -7,23 +7,16 @@
{% endif %}
{% if data.name and data.schema and data.definition %}
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 (
{% if data.fillfactor %}
FILLFACTOR = {{ data.fillfactor }}{% if data['autovacuum_enabled'] or data['toast_autovacuum_enabled'] or data['vacuum_data']|length > 0 %},{{ '\r' }}{% 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'] %}
{% 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 %}
{% endfor %}
{% endfor %}{{ '\r' }}
)
{% endif %}
{% if data.spcname %}TABLESPACE {{ data.spcname }}
@ -41,7 +34,7 @@ ALTER TABLE {{ conn|qtIdent(data.schema, data.name) }}
{% endif %}
{% 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 }};
{% endif %}
{% endif %}

View File

@ -1,6 +1,6 @@
{# ===== fetch schema name =====#}
SELECT
nspname
nspname
FROM
pg_namespace
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) }}
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 %}
{# ===== First Drop and then create mat view ===== #}
{% 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) }};
CREATE MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }}
{% if data.fillfactor or (data['vacuum_data']['changed']|length > 0 ) %}
WITH(
{% if data.fillfactor %}
FILLFACTOR = {{ data.fillfactor }}{% if data['vacuum_data']['changed']|length > 0 %},{% endif %}{{ '\r' }}
@ -56,15 +38,15 @@ WITH(
{% endfor %}
{% endif %}
)
{% endif %}
AS
{{ def }}
{% if data.with_data %}
WITH DATA;
{% if data.with_data is defined %}
WITH {{ 'DATA' if data.with_data else 'NO DATA' }};
{% else %}
WITH NO DATA;
{% elif o_data.with_data %}
WITH {{ 'DATA' if o_data.with_data else 'NO DATA' }};
{% endif %}
{% endif %}
{% else %}
{# ======= Alter Tablespace ========= #}
@ -76,9 +58,11 @@ ALTER MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }}
{# ======= SET/RESET Fillfactor ========= #}
{% if data.fillfactor and o_data.fillfactor != data.fillfactor %}
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) }}
RESET(
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
(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) }}
RESET(
autovacuum_enabled,
autovacuum_vacuum_threshold,
autovacuum_analyze_threshold,
autovacuum_vacuum_scale_factor,
@ -107,10 +92,25 @@ RESET(
autovacuum_freeze_max_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 %}
{% 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) }}
RESET(
toast.autovacuum_enabled,
toast.autovacuum_vacuum_threshold,
toast.autovacuum_analyze_threshold,
toast.autovacuum_vacuum_scale_factor,
@ -121,19 +121,54 @@ RESET(
toast.autovacuum_freeze_max_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(
{% for field in data['vacuum_data']['changed'] %}
{% for field in data['vacuum_table']['changed'] %}
{% if field.value != None %}
{{ field.name }} = {{ field.value|lower }}{% if not loop.last %},{% endif %}{{ '\r' }}
{% endif %}
{% 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 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) }}
IS {{ data.comment|qtLiteral }};

View File

@ -1,4 +1,4 @@
{# ===== Below will provide view id for last created view ==== #}
{% 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 %}