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

Commit 072d61d5 by Harshith Kashyap Committed by Sushant

Filtered indexes for SQL Server (#7033)

* Enabled filtered indexes for SQL Server

* [ci skip] Added filtered indexes to docs/migrations.md
1 parent 6f9a53bf
# Future
- [ADDED] Filtered Indexes support for SQL Server [#7016](https://github.com/sequelize/sequelize/issues/7016)
- [FIXED] Set `timestamps` and `paranoid` options from through model on `belongsToMany` association
- [FIXED] Properly apply paranoid condition when `groupedLimit.on` association is `paranoid`
- [FIXED] Throw MSSQL MERGE Statement foreignKey violations as ForeignKeyConstraintError [#7011](https://github.com/sequelize/sequelize/pull/7011)
......
......@@ -271,6 +271,7 @@ queryInterface.addIndex('Person', ['firstname', 'lastname'])
// - parser: For FULLTEXT columns set your parser
// - indexType: Set a type for the index, e.g. BTREE. See the documentation of the used dialect
// - logging: A function that receives the sql query, e.g. console.log
// - where: A hash of attributes to limit your index(Filtered Indexes - MSSQL & PostgreSQL only)
queryInterface.addIndex(
'Person',
['firstname', 'lastname'],
......@@ -279,6 +280,18 @@ queryInterface.addIndex(
indicesType: 'UNIQUE'
}
)
queryInterface.addIndex(
'Person',
['firstname', 'lastname'],
{
where: {
lastname: {
$ne: null
}
}
}
)
```
### removeIndex(tableName, indexNameOrAttributes, options)
......
......@@ -44,7 +44,8 @@ MssqlDialect.prototype.supports = _.merge(_.cloneDeep(Abstract.prototype.support
length: false,
parser: false,
type: true,
using: false
using: false,
where: true
},
NUMERIC: true,
tmpTableTrigger: true
......
......@@ -87,7 +87,7 @@ suite(Support.getTestDialectTeaser('SQL'), function() {
});
}
if (current.dialect.supports.index.using === 2) {
if (current.dialect.supports.index.where) {
test('WHERE', function () {
expectsql(sql.addIndexQuery('table', {
fields: ['type'],
......@@ -95,7 +95,8 @@ suite(Support.getTestDialectTeaser('SQL'), function() {
type: 'public'
}
}), {
postgres: 'CREATE INDEX "table_type" ON "table" ("type") WHERE "type" = \'public\''
postgres: 'CREATE INDEX "table_type" ON "table" ("type") WHERE "type" = \'public\'',
mssql: 'CREATE INDEX [table_type] ON [table] ([type]) WHERE [type] = N\'public\''
});
expectsql(sql.addIndexQuery('table', {
......@@ -109,7 +110,20 @@ suite(Support.getTestDialectTeaser('SQL'), function() {
}
}
}), {
postgres: 'CREATE INDEX "table_type" ON "table" ("type") WHERE ("type" = \'group\' OR "type" = \'private\')'
postgres: 'CREATE INDEX "table_type" ON "table" ("type") WHERE ("type" = \'group\' OR "type" = \'private\')',
mssql: 'CREATE INDEX [table_type] ON [table] ([type]) WHERE ([type] = N\'group\' OR [type] = N\'private\')'
});
expectsql(sql.addIndexQuery('table', {
fields: ['type'],
where: {
type: {
$ne: null
}
}
}), {
postgres: 'CREATE INDEX "table_type" ON "table" ("type") WHERE "type" IS NOT NULL',
mssql: 'CREATE INDEX [table_type] ON [table] ([type]) WHERE [type] IS NOT NULL'
});
});
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!