不要怂,就是干,撸起袖子干!

Commit dc090b5c by Mick Hansen

Merge branch 'vickenstein-postgres-partial-index'

2 parents e7f3b195 1d22f404
......@@ -3,6 +3,7 @@
- [BUG] instance.removeAssociation(s) do not fire the select query twice anymore
- [BUG] Error messages thrown by the db in languages other than english do not crash the app anymore (mysql, mariadb and postgres only) [#3567](https://github.com/sequelize/sequelize/pull/3567)
- [FEATURE] All querys can be logged individually by inserting `logging: fn` in the query option.
- [FEATURE] Partial index support for Postgres with `index.where`
- [DEPRECATED] The query-chainer is deprecated and will be removed in version 2.2. Please use promises instead.
- [REMOVED] Events are no longer supported.
......
......@@ -538,6 +538,10 @@ module.exports = (function() {
delete options.type;
}
if (options.where) {
options.where = this.whereQuery(options.where);
}
return Utils._.compact([
'CREATE',
options.unique ? 'UNIQUE' : '',
......@@ -548,7 +552,8 @@ module.exports = (function() {
'ON', this.quoteIdentifiers(tableName),
this._dialect.supports.index.using === 2 && options.using ? 'USING ' + options.using : '',
'(' + fieldsSql.join(', ') + (options.operator ? ' '+options.operator : '') + ')',
(this._dialect.supports.index.parser && options.parser ? 'WITH PARSER ' + options.parser : undefined)
(this._dialect.supports.index.parser && options.parser ? 'WITH PARSER ' + options.parser : undefined),
(this._dialect.supports.index.where && options.where ? options.where : undefined)
]).join(' ');
},
......
......@@ -37,6 +37,7 @@ PostgresDialect.prototype.supports = _.merge(_.cloneDeep(Abstract.prototype.supp
index: {
concurrently: true,
using: 2,
where: true
},
JSON: true,
JSONB: true
......
......@@ -55,6 +55,33 @@ suite(Support.getTestDialectTeaser('SQL'), function() {
});
}
if (current.dialect.supports.index.using === 2) {
test('WHERE', function () {
expectsql(sql.addIndexQuery('table', {
fields: ['type'],
where: {
type: 'public'
}
}), {
postgres: 'CREATE INDEX "table_type" ON "table" ("type") WHERE "type" = \'public\''
});
expectsql(sql.addIndexQuery('table', {
fields: ['type'],
where: {
type: {
$or: [
'group',
'private'
]
}
}
}), {
postgres: 'CREATE INDEX "table_type" ON "table" ("type") WHERE ("type" = \'group\' OR "type" = \'private\')'
});
});
}
if (current.dialect.supports.JSON) {
test('operator', function () {
expectsql(sql.addIndexQuery('table', {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!