Hi, PFA patch for RM1500.
Changes/Issues fixed: 1] datamodel.js: For collection type added check before adding model into "changed" list instead of adding it blindly. 2] Type casting from str to int of column properties like attlen, attpricision. 3] Added missing data formating when adding new column to existing table (from table edit mode). 4] Added more validation for Foreign key constraint. 5] Column.js: Column grid (in table edit mode) show proper disabled color for disabled cell when grid renders. 6] All constraints and index js added idattribute to distinguish which s/constraint or s/index is updated on server side. 7] Column update.sql: Fixed sql when altering column data type. The issue was when we alter data type from which has length and precision to data type which don't have these properties and vice versa. For e.g. alter data type numeric(10,12) to real (and vice versa) 8] Renaming constraint (RM1500). -- *Harshal Dhumal* *Software Engineer* EnterpriseDB India: http://www.enterprisedb.com The Enterprise PostgreSQL Company
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/__init__.py index 02057bf..ece103f 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/__init__.py @@ -187,9 +187,9 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings): - It will return formatted output of query result as per client model format for index constraint node - * _cltype_formatter(self, type): + * _cltype_formatter(type): (staticmethod) - We need to remove [] from type and append it - after length/precision so we will set flag for + after length/precision so we will send flag for sql template * _parse_format_columns(self, data, mode=None): @@ -627,17 +627,16 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings): column['isdup'], column['attndims'], column['atttypmod'] ) - import re # If we have length & precision both matchObj = re.search(r'(\d+),(\d+)', fulltype) if matchObj: - column['attlen'] = matchObj.group(1) - column['attprecision'] = matchObj.group(2) + column['attlen'] = int(matchObj.group(1)) + column['attprecision'] = int(matchObj.group(2)) else: # If we have length only matchObj = re.search(r'(\d+)', fulltype) if matchObj: - column['attlen'] = matchObj.group(1) + column['attlen'] = int(matchObj.group(1)) column['attprecision'] = None else: column['attlen'] = None @@ -1045,7 +1044,6 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings): # Filter inherited columns from all columns if 'columns' in data and len(data['columns']) > 0 \ and len(all_columns) > 0: - columns = [] for row in data['columns']: for i, col in enumerate(all_columns): # If both name are same then remove it @@ -1271,24 +1269,22 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings): except Exception as e: return internal_server_error(errormsg=str(e)) - def _cltype_formatter(self, type): + @staticmethod + def _cltype_formatter(data_type): """ Args: - data: Type string + data_type: Type string Returns: We need to remove [] from type and append it - after length/precision so we will set flag for + after length/precision so we will send flag for sql template """ - if '[]' in type: - type = type.replace('[]', '') - self.hasSqrBracket = True + if '[]' in data_type: + return data_type[:-2], True else: - self.hasSqrBracket = False - - return type + return data_type, False def _parse_format_columns(self, data, mode=None): """ @@ -1313,9 +1309,9 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings): if 'attacl' in c: c['attacl'] = parse_priv_to_db(c['attacl'], self.column_acl) - # check type for '[]' in it - c['cltype'] = self._cltype_formatter(c['cltype']) - c['hasSqrBracket'] = self.hasSqrBracket + if 'cltype' in c: + # check type for '[]' in it + c['cltype'], c['hasSqrBracket'] = self._cltype_formatter(c['cltype']) data['columns'][action] = final_columns else: @@ -1333,9 +1329,9 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings): if 'attacl' in c: c['attacl'] = parse_priv_to_db(c['attacl'], self.column_acl) - # check type for '[]' in it - c['cltype'] = self._cltype_formatter(c['cltype']) - c['hasSqrBracket'] = self.hasSqrBracket + if 'cltype' in c: + # check type for '[]' in it + c['cltype'], c['hasSqrBracket'] = self._cltype_formatter(c['cltype']) data['columns'] = final_columns @@ -1843,19 +1839,20 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings): ) return '\n\n'.join(sql) - cols = [] - for col in c['columns']: - cols.append(col['local_column']) + if 'columns' in c: + cols = [] + for col in c['columns']: + cols.append(col['local_column']) - coveringindex = self.search_coveringindex(tid, cols) + coveringindex = self.search_coveringindex(tid, cols) - if coveringindex is None and 'autoindex' in c and c['autoindex'] and \ - ('coveringindex' in c and - c['coveringindex'] != ''): - sql.append(render_template( - "/".join([self.foreign_key_template_path, 'create_index.sql']), - data=c, conn=self.conn).strip('\n') - ) + if coveringindex is None and 'autoindex' in c and c['autoindex'] and \ + ('coveringindex' in c and + c['coveringindex'] != ''): + sql.append(render_template( + "/".join([self.foreign_key_template_path, 'create_index.sql']), + data=c, conn=self.conn).strip('\n') + ) if 'added' in constraint: for c in constraint['added']: @@ -2163,9 +2160,46 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings): return internal_server_error(errormsg=res) old_data = res['rows'][0] - old_data['cltype'] = self._cltype_formatter(old_data['cltype']) - old_data['hasSqrBracket'] = self.hasSqrBracket + old_data['cltype'], old_data['hasSqrBracket'] = self._cltype_formatter(old_data['cltype']) + + fulltype = self.get_full_type( + old_data['typnspname'], old_data['typname'], + old_data['isdup'], old_data['attndims'], old_data['atttypmod'] + ) + # If we have length & precision both + matchObj = re.search(r'(\d+),(\d+)', fulltype) + if matchObj: + old_data['attlen'] = int(matchObj.group(1)) + old_data['attprecision'] = int(matchObj.group(2)) + else: + # If we have length only + matchObj = re.search(r'(\d+)', fulltype) + if matchObj: + old_data['attlen'] = int(matchObj.group(1)) + old_data['attprecision'] = None + else: + old_data['attlen'] = None + old_data['attprecision'] = None + + # Manual Data type formatting + # If data type has () with them then we need to remove them + # eg bit(1) because we need to match the name with combobox + isArray = False + if old_data['cltype'].endswith('[]'): + isArray = True + old_data['cltype'] = old_data['cltype'].rstrip('[]') + + idx = old_data['cltype'].find('(') + if idx and old_data['cltype'].endswith(')'): + old_data['cltype'] = old_data['cltype'][:idx] + + if isArray: + old_data['cltype'] += "[]" + + if old_data['typnspname'] != 'pg_catalog': + old_data['cltype'] = self.qtIdent(self.conn, old_data['typnspname']) \ + + '.' + old_data['cltype'] # Sql for alter column if 'inheritedfrom' not in c: column_sql += render_template("/".join( @@ -2259,7 +2293,8 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings): return SQL - def validate_constrains(self, key, data): + @staticmethod + def validate_constrains(key, data): if key == 'primary_key' or key == 'unique_constraint': if 'columns' in data and len(data['columns']) > 0: @@ -2267,15 +2302,17 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings): else: return False elif key == 'foreign_key': - for arg in ['columns']: - if arg not in data: + if 'oid' not in data: + for arg in ['columns']: + if arg not in data: + return False + elif isinstance(data[arg], list) and len(data[arg]) < 1: + return False + + if 'autoindex' in data and data['autoindex'] and \ + ('coveringindex' not in data or + data['coveringindex'] == ''): return False - elif isinstance(data[arg], list) and len(data[arg]) < 1: - return False - - if data['autoindex'] and ('coveringindex' not in data or - data['coveringindex'] == ''): - return False return True @@ -2406,8 +2443,8 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings): c['attacl'] = parse_priv_to_db(c['attacl'], self.column_acl) # check type for '[]' in it - c['cltype'] = self._cltype_formatter(c['cltype']) - c['hasSqrBracket'] = self.hasSqrBracket + if 'cltype' in c: + c['cltype'], c['hasSqrBracket'] = self._cltype_formatter(c['cltype']) sql_header = u"-- Table: {0}\n\n-- ".format(self.qtIdent(self.conn, data['schema'], diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/column/templates/column/js/column.js b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/column/templates/column/js/column.js index d7fe5a4..072adaf 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/column/templates/column/js/column.js +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/column/templates/column/js/column.js @@ -57,17 +57,29 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) { }, dependentChanged: function () { this.$el.empty(); - var model = this.model; - var column = this.column; - editable = this.column.get("editable"); + var model = this.model, + column = this.column, + editable = this.column.get("editable"), + is_editable = _.isFunction(editable) ? !!editable.apply(column, [model]) : !!editable; - is_editable = _.isFunction(editable) ? !!editable.apply(column, [model]) : !!editable; if (is_editable){ this.$el.addClass("editable"); } else { this.$el.removeClass("editable"); } this.delegateEvents(); return this; }, + render: function() { + Backgrid.NumberCell.prototype.render.apply(this, arguments); + + var model = this.model, + column = this.column, + editable = this.column.get("editable"), + is_editable = _.isFunction(editable) ? !!editable.apply(column, [model]) : !!editable; + + if (is_editable){ this.$el.addClass("editable"); } + else { this.$el.removeClass("editable"); } + return this; + }, remove: Backgrid.Extension.DependentCell.prototype.remove }); @@ -140,6 +152,8 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) { ]); }, model: pgBrowser.Node.Model.extend({ + idAttribute: 'attnum', + defaults: { name: undefined, attowner: undefined, @@ -156,7 +170,9 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) { is_primary_key: false, inheritedfrom: undefined, attstattarget:undefined, - attnotnull: false + attnotnull: false, + attlen: null, + attprecision: null }, schema: [{ id: 'name', label: '{{ _('Name') }}', cell: 'string', @@ -322,16 +338,21 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) { if(!_.isUndefined(m.get('inheritedfrom'))) { return false; } + + if (!m.datatypes) { + // datatypes not loaded, may be this call is from CallByNeed from backgrid cell initialize. + return true; + } var of_type = m.get('cltype'), flag = false; - _.each(m.datatypes, function(o) { - if ( of_type == o.value ) { - if(o.length) - { - m.set('min_val', o.min_val, {silent: true}); - m.set('max_val', o.max_val, {silent: true}); - flag = true; - } + + _.each(m.datatypes, function(o) { + if ( of_type == o.value ) { + if(o.length) { + m.set('min_val', o.min_val, {silent: true}); + m.set('max_val', o.max_val, {silent: true}); + flag = true; + } } }); @@ -351,12 +372,11 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) { flag = true; _.each(m.datatypes, function(o) { if ( of_type == o.value ) { - if(o.precision) - { - m.set('min_val', o.min_val, {silent: true}); - m.set('max_val', o.max_val, {silent: true}); - flag = false; - } + if(o.precision) { + m.set('min_val', o.min_val, {silent: true}); + m.set('max_val', o.max_val, {silent: true}); + flag = false; + } } }); @@ -373,16 +393,20 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) { return false; } + if (!m.datatypes) { + // datatypes not loaded yet, may be this call is from CallByNeed from backgrid cell initialize. + return true; + } + var of_type = m.get('cltype'), flag = false; _.each(m.datatypes, function(o) { if ( of_type == o.value ) { - if(o.precision) - { - m.set('min_val', o.min_val, {silent: true}); - m.set('max_val', o.max_val, {silent: true}); - flag = true; - } + if(o.precision) { + m.set('min_val', o.min_val, {silent: true}); + m.set('max_val', o.max_val, {silent: true}); + flag = true; + } } }); @@ -401,22 +425,22 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) { deps: ['cltype'], disabled: function(m) { var of_type = m.get('cltype'), flag = true; - _.each(m.datatypes, function(o) { + _.each(m.datatypes, function(o) { if ( of_type == o.value ) { if(o.is_collatable) { flag = false; } } - }); - if (flag) { + }); + if (flag) { setTimeout(function(){ if(m.get('collspcname') && m.get('collspcname') !== '') { m.set('collspcname', ""); } }, 10); - } - return flag; + } + return flag; } },{ id: 'defval', label:'{{ _('Default Value') }}', cell: 'string', diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/check_constraint/templates/check_constraint/js/check_constraint.js b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/check_constraint/templates/check_constraint/js/check_constraint.js index cb33a1a..9389bc9 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/check_constraint/templates/check_constraint/js/check_constraint.js +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/check_constraint/templates/check_constraint/js/check_constraint.js @@ -90,6 +90,8 @@ function($, _, S, pgAdmin, pgBrowser, Alertify) { }, canDrop: pgBrowser.Nodes['schema'].canChildDrop, model: pgAdmin.Browser.Node.Model.extend({ + idAttribute: 'oid', + defaults: { name: undefined, oid: undefined, diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/exclusion_constraint/templates/exclusion_constraint/js/exclusion_constraint.js b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/exclusion_constraint/templates/exclusion_constraint/js/exclusion_constraint.js index 9232677..abdd623 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/exclusion_constraint/templates/exclusion_constraint/js/exclusion_constraint.js +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/exclusion_constraint/templates/exclusion_constraint/js/exclusion_constraint.js @@ -639,6 +639,8 @@ function($, _, S, pgAdmin, pgBrowser, Alertify) { }, // Define the model for exclusion constraint node model: pgAdmin.Browser.Node.Model.extend({ + idAttribute: 'oid', + defaults: { name: undefined, oid: undefined, diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/foreign_key/templates/foreign_key/js/foreign_key.js b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/foreign_key/templates/foreign_key/js/foreign_key.js index cae2efa..9da61f9 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/foreign_key/templates/foreign_key/js/foreign_key.js +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/foreign_key/templates/foreign_key/js/foreign_key.js @@ -672,6 +672,8 @@ function($, _, S, pgAdmin, pgBrowser, Alertify) { }, // Define the model for foreign key node model: pgAdmin.Browser.Node.Model.extend({ + idAttribute: 'oid', + defaults: { name: undefined, oid: undefined, diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/index_constraint/templates/index_constraint/js/index_constraint.js b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/index_constraint/templates/index_constraint/js/index_constraint.js index 73a563b..7db68d5 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/index_constraint/templates/index_constraint/js/index_constraint.js +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/index_constraint/templates/index_constraint/js/index_constraint.js @@ -79,6 +79,8 @@ function($, _, S, pgAdmin, pgBrowser, alertify) { // Define the model for index constraint node model: pgAdmin.Browser.Node.Model.extend({ + idAttribute: 'oid', + defaults: { name: undefined, oid: undefined, diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/templates/index/js/index.js b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/templates/index/js/index.js index 3283582..8ff8359 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/templates/index/js/index.js +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/templates/index/js/index.js @@ -238,8 +238,11 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) { canDrop: pgBrowser.Nodes['schema'].canChildDrop, canDropCascade: pgBrowser.Nodes['schema'].canChildDrop, model: pgAdmin.Browser.Node.Model.extend({ + idAttribute: 'oid', + defaults: { name: undefined, + oid: undefined, nspname: undefined, tabname: undefined, spcname: 'pg_default', diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/column/sql/9.1_plus/update.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/column/sql/9.1_plus/update.sql index 2b1d5b9..454f964 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/column/sql/9.1_plus/update.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/column/sql/9.1_plus/update.sql @@ -2,7 +2,7 @@ {% import 'column/macros/privilege.macros' as PRIVILEGE %} {% import 'macros/variable.macros' as VARIABLE %} {### Rename column name ###} -{% if data.name != o_data.name %} +{% if data.name and data.name != o_data.name %} ALTER TABLE {{conn|qtIdent(data.schema, data.table)}} RENAME {{conn|qtIdent(o_data.name)}} TO {{conn|qtIdent(data.name)}}; @@ -10,8 +10,8 @@ ALTER TABLE {{conn|qtIdent(data.schema, data.table)}} {### Alter column type and collation ###} {% if (data.cltype and data.cltype != o_data.cltype) or (data.attlen and data.attlen != o_data.attlen) or (data.attprecision and data.attprecision != o_data.attprecision) %} ALTER TABLE {{conn|qtIdent(data.schema, data.table)}} - ALTER COLUMN {{conn|qtIdent(data.name)}} TYPE {% if data.cltype %}{{conn|qtTypeIdent(data.cltype)}} {% else %}{{o_data.cltype}} {% endif %}{% if data.attlen %} -({{data.attlen}}{% if data.attprecision%}, {{data.attprecision}}{% endif %}){% endif %}{% if data.hasSqrBracket %} + ALTER COLUMN {% if data.name %}{{conn|qtTypeIdent(data.name)}}{% else %}{{conn|qtTypeIdent(o_data.name)}}{% endif %} TYPE {% if data.cltype %}{{conn|qtTypeIdent(data.cltype)}} {% else %}{{conn|qtTypeIdent(o_data.cltype)}} {% endif %} +{% if data.attlen %}({{data.attlen}}{% elif not data.cltype %}({{o_data.attlen}}{% endif %}{% if data.attprecision%}, {{data.attprecision}}){% elif not data.cltype %}, {{o_data.attprecision}}){% elif data.attlen %}){% endif %}{% if data.hasSqrBracket %} []{% endif %}{% if data.collspcname and data.collspcname != o_data.collspcname %} COLLATE {{data.collspcname}}{% endif %}; @@ -19,31 +19,35 @@ ALTER TABLE {{conn|qtIdent(data.schema, data.table)}} {### Alter column default value ###} {% if data.defval and data.defval != o_data.defval %} ALTER TABLE {{conn|qtIdent(data.schema, data.table)}} - ALTER COLUMN {{conn|qtIdent(data.name)}} SET DEFAULT {{data.defval}}; + ALTER COLUMN {% if data.name %}{{conn|qtTypeIdent(data.name)}}{% else %}{{conn|qtTypeIdent(o_data.name)}}{% endif %} SET DEFAULT {{data.defval}}; {% endif %} {### Alter column not null value ###} {% if 'attnotnull' in data and data.attnotnull != o_data.attnotnull %} ALTER TABLE {{conn|qtIdent(data.schema, data.table)}} - ALTER COLUMN {{conn|qtIdent(data.name)}} {% if data.attnotnull %}SET{% else %}DROP{% endif %} NOT NULL; + ALTER COLUMN {% if data.name %}{{conn|qtTypeIdent(data.name)}}{% else %}{{conn|qtTypeIdent(o_data.name)}}{% endif %} {% if data.attnotnull %}SET{% else %}DROP{% endif %} NOT NULL; {% endif %} {### Alter column statistics value ###} {% if data.attstattarget and data.attstattarget != o_data.attstattarget %} ALTER TABLE {{conn|qtIdent(data.schema, data.table)}} - ALTER COLUMN {{conn|qtIdent(data.name)}} SET STATISTICS {{data.attstattarget}}; + ALTER COLUMN {% if data.name %}{{conn|qtTypeIdent(data.name)}}{% else %}{{conn|qtTypeIdent(o_data.name)}}{% endif %} SET STATISTICS {{data.attstattarget}}; {% endif %} {### Alter column storage value ###} {% if data.attstorage and data.attstorage != o_data.attstorage %} ALTER TABLE {{conn|qtIdent(data.schema, data.table)}} - ALTER COLUMN {{conn|qtIdent(data.name)}} SET STORAGE {%if data.attstorage == 'p' %} + ALTER COLUMN {% if data.name %}{{conn|qtTypeIdent(data.name)}}{% else %}{{conn|qtTypeIdent(o_data.name)}}{% endif %} SET STORAGE {%if data.attstorage == 'p' %} PLAIN{% elif data.attstorage == 'm'%}MAIN{% elif data.attstorage == 'e'%} EXTERNAL{% elif data.attstorage == 'x'%}EXTENDED{% endif %}; {% endif %} {% if data.description is defined %} +{% if data.name %} COMMENT ON COLUMN {{conn|qtIdent(data.schema, data.table, data.name)}} +{% else %} +COMMENT ON COLUMN {{conn|qtIdent(data.schema, data.table, o_data.name)}} +{% endif %} IS {{data.description|qtLiteral}}; {% endif %} @@ -52,15 +56,27 @@ COMMENT ON COLUMN {{conn|qtIdent(data.schema, data.table, data.name)}} {% set variables = data.attoptions %} {% if 'deleted' in variables and variables.deleted|length > 0 %} ALTER TABLE {{conn|qtIdent(data.schema, data.table)}} +{% if data.name %} {{ VARIABLE.UNSET(conn, 'COLUMN', data.name, variables.deleted) }} +{% else %} + {{ VARIABLE.UNSET(conn, 'COLUMN', o_data.name, variables.deleted) }} +{% endif %} {% endif %} {% if 'added' in variables and variables.added|length > 0 %} ALTER TABLE {{conn|qtIdent(data.schema, data.table)}} +{% if data.name %} {{ VARIABLE.SET(conn, 'COLUMN', data.name, variables.added) }} +{% else %} + {{ VARIABLE.SET(conn, 'COLUMN', o_data.name, variables.added) }} +{% endif %} {% endif %} {% if 'changed' in variables and variables.changed|length > 0 %} ALTER TABLE {{conn|qtIdent(data.schema, data.table)}} +{% if data.name %} {{ VARIABLE.SET(conn, 'COLUMN', data.name, variables.changed) }} +{% else %} + {{ VARIABLE.SET(conn, 'COLUMN', o_data.name, variables.changed) }} +{% endif %} {% endif %} {% endif %} @@ -69,18 +85,31 @@ ALTER TABLE {{conn|qtIdent(data.schema, data.table)}} {% if data.attacl %} {% if 'deleted' in data.attacl %} {% for priv in data.attacl.deleted %} +{% if data.name %} {{ PRIVILEGE.RESETALL(conn, data.schema, data.table, data.name, priv.grantee) }} +{% else %} +{{ PRIVILEGE.RESETALL(conn, data.schema, data.table, o_data.name, priv.grantee) }} +{% endif %} {% endfor %} {% endif %} {% if 'changed' in data.attacl %} {% for priv in data.attacl.changed %} +{% if data.name %} {{ PRIVILEGE.RESETALL(conn, data.schema, data.table, data.name, priv.grantee) }} {{ PRIVILEGE.APPLY(conn, data.schema, data.table, data.name, priv.grantee, priv.without_grant, priv.with_grant) }} +{% else %} +{{ PRIVILEGE.RESETALL(conn, data.schema, data.table, o_data.name, priv.grantee) }} +{{ PRIVILEGE.APPLY(conn, data.schema, data.table, o_data.name, priv.grantee, priv.without_grant, priv.with_grant) }} +{% endif %} {% endfor %} {% endif %} {% if 'added' in data.attacl %} {% for priv in data.attacl.added %} +{% if data.name %} {{ PRIVILEGE.APPLY(conn, data.schema, data.table, data.name, priv.grantee, priv.without_grant, priv.with_grant) }} +{% else %} +{{ PRIVILEGE.APPLY(conn, data.schema, data.table, o_data.name, priv.grantee, priv.without_grant, priv.with_grant) }} +{% endif %} {% endfor %} {% endif %} {% endif %} @@ -90,18 +119,30 @@ ALTER TABLE {{conn|qtIdent(data.schema, data.table)}} {% set seclabels = data.seclabels %} {% if 'deleted' in seclabels and seclabels.deleted|length > 0 %} {% for r in seclabels.deleted %} +{% if data.name %} {{ SECLABEL.DROP(conn, 'COLUMN', data.schema, data.table, data.name, r.provider) }} +{% else %} +{{ SECLABEL.DROP(conn, 'COLUMN', data.schema, data.table, o_data.name, r.provider) }} +{% endif %} {% endfor %} {% endif %} {% if 'added' in seclabels and seclabels.added|length > 0 %} {% for r in seclabels.added %} +{% if data.name %} {{ SECLABEL.APPLY(conn, 'COLUMN',data.schema, data.table, data.name, r.provider, r.label) }} +{% else %} +{{ SECLABEL.APPLY(conn, 'COLUMN',data.schema, data.table, o_data.name, r.provider, r.label) }} +{% endif %} {% endfor %} {% endif %} {% if 'changed' in seclabels and seclabels.changed|length > 0 %} {% for r in seclabels.changed %} +{% if data.name %} {{ SECLABEL.APPLY(conn, 'COLUMN',data.schema, data.table, data.name, r.provider, r.label) }} +{% else %} +{{ SECLABEL.APPLY(conn, 'COLUMN',data.schema, data.table, o_data.name, r.provider, r.label) }} +{% endif %} {% endfor %} {% endif %} -{% endif %} +{% endif %} \ No newline at end of file diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/column/sql/9.2_plus/update.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/column/sql/9.2_plus/update.sql index 5445805..77ef8ea 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/column/sql/9.2_plus/update.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/column/sql/9.2_plus/update.sql @@ -2,7 +2,7 @@ {% import 'column/macros/privilege.macros' as PRIVILEGE %} {% import 'macros/variable.macros' as VARIABLE %} {### Rename column name ###} -{% if data.name != o_data.name %} +{% if data.name and data.name != o_data.name %} ALTER TABLE {{conn|qtIdent(data.schema, data.table)}} RENAME {{conn|qtIdent(o_data.name)}} TO {{conn|qtIdent(data.name)}}; @@ -10,40 +10,43 @@ ALTER TABLE {{conn|qtIdent(data.schema, data.table)}} {### Alter column type and collation ###} {% if (data.cltype and data.cltype != o_data.cltype) or (data.attlen and data.attlen != o_data.attlen) or (data.attprecision and data.attprecision != o_data.attprecision) %} ALTER TABLE {{conn|qtIdent(data.schema, data.table)}} - ALTER COLUMN {{conn|qtIdent(data.name)}} TYPE {% if data.cltype %}{{conn|qtTypeIdent(data.cltype)}} {% else %}{{o_data.cltype}} {% endif %}{% if data.attlen %} -({{data.attlen}}{% if data.attprecision%}, {{data.attprecision}}{% endif %}){% endif %}{% if data.hasSqrBracket %} + ALTER COLUMN {% if data.name %}{{conn|qtTypeIdent(data.name)}}{% else %}{{conn|qtTypeIdent(o_data.name)}}{% endif %} TYPE {% if data.cltype %}{{conn|qtTypeIdent(data.cltype)}} {% else %}{{conn|qtTypeIdent(o_data.cltype)}} {% endif %} +{% if data.attlen %}({{data.attlen}}{% elif not data.cltype %}({{o_data.attlen}}{% endif %}{% if data.attprecision%}, {{data.attprecision}}){% elif not data.cltype %}, {{o_data.attprecision}}){% elif data.attlen %}){% endif %}{% if data.hasSqrBracket %} []{% endif %}{% if data.collspcname and data.collspcname != o_data.collspcname %} COLLATE {{data.collspcname}}{% endif %}; - {% endif %} {### Alter column default value ###} {% if data.defval and data.defval != o_data.defval %} ALTER TABLE {{conn|qtIdent(data.schema, data.table)}} - ALTER COLUMN {{conn|qtIdent(data.name)}} SET DEFAULT {{data.defval}}; + ALTER COLUMN {% if data.name %}{{conn|qtTypeIdent(data.name)}}{% else %}{{conn|qtTypeIdent(o_data.name)}}{% endif %} SET DEFAULT {{data.defval}}; {% endif %} {### Alter column not null value ###} {% if 'attnotnull' in data and data.attnotnull != o_data.attnotnull %} ALTER TABLE {{conn|qtIdent(data.schema, data.table)}} - ALTER COLUMN {{conn|qtIdent(data.name)}} {% if data.attnotnull %}SET{% else %}DROP{% endif %} NOT NULL; + ALTER COLUMN {% if data.name %}{{conn|qtTypeIdent(data.name)}}{% else %}{{conn|qtTypeIdent(o_data.name)}}{% endif %} {% if data.attnotnull %}SET{% else %}DROP{% endif %} NOT NULL; {% endif %} {### Alter column statistics value ###} {% if data.attstattarget and data.attstattarget != o_data.attstattarget %} ALTER TABLE {{conn|qtIdent(data.schema, data.table)}} - ALTER COLUMN {{conn|qtIdent(data.name)}} SET STATISTICS {{data.attstattarget}}; + ALTER COLUMN {% if data.name %}{{conn|qtTypeIdent(data.name)}}{% else %}{{conn|qtTypeIdent(o_data.name)}}{% endif %} SET STATISTICS {{data.attstattarget}}; {% endif %} {### Alter column storage value ###} {% if data.attstorage and data.attstorage != o_data.attstorage %} ALTER TABLE {{conn|qtIdent(data.schema, data.table)}} - ALTER COLUMN {{conn|qtIdent(data.name)}} SET STORAGE {%if data.attstorage == 'p' %} + ALTER COLUMN {% if data.name %}{{conn|qtTypeIdent(data.name)}}{% else %}{{conn|qtTypeIdent(o_data.name)}}{% endif %} SET STORAGE {%if data.attstorage == 'p' %} PLAIN{% elif data.attstorage == 'm'%}MAIN{% elif data.attstorage == 'e'%} EXTERNAL{% elif data.attstorage == 'x'%}EXTENDED{% endif %}; {% endif %} {% if data.description is defined %} +{% if data.name %} COMMENT ON COLUMN {{conn|qtIdent(data.schema, data.table, data.name)}} +{% else %} +COMMENT ON COLUMN {{conn|qtIdent(data.schema, data.table, o_data.name)}} +{% endif %} IS {{data.description|qtLiteral}}; {% endif %} @@ -52,15 +55,27 @@ COMMENT ON COLUMN {{conn|qtIdent(data.schema, data.table, data.name)}} {% set variables = data.attoptions %} {% if 'deleted' in variables and variables.deleted|length > 0 %} ALTER TABLE {{conn|qtIdent(data.schema, data.table)}} +{% if data.name %} {{ VARIABLE.UNSET(conn, 'COLUMN', data.name, variables.deleted) }} +{% else %} + {{ VARIABLE.UNSET(conn, 'COLUMN', o_data.name, variables.deleted) }} +{% endif %} {% endif %} {% if 'added' in variables and variables.added|length > 0 %} ALTER TABLE {{conn|qtIdent(data.schema, data.table)}} +{% if data.name %} {{ VARIABLE.SET(conn, 'COLUMN', data.name, variables.added) }} +{% else %} + {{ VARIABLE.SET(conn, 'COLUMN', o_data.name, variables.added) }} +{% endif %} {% endif %} {% if 'changed' in variables and variables.changed|length > 0 %} ALTER TABLE {{conn|qtIdent(data.schema, data.table)}} +{% if data.name %} {{ VARIABLE.SET(conn, 'COLUMN', data.name, variables.changed) }} +{% else %} + {{ VARIABLE.SET(conn, 'COLUMN', o_data.name, variables.changed) }} +{% endif %} {% endif %} {% endif %} {### Update column privileges ###} @@ -68,18 +83,31 @@ ALTER TABLE {{conn|qtIdent(data.schema, data.table)}} {% if data.attacl %} {% if 'deleted' in data.attacl %} {% for priv in data.attacl.deleted %} -{{ PRIVILEGE.RESETALL(conn, data.schema, data.table, data.name, priv.grantee) }} +{% if data.name %} + {{ PRIVILEGE.RESETALL(conn, data.schema, data.table, data.name, priv.grantee) }} +{% else %} + {{ PRIVILEGE.RESETALL(conn, data.schema, data.table, o_data.name, priv.grantee) }} +{% endif %} {% endfor %} {% endif %} {% if 'changed' in data.attacl %} {% for priv in data.attacl.changed %} -{{ PRIVILEGE.RESETALL(conn, data.schema, data.table, data.name, priv.grantee) }} -{{ PRIVILEGE.APPLY(conn, data.schema, data.table, data.name, priv.grantee, priv.without_grant, priv.with_grant) }} +{% if data.name %} + {{ PRIVILEGE.RESETALL(conn, data.schema, data.table, data.name, priv.grantee) }} + {{ PRIVILEGE.APPLY(conn, data.schema, data.table, data.name, priv.grantee, priv.without_grant, priv.with_grant) }} +{% else %} + {{ PRIVILEGE.RESETALL(conn, data.schema, data.table, o_data.name, priv.grantee) }} + {{ PRIVILEGE.APPLY(conn, data.schema, data.table, o_data.name, priv.grantee, priv.without_grant, priv.with_grant) }} +{% endif %} {% endfor %} {% endif %} {% if 'added' in data.attacl %} {% for priv in data.attacl.added %} -{{ PRIVILEGE.APPLY(conn, data.schema, data.table, data.name, priv.grantee, priv.without_grant, priv.with_grant) }} +{% if data.name %} + {{ PRIVILEGE.APPLY(conn, data.schema, data.table, data.name, priv.grantee, priv.without_grant, priv.with_grant) }} +{% else %} + {{ PRIVILEGE.APPLY(conn, data.schema, data.table, o_data.name, priv.grantee, priv.without_grant, priv.with_grant) }} +{% endif %} {% endfor %} {% endif %} {% endif %} @@ -89,17 +117,29 @@ ALTER TABLE {{conn|qtIdent(data.schema, data.table)}} {% set seclabels = data.seclabels %} {% if 'deleted' in seclabels and seclabels.deleted|length > 0 %} {% for r in seclabels.deleted %} +{% if data.name %} {{ SECLABEL.DROP(conn, 'COLUMN', data.schema, data.table, data.name, r.provider) }} +{% else %} +{{ SECLABEL.DROP(conn, 'COLUMN', data.schema, data.table, o_data.name, r.provider) }} +{% endif %} {% endfor %} {% endif %} {% if 'added' in seclabels and seclabels.added|length > 0 %} {% for r in seclabels.added %} +{% if data.name %} {{ SECLABEL.APPLY(conn, 'COLUMN',data.schema, data.table, data.name, r.provider, r.label) }} +{% else %} +{{ SECLABEL.APPLY(conn, 'COLUMN',data.schema, data.table, o_data.name, r.provider, r.label) }} +{% endif %} {% endfor %} {% endif %} {% if 'changed' in seclabels and seclabels.changed|length > 0 %} {% for r in seclabels.changed %} +{% if data.name %} {{ SECLABEL.APPLY(conn, 'COLUMN',data.schema, data.table, data.name, r.provider, r.label) }} -{% endfor %} +{% else %} +{{ SECLABEL.APPLY(conn, 'COLUMN',data.schema, data.table, o_data.name, r.provider, r.label) }} {% endif %} +{% endfor %} {% endif %} +{% endif %} \ No newline at end of file diff --git a/web/pgadmin/browser/static/js/datamodel.js b/web/pgadmin/browser/static/js/datamodel.js index 7b379ce..7d326f9 100644 --- a/web/pgadmin/browser/static/js/datamodel.js +++ b/web/pgadmin/browser/static/js/datamodel.js @@ -1065,8 +1065,10 @@ function(_, pgAdmin, $, Backbone) { return true; } - self.sessAttrs['changed'].push(obj); - (self.handler || self).trigger('pgadmin-session:changed', self, obj); + if (obj.sessChanged()) { + self.sessAttrs['changed'].push(obj); + (self.handler || self).trigger('pgadmin-session:changed', self, obj); + } return true; },
-- Sent via pgadmin-hackers mailing list (pgadmin-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgadmin-hackers