Added missing comments in reverse engineering SQL for each column of a View. Fixes #3791

This commit is contained in:
Rahul Shirsat 2020-08-11 11:30:47 +05:30 committed by Akshay Joshi
parent 46af290b85
commit 2907a79dd7
4 changed files with 23 additions and 8 deletions

View File

@ -25,6 +25,7 @@ Bug fixes
********* *********
| `Issue #3767 <https://redmine.postgresql.org/issues/3767>`_ - Ensure that the original file format should be retained when saving the same file in SQL editor. | `Issue #3767 <https://redmine.postgresql.org/issues/3767>`_ - Ensure that the original file format should be retained when saving the same file in SQL editor.
| `Issue #3791 <https://redmine.postgresql.org/issues/3791>`_ - Added missing comments in reverse engineering SQL for each column of a View.
| `Issue #4361 <https://redmine.postgresql.org/issues/4361>`_ - Fixed ssh tunnel hang issue when the user tries to disconnect the server. | `Issue #4361 <https://redmine.postgresql.org/issues/4361>`_ - Fixed ssh tunnel hang issue when the user tries to disconnect the server.
| `Issue #4387 <https://redmine.postgresql.org/issues/4387>`_ - Fixed an issue where the user is not able to insert the data if the table and columns name contains special characters. | `Issue #4387 <https://redmine.postgresql.org/issues/4387>`_ - Fixed an issue where the user is not able to insert the data if the table and columns name contains special characters.
| `Issue #4810 <https://redmine.postgresql.org/issues/4810>`_ - Fixed an issue where the user is not able to save the new row if the table is empty. | `Issue #4810 <https://redmine.postgresql.org/issues/4810>`_ - Fixed an issue where the user is not able to save the new row if the table is empty.

View File

@ -1331,6 +1331,7 @@ class ViewNode(PGChildNodeView, VacuumSettings, SchemaDiffObjectCompare):
'attlen': rows['attlen'], 'attlen': rows['attlen'],
'typnspname': rows['typnspname'], 'typnspname': rows['typnspname'],
'defval': None, 'defval': None,
'description': None,
'table': rows['relname'], 'table': rows['relname'],
'schema': self.view_schema 'schema': self.view_schema
} }
@ -1341,8 +1342,12 @@ class ViewNode(PGChildNodeView, VacuumSettings, SchemaDiffObjectCompare):
if 'defval' in rows and rows['defval'] is not None: if 'defval' in rows and rows['defval'] is not None:
res['defval'] = rows['defval'] res['defval'] = rows['defval']
o_data['defval'] = None o_data['defval'] = None
else:
continue # Generate alter statement for comments
if 'description' in rows and (rows['description'] is not None or
rows['description'] != ''):
res['description'] = rows['description']
o_data['description'] = None
SQL = render_template("/".join( SQL = render_template("/".join(
[self.column_template_path, [self.column_template_path,

View File

@ -44,7 +44,7 @@ ALTER TABLE {{ conn|qtIdent(view_schema, view_name) }}
COMMENT ON VIEW {{ conn|qtIdent(view_schema, view_name) }} COMMENT ON VIEW {{ conn|qtIdent(view_schema, view_name) }}
IS {{ data.comment|qtLiteral }}; IS {{ data.comment|qtLiteral }};
{% elif data.del_sql == True %} {% elif data.del_sql == True and old_comment != '' %}
COMMENT ON VIEW {{ conn|qtIdent(view_schema, view_name) }} COMMENT ON VIEW {{ conn|qtIdent(view_schema, view_name) }}
IS {{ old_comment|qtLiteral }}; IS {{ old_comment|qtLiteral }};
{% endif %} {% endif %}

View File

@ -13,14 +13,13 @@ ALTER VIEW {{ conn|qtIdent(o_data.schema, o_data.name) }}
ALTER VIEW {{ conn|qtIdent(o_data.schema, view_name ) }} ALTER VIEW {{ conn|qtIdent(o_data.schema, view_name ) }}
SET SCHEMA {{ conn|qtIdent(data.schema) }}; SET SCHEMA {{ conn|qtIdent(data.schema) }};
{% endif %} {% endif %}
{% if data.owner and data.owner != o_data.owner %}
ALTER TABLE {{ conn|qtIdent(view_schema, view_name) }}
OWNER TO {{ conn|qtIdent(data.owner) }};
{% endif %}
{% if def and def != o_data.definition.rstrip(';') %} {% if def and def != o_data.definition.rstrip(';') %}
{% if data.del_sql %}
DROP VIEW {{ conn|qtIdent(view_schema, view_name) }};
{% endif %}
CREATE OR REPLACE VIEW {{ conn|qtIdent(view_schema, view_name) }} CREATE OR REPLACE VIEW {{ conn|qtIdent(view_schema, view_name) }}
{% if ((data.check_option and data.check_option.lower() != 'no') or data.security_barrier) %} {% if ((data.check_option and data.check_option.lower() != 'no') or data.security_barrier) %}
WITH ({% if (data.check_option or o_data.check_option) %}check_option={{ data.check_option if data.check_option else o_data.check_option }}{{', ' }}{% endif %}security_barrier={{ data.security_barrier|lower if data.security_barrier else o_data.security_barrier|default('false', 'true')|lower }}) WITH ({% if (data.check_option or o_data.check_option) %}check_option={{ data.check_option if data.check_option else o_data.check_option }}{{', ' }}{% endif %}security_barrier={{ data.security_barrier|lower if data.security_barrier is defined else o_data.security_barrier|default('false', 'true')|lower }})
{% endif %} {% endif %}
AS AS
{{ def }}; {{ def }};
@ -36,13 +35,23 @@ ALTER VIEW {{ conn|qtIdent(view_schema, view_name) }}
ALTER VIEW {{ conn|qtIdent(view_schema, view_name) }} RESET (check_option); ALTER VIEW {{ conn|qtIdent(view_schema, view_name) }} RESET (check_option);
{% endif %} {% endif %}
{% endif %} {% endif %}
{% if data.owner and data.owner != o_data.owner %}
ALTER TABLE {{ conn|qtIdent(view_schema, view_name) }}
OWNER TO {{ conn|qtIdent(data.owner) }};
{% endif %}
{% set old_comment = o_data.comment|default('', true) %} {% set old_comment = o_data.comment|default('', true) %}
{% if (data.comment is defined and (data.comment != old_comment)) %} {% if (data.comment is defined and (data.comment != old_comment)) %}
COMMENT ON VIEW {{ conn|qtIdent(view_schema, view_name) }} COMMENT ON VIEW {{ conn|qtIdent(view_schema, view_name) }}
IS {{ data.comment|qtLiteral }}; IS {{ data.comment|qtLiteral }};
{% elif data.del_sql == True and old_comment != '' %}
COMMENT ON VIEW {{ conn|qtIdent(view_schema, view_name) }}
IS {{ old_comment|qtLiteral }};
{% endif %} {% endif %}
{# The SQL generated below will change privileges #} {# The SQL generated below will change privileges #}
{% if o_data.acl_sql and o_data.acl_sql != '' %}
{{o_data['acl_sql']}}
{% endif %}
{% 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 %}