Fixed an issue where changing the columns in the existing view throws an error. Fixes #5053
PostgreSQL doesn't allow to change the view columns. So the view should be dropped first and then recreate it and also the user will get a warning first.pull/29/head
parent
03f4109ac4
commit
f4607885e1
|
@ -27,6 +27,7 @@ Bug fixes
|
|||
| `Issue #4206 <https://redmine.postgresql.org/issues/4206>`_ - Ensure that the grant wizard should be closed on pressing the ESC key.
|
||||
| `Issue #4512 <https://redmine.postgresql.org/issues/4512>`_ - Fixed calendar opening issue on the exception tab inside the schedules tab of pgAgent.
|
||||
| `Issue #4856 <https://redmine.postgresql.org/issues/4856>`_ - Enable the save button by default when a query tool is opened with CREATE or other scripts.
|
||||
| `Issue #5053 <https://redmine.postgresql.org/issues/5053>`_ - Fixed an issue where changing the columns in the existing view throws an error.
|
||||
| `Issue #5180 <https://redmine.postgresql.org/issues/5180>`_ - Fixed an issue where the autovacuum_enabled parameter is added automatically in the RE-SQL when the table has been created using the WITH clause.
|
||||
| `Issue #5268 <https://redmine.postgresql.org/issues/5268>`_ - Fixed generated SQL when any token in FTS Configuration or any option in FTS Dictionary is changed.
|
||||
| `Issue #5275 <https://redmine.postgresql.org/issues/5275>`_ - Fixed tab key navigation issue for parameters in table dialog.
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
"""Implements View and Materialized View Node"""
|
||||
|
||||
import copy
|
||||
import re
|
||||
from functools import wraps
|
||||
|
||||
import simplejson as json
|
||||
|
@ -496,7 +497,7 @@ class ViewNode(PGChildNodeView, VacuumSettings, SchemaDiffObjectCompare):
|
|||
)
|
||||
)
|
||||
try:
|
||||
SQL, nameOrError = self.getSQL(gid, sid, did, data)
|
||||
SQL, nameOrError = self.getSQL(gid, sid, did, scid, data)
|
||||
if SQL is None:
|
||||
return nameOrError
|
||||
SQL = SQL.strip('\n').strip(' ')
|
||||
|
@ -541,7 +542,7 @@ class ViewNode(PGChildNodeView, VacuumSettings, SchemaDiffObjectCompare):
|
|||
request.data, encoding='utf-8'
|
||||
)
|
||||
try:
|
||||
SQL, name = self.getSQL(gid, sid, did, data, vid)
|
||||
SQL, name = self.getSQL(gid, sid, did, scid, data, vid)
|
||||
if SQL is None:
|
||||
return name
|
||||
SQL = SQL.strip('\n').strip(' ')
|
||||
|
@ -678,7 +679,7 @@ class ViewNode(PGChildNodeView, VacuumSettings, SchemaDiffObjectCompare):
|
|||
except ValueError:
|
||||
data[k] = v
|
||||
|
||||
sql, nameOrError = self.getSQL(gid, sid, did, data, vid)
|
||||
sql, nameOrError = self.getSQL(gid, sid, did, scid, data, vid)
|
||||
if sql is None:
|
||||
return nameOrError
|
||||
|
||||
|
@ -692,7 +693,7 @@ class ViewNode(PGChildNodeView, VacuumSettings, SchemaDiffObjectCompare):
|
|||
status=200
|
||||
)
|
||||
|
||||
def getSQL(self, gid, sid, did, data, vid=None):
|
||||
def getSQL(self, gid, sid, did, scid, data, vid=None):
|
||||
"""
|
||||
This function will generate sql from model data
|
||||
"""
|
||||
|
@ -716,7 +717,22 @@ class ViewNode(PGChildNodeView, VacuumSettings, SchemaDiffObjectCompare):
|
|||
if 'schema' not in data:
|
||||
data['schema'] = res['rows'][0]['schema']
|
||||
|
||||
acls = []
|
||||
DEL_SQL = None
|
||||
if 'definition' in data:
|
||||
new_def = re.sub(r"\W", "", data['definition']).split('FROM')
|
||||
old_def = re.sub(r"\W", "", res['rows'][0]['definition']
|
||||
).split('FROM')
|
||||
if 'definition' in data and (
|
||||
len(old_def) > 1 or len(new_def) > 1
|
||||
) and(
|
||||
old_def[0] != new_def[0] and
|
||||
old_def[0] not in new_def[0]
|
||||
):
|
||||
DEL_SQL = self.delete(gid=gid, sid=sid, did=did,
|
||||
scid=scid,
|
||||
vid=vid, only_sql=True
|
||||
)
|
||||
|
||||
try:
|
||||
acls = render_template(
|
||||
"/".join([self.template_path, 'sql/allowed_privs.json'])
|
||||
|
@ -740,6 +756,9 @@ class ViewNode(PGChildNodeView, VacuumSettings, SchemaDiffObjectCompare):
|
|||
SQL = render_template("/".join(
|
||||
[self.template_path, 'sql/update.sql']), data=data,
|
||||
o_data=old_data, conn=self.conn)
|
||||
|
||||
if DEL_SQL:
|
||||
SQL = DEL_SQL + SQL
|
||||
except Exception as e:
|
||||
current_app.logger.exception(e)
|
||||
return None, internal_server_error(errormsg=str(e))
|
||||
|
@ -1439,7 +1458,14 @@ class ViewNode(PGChildNodeView, VacuumSettings, SchemaDiffObjectCompare):
|
|||
if data:
|
||||
if diff_schema:
|
||||
data['schema'] = diff_schema
|
||||
sql, nameOrError = self.getSQL(gid, sid, did, data, oid)
|
||||
sql, nameOrError = self.getSQL(gid, sid, did, scid, data, oid)
|
||||
if sql.find('DROP VIEW') != -1:
|
||||
sql = gettext("""
|
||||
-- Changing the columns in a view requires dropping and re-creating the view.
|
||||
-- This may fail if other objects are dependent upon this view,
|
||||
-- or may cause procedural functions to fail if they are not modified to
|
||||
-- take account of the changes.
|
||||
""") + sql
|
||||
else:
|
||||
if drop_sql:
|
||||
sql = self.delete(gid=gid, sid=sid, did=did,
|
||||
|
@ -1547,8 +1573,8 @@ class MViewNode(ViewNode, VacuumSettings):
|
|||
data['vacuum_data']['reset'] = []
|
||||
|
||||
# table vacuum: separate list of changed and reset data for
|
||||
if ('vacuum_table' in data):
|
||||
if ('changed' in data['vacuum_table']):
|
||||
if 'vacuum_table' in data:
|
||||
if 'changed' in data['vacuum_table']:
|
||||
for item in data['vacuum_table']['changed']:
|
||||
if 'value' in item.keys():
|
||||
if item['value'] is None:
|
||||
|
@ -1581,8 +1607,8 @@ class MViewNode(ViewNode, VacuumSettings):
|
|||
'value': data['autovacuum_enabled']})
|
||||
|
||||
# toast autovacuum: separate list of changed and reset data
|
||||
if ('vacuum_toast' in data):
|
||||
if ('changed' in data['vacuum_toast']):
|
||||
if 'vacuum_toast' in data:
|
||||
if 'changed' in data['vacuum_toast']:
|
||||
for item in data['vacuum_toast']['changed']:
|
||||
if 'value' in item.keys():
|
||||
toast_key = 'toast_' + item['name']
|
||||
|
@ -1671,14 +1697,14 @@ class MViewNode(ViewNode, VacuumSettings):
|
|||
if 'value' in item.keys() and item['value'] is not None]
|
||||
|
||||
# add table_enabled & toast_enabled settings
|
||||
if ('autovacuum_custom' in data and data['autovacuum_custom']):
|
||||
if 'autovacuum_custom' in data and data['autovacuum_custom']:
|
||||
vacuum_table.append(
|
||||
{
|
||||
'name': 'autovacuum_enabled',
|
||||
'value': str(data['autovacuum_enabled'])
|
||||
}
|
||||
)
|
||||
if ('toast_autovacuum' in data and data['toast_autovacuum']):
|
||||
if 'toast_autovacuum' in data and data['toast_autovacuum']:
|
||||
vacuum_table.append(
|
||||
{
|
||||
'name': 'toast.autovacuum_enabled',
|
||||
|
|
|
@ -154,8 +154,33 @@ define('pgadmin.node.view', [
|
|||
id: 'definition', label: gettext('Code'), cell: 'string',
|
||||
type: 'text', mode: ['create', 'edit'], group: gettext('Code'),
|
||||
tabPanelCodeClass: 'sql-code-control',
|
||||
control: Backform.SqlCodeControl,
|
||||
disabled: 'notInSchema',
|
||||
control: Backform.SqlCodeControl.extend({
|
||||
onChange: function() {
|
||||
Backform.SqlCodeControl.prototype.onChange.apply(this, arguments);
|
||||
if(this.model && this.model.changed) {
|
||||
if(this.model.origSessAttrs && (this.model.changed.definition != this.model.origSessAttrs.definition)) {
|
||||
let old_def = this.model.origSessAttrs.definition.replace(/\s/gi, '').split('FROM'),
|
||||
new_def = [];
|
||||
|
||||
if(this.model.changed.definition !== undefined) {
|
||||
new_def = this.model.changed.definition.replace(/\s/gi, '').split('FROM');
|
||||
}
|
||||
if ((old_def.length > 1 || new_def.length > 1) && old_def[0] != new_def[0] && !new_def[0].includes(old_def[0])) {
|
||||
this.model.warn_text = gettext('Changing the columns in a view requires dropping and re-creating the view. This may fail if other objects are dependent upon this view, or may cause procedural functions to fail if they are not modified to take account of the changes. Do you wish to continue?');
|
||||
} else {
|
||||
this.model.warn_text = undefined;
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.model.warn_text = undefined;
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.model.warn_text = undefined;
|
||||
}
|
||||
},
|
||||
}),
|
||||
}, pgBrowser.SecurityGroupSchema, {
|
||||
// Add Privilege Control
|
||||
id: 'datacl', label: gettext('Privileges'), type: 'collection',
|
||||
|
|
Loading…
Reference in New Issue