diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/__init__.py index 4573a9778..e80e7d2d0 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/__init__.py @@ -559,7 +559,7 @@ class IndexesView(PGChildNodeView): try: SQL = render_template("/".join([self.template_path, 'create.sql']), - data=data, conn=self.conn) + data=data, conn=self.conn, mode='create') status, res = self.conn.execute_scalar(SQL) if not status: return internal_server_error(errormsg=res) @@ -719,7 +719,7 @@ class IndexesView(PGChildNodeView): data['table'] = self.table try: - SQL = self.get_sql(scid, tid, idx, data) + SQL = self.get_sql(scid, tid, idx, data, mode='create') if SQL and SQL.strip('\n') and SQL.strip(' '): return make_json_response( @@ -729,7 +729,7 @@ class IndexesView(PGChildNodeView): except Exception as e: return internal_server_error(errormsg=str(e)) - def get_sql(self, scid, tid, idx, data): + def get_sql(self, scid, tid, idx, data, mode=None): """ This function will genrate sql from model data """ @@ -772,7 +772,7 @@ class IndexesView(PGChildNodeView): # If the request for new object which do not have did SQL = render_template("/".join([self.template_path, 'create.sql']), - data=data, conn=self.conn) + data=data, conn=self.conn, mode=mode) SQL += "\n" SQL += render_template("/".join([self.template_path, 'alter.sql']), data=data, conn=self.conn) 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 4492021d4..be3eca38d 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 @@ -55,17 +55,23 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) { schema: [ { id: 'colname', label:'{{ _('Column') }}', cell: 'node-list-by-name', - type: 'text', disabled: 'inSchema', editable: true, - control: 'node-list-by-name', node: 'column' - },{ - id: 'collspcname', label:'{{ _('Collation') }}', - cell: NodeAjaxOptionsDepsCell, - type: 'text', disabled: 'inSchema', editable: function(m) { + type: 'text', disabled: 'inSchemaWithModelCheck', editable: function(m) { // Header cell then skip if (m instanceof Backbone.Collection) { return false; } - return !(m.inSchema.apply(this, arguments)); + return !(m.inSchemaWithModelCheck.apply(this, arguments)); + }, + control: 'node-list-by-name', node: 'column' + },{ + id: 'collspcname', label:'{{ _('Collation') }}', + cell: NodeAjaxOptionsDepsCell, + type: 'text', disabled: 'inSchemaWithModelCheck', editable: function(m) { + // Header cell then skip + if (m instanceof Backbone.Collection) { + return false; + } + return !(m.inSchemaWithModelCheck.apply(this, arguments)); }, control: 'node-ajax-options', url: 'get_collations', node: 'index' },{ @@ -153,9 +159,9 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) { }, // We will check if we are under schema node & in 'create' mode inSchemaWithModelCheck: function(m) { - if(this.node_info && 'schema' in this.node_info) { + if(m.top.node_info && 'schema' in m.top.node_info) { // We will disable control if it's in 'edit' mode - if (m.isNew()) { + if (m.top.isNew()) { return false; } else { return true; @@ -167,7 +173,7 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) { checkAccessMethod: function(m) { //Access method is empty or btree then do not disable field var parent_model = m.top; - if(!m.inSchema.apply(this, [m]) && + if(!m.inSchemaWithModelCheck.apply(this, [m]) && (_.isUndefined(parent_model.get('amname')) || _.isNull(parent_model.get('amname')) || String(parent_model.get('amname')).replace(/^\s+|\s+$/g, '') == '' || diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/index/sql/9.1_plus/alter.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/index/sql/9.1_plus/alter.sql index 68a444404..708583cc6 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/index/sql/9.1_plus/alter.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/index/sql/9.1_plus/alter.sql @@ -5,7 +5,7 @@ ALTER TABLE {{conn|qtIdent(data.schema, data.table)}} CLUSTER ON {{conn|qtIdent(data.name)}}; {% endif %} {## Changes description ##} -{% if data.description is defined %} +{% if data.description is defined and data.description %} COMMENT ON INDEX {{conn|qtIdent(data.schema, data.name)}} IS {{data.description|qtLiteral}};{% endif %} \ No newline at end of file diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/index/sql/9.1_plus/create.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/index/sql/9.1_plus/create.sql index b31c82754..5c2dc054d 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/index/sql/9.1_plus/create.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/index/sql/9.1_plus/create.sql @@ -1,12 +1,19 @@ CREATE {% if data.indisunique %}UNIQUE {% endif %}INDEX {% if data.isconcurrent %}CONCURRENTLY {% endif %}{{conn|qtIdent(data.name)}} ON {{conn|qtIdent(data.schema, data.table)}} {% if data.amname %}USING {{conn|qtIdent(data.amname)}}{% endif %} - ({% for c in data.columns %}{% if loop.index != 1 %}, {% endif %}{{conn|qtIdent(c.colname)}}{% if c.collspcname %} COLLATE {{c.collspcname}} {% endif %}{% if c.op_class %} +{% if mode == 'create' %} + ({% for c in data.columns %}{% if loop.index != 1 %}, {% endif %}{{conn|qtIdent(c.colname)}}{% if c.collspcname %} COLLATE {{c.collspcname}}{% endif %}{% if c.op_class %} {{c.op_class}}{% endif %}{% if c.sort_order is defined %}{% if c.sort_order %} DESC{% else %} ASC{% endif %}{% endif %}{% if c.nulls is defined %} NULLS {% if c.nulls %} -FIRST{% else %}LAST{% endif %}{% endif %}{% endfor %}){% if data.fillfactor %} - - WITH (FILLFACTOR={{data.fillfactor}}){% endif %}{% if data.spcname %} - +FIRST{% else %}LAST{% endif %}{% endif %}{% endfor %}) +{% else %} +{## We will get indented data from postgres for column ##} + ({% for c in data.columns %}{% if loop.index != 1 %}, {% endif %}{{c.colname}}{% if c.collspcname %} COLLATE {{c.collspcname}}{% endif %}{% if c.op_class %} + {{c.op_class}}{% endif %}{% if c.sort_order is defined %}{% if c.sort_order %} DESC{% else %} ASC{% endif %}{% endif %}{% if c.nulls is defined %} NULLS {% if c.nulls %} +FIRST{% else %}LAST{% endif %}{% endif %}{% endfor %}) +{% endif %} +{% if data.fillfactor %} + WITH (FILLFACTOR={{data.fillfactor}}) +{% endif %}{% if data.spcname %} TABLESPACE {{conn|qtIdent(data.spcname)}}{% endif %}{% if data.indconstraint %} - - WHERE {{data.indconstraint}}{% endif %}; \ No newline at end of file + WHERE {{data.indconstraint}} +{% endif %}; \ No newline at end of file