Enable/disable NULLs and ASC/DESC options for index columns and exclusion constraints appropriately. Fixes #2061. Fixes #1840.

pull/3/head
Surinder Kumar 2017-01-25 13:21:39 +00:00 committed by Dave Page
parent 2ebaf56cc4
commit e01cf748ea
7 changed files with 71 additions and 43 deletions

View File

@ -816,7 +816,7 @@ class ExclusionConstraintView(PGChildNodeView):
sql = render_template("/".join([self.template_path, 'create.sql']),
data=data, conn=self.conn)
return sql, data['name'] if 'name' in data else old_data['name']
return sql, data['name']
@check_precondition
def sql(self, gid, sid, did, scid, tid, exid=None):

View File

@ -7,10 +7,11 @@ function($, _, S, pgAdmin, pgBrowser, Alertify) {
defaults: {
column: undefined,
oper_class: undefined,
order: undefined,
nulls_order: undefined,
order: false,
nulls_order: false,
operator:undefined,
col_type:undefined
col_type:undefined,
is_sort_nulls_applicable: true
},
toJSON: function () {
var d = pgBrowser.Node.Model.prototype.toJSON.apply(this, arguments);
@ -23,26 +24,9 @@ function($, _, S, pgAdmin, pgBrowser, Alertify) {
},{
id: 'oper_class', label:'{{ _('Operator class') }}', type:'text',
node: 'table', url: 'get_oper_class', first_empty: true,
editable: function(m) {
if (m instanceof Backbone.Collection) {
return true;
}
if ((_.has(m.collection, 'handler') &&
!_.isUndefined(m.collection.handler) &&
!_.isUndefined(m.collection.handler.get('oid')))) {
return false;
}
if (m.collection) {
var indexType = m.collection.handler.get('amname')
return (indexType == 'btree' || _.isUndefined(indexType) ||
_.isNull(indexType) || indexType == '');
} else {
return true;
}
},
editable: true,
select2: {
allowClear: true, width: 'style',
allowClear: true, width: 'style', tags: true,
placeholder: '{{ _("Select the operator class") }}'
}, cell: Backgrid.Extension.Select2Cell.extend({
initialize: function () {
@ -55,6 +39,12 @@ function($, _, S, pgAdmin, pgBrowser, Alertify) {
if (url && (indextype == 'btree' || _.isUndefined(indextype) ||
_.isNull(indextype) || indextype == '')) {
// Set sort_order and nulls to true if access method is btree
setTimeout(function() {
m.set('order', true);
m.set('nulls_order', true);
}, 10);
var node = this.column.get('schema_node'),
eventHandler = m.top || m,
node_info = this.column.get('node_info'),
@ -108,6 +98,14 @@ function($, _, S, pgAdmin, pgBrowser, Alertify) {
if (m instanceof Backbone.Collection) {
return true;
}
else {
if (m.top.get('amname') === 'btree') {
m.set('is_sort_nulls_applicable', true);
return true;
}
m.set('is_sort_nulls_applicable', false);
return false;
}
if ((_.has(m.collection, 'handler') &&
!_.isUndefined(m.collection.handler) &&
!_.isUndefined(m.collection.handler.get('oid')))) {
@ -124,6 +122,15 @@ function($, _, S, pgAdmin, pgBrowser, Alertify) {
if (m instanceof Backbone.Collection) {
return true;
}
else {
if (m.top.get('amname') === 'btree') {
m.set('is_sort_nulls_applicable', true);
return true;
}
m.set('is_sort_nulls_applicable', false);
return false;
}
if ((_.has(m.collection, 'handler') &&
!_.isUndefined(m.collection.handler) &&
!_.isUndefined(m.collection.handler.get('oid')))) {
@ -898,8 +905,15 @@ function($, _, S, pgAdmin, pgBrowser, Alertify) {
}],
validate: function() {
this.errorModel.clear();
var columns = this.get('columns');
if ((_.isUndefined(columns) || _.isNull(columns) || columns.length < 1)) {
var columns = this.get('columns'),
name = this.get('name');
if ((_.isUndefined(name) || _.isNull(name) || name.length < 1)) {
var msg = '{{ _('Please specify name for exclusion constraint.') }}';
this.errorModel.set('name', msg);
return msg;
}
else if ((_.isUndefined(columns) || _.isNull(columns) || columns.length < 1)) {
var msg = '{{ _('Please specify columns for exclusion constraint.') }}';
this.errorModel.set('columns', msg);
return msg;

View File

@ -51,7 +51,8 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) {
collspcname: undefined,
op_class: undefined,
sort_order: false,
nulls: false
nulls: false,
is_sort_nulls_applicable: true
},
schema: [
{
@ -77,7 +78,7 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) {
control: 'node-ajax-options', url: 'get_collations', node: 'index'
},{
id: 'op_class', label:'{{ _('Operator class') }}',
cell: NodeAjaxOptionsDepsCell,
cell: NodeAjaxOptionsDepsCell, tags: true,
type: 'text', disabled: 'checkAccessMethod',
editable: function(m) {
// Header cell then skip
@ -108,13 +109,19 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) {
},{
id: 'sort_order', label:'{{ _('Sort order') }}',
cell: Backgrid.Extension.TableChildSwitchCell, type: 'switch',
disabled: 'checkAccessMethod',
editable: function(m) {
// Header cell then skip
if (m instanceof Backbone.Collection) {
return false;
}
return !(m.checkAccessMethod.apply(this, arguments));
else {
if (m.top.get('amname') === 'btree') {
m.set('is_sort_nulls_applicable', true);
return true;
}
m.set('is_sort_nulls_applicable', false);
return false;
}
},
deps: ['amname'],
options: {
@ -125,13 +132,18 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) {
},{
id: 'nulls', label:'{{ _('NULLs') }}',
cell: Backgrid.Extension.TableChildSwitchCell, type: 'switch',
disabled: 'checkAccessMethod',
editable: function(m) {
// Header cell then skip
if (m instanceof Backbone.Collection) {
return true;
} else {
if (m.top.get('amname') === 'btree') {
m.set('is_sort_nulls_applicable', true);
return true;
}
m.set('is_sort_nulls_applicable', false);
return false;
}
return !(m.checkAccessMethod.apply(this, arguments));
},
deps: ['amname', 'sort_order'],
options: {
@ -184,9 +196,11 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) {
if(m.get('sort_order') == true && m.previous('sort_order') == false) {
setTimeout(function() { m.set('nulls', true) }, 10);
}
return false;
}
return true;
else {
m.set('is_sort_nulls_applicable', false);
}
return false;
},
});

View File

@ -1,7 +1,7 @@
ALTER TABLE {{ conn|qtIdent(data.schema, data.table) }}
ADD{% if data.name %} CONSTRAINT {{ conn|qtIdent(data.name) }}{% endif%} EXCLUDE {% if data.amname and data.amname != '' %}USING {{data.amname}}{% endif %} (
{% for col in data.columns %}{% if loop.index != 1 %},
{% endif %}{{ conn|qtIdent(col.column)}} {% if col.oper_class and col.oper_class != '' %}{{col.oper_class}} {% endif%}{% if col.order %}ASC{% else %}DESC{% endif %} NULLS {% if col.nulls_order %}FIRST{% else %}LAST{% endif %} WITH {{col.operator}}{% endfor %}){% if data.fillfactor %}
{% endif %}{{ conn|qtIdent(col.column)}}{% if col.oper_class and col.oper_class != '' %} {{col.oper_class}}{% endif%}{% if col.order is defined and col.is_sort_nulls_applicable %}{% if col.order %} ASC{% else %} DESC{% endif %} NULLS{% endif %} {% if col.nulls_order is defined and col.is_sort_nulls_applicable %}{% if col.nulls_order %}FIRST {% else %}LAST {% endif %}{% endif %}WITH {{col.operator}}{% endfor %}){% if data.fillfactor %}
WITH (FILLFACTOR={{data.fillfactor}}){% endif %}{% if data.spcname and data.spcname != "pg_default" %}
USING INDEX TABLESPACE {{ conn|qtIdent(data.spcname) }}{% endif %}

View File

@ -1,7 +1,7 @@
ALTER TABLE {{ conn|qtIdent(data.schema, data.table) }}
ADD{% if data.name %} CONSTRAINT {{ conn|qtIdent(data.name) }}{% endif%} EXCLUDE {% if data.amname and data.amname != '' %}USING {{data.amname}}{% endif %} (
{% for col in data.columns %}{% if loop.index != 1 %},
{% endif %}{{ conn|qtIdent(col.column)}} {% if col.oper_class and col.oper_class != '' %}{{col.oper_class}} {% endif%}{% if col.order %}ASC{% else %}DESC{% endif %} NULLS {% if col.nulls_order %}FIRST{% else %}LAST{% endif %} WITH {{col.operator}}{% endfor %}){% if data.fillfactor %}
{% endif %}{{ conn|qtIdent(col.column)}}{% if col.oper_class and col.oper_class != '' %} {{col.oper_class}}{% endif%}{% if col.order is defined and col.is_sort_nulls_applicable %}{% if col.order %} ASC{% else %} DESC{% endif %} NULLS{% endif %} {% if col.nulls_order is defined and col.is_sort_nulls_applicable %}{% if col.nulls_order %}FIRST {% else %}LAST {% endif %}{% endif %}WITH {{col.operator}}{% endfor %}){% if data.fillfactor %}
WITH (FILLFACTOR={{data.fillfactor}}){% endif %}{% if data.spcname and data.spcname != "pg_default" %}
USING INDEX TABLESPACE {{ conn|qtIdent(data.spcname) }}{% endif %}

View File

@ -1,7 +1,7 @@
ALTER TABLE {{ conn|qtIdent(data.schema, data.table) }}
ADD{% if data.name %} CONSTRAINT {{ conn|qtIdent(data.name) }}{% endif%} EXCLUDE {% if data.amname and data.amname != '' %}USING {{data.amname}}{% endif %} (
{% for col in data.columns %}{% if loop.index != 1 %},
{% endif %}{{ conn|qtIdent(col.column)}} {% if col.oper_class and col.oper_class != '' %}{{col.oper_class}} {% endif%}{% if col.order %}ASC{% else %}DESC{% endif %} NULLS {% if col.nulls_order %}FIRST{% else %}LAST{% endif %} WITH {{col.operator}}{% endfor %}){% if data.fillfactor %}
{% endif %}{{ conn|qtIdent(col.column)}}{% if col.oper_class and col.oper_class != '' %} {{col.oper_class}}{% endif%}{% if col.order is defined and col.is_sort_nulls_applicable %}{% if col.order %} ASC{% else %} DESC{% endif %} NULLS{% endif %} {% if col.nulls_order is defined and col.is_sort_nulls_applicable %}{% if col.nulls_order %}FIRST {% else %}LAST {% endif %}{% endif %}WITH {{col.operator}}{% endfor %}){% if data.fillfactor %}
WITH (FILLFACTOR={{data.fillfactor}}){% endif %}{% if data.spcname and data.spcname != "pg_default" %}
USING INDEX TABLESPACE {{ conn|qtIdent(data.spcname) }}{% endif %}

View File

@ -3,7 +3,7 @@ CREATE {% if data.indisunique %}UNIQUE {% endif %}INDEX {% if data.isconcurrent
{% 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 data.amname is defined and data.amname not in ['gist', 'gin'] %}{% if c.sort_order is defined %}{% if c.sort_order %} DESC{% else %} ASC{% endif %}{% endif %}{% if c.nulls is defined %} NULLS {% if c.nulls %}
{{c.op_class}}{% endif %}{% if data.amname is defined %}{% if c.sort_order is defined and c.is_sort_nulls_applicable %}{% if c.sort_order %} DESC{% else %} ASC{% endif %}{% endif %}{% if c.nulls is defined and c.is_sort_nulls_applicable %} NULLS {% if c.nulls %}
FIRST{% else %}LAST{% endif %}{% endif %}{% endif %}{% endfor %})
{% else %}
{## We will get indented data from postgres for column ##}