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

Commit 58573c19 by Juan Hoyos Committed by Jan Aagaard Meier

Create concurrent indexes at the end to avoid postgresql deadlocks. (#5810)

Also, fixed mssql tests
1 parent 56c3baf5
Showing with 24 additions and 3 deletions
......@@ -923,7 +923,17 @@ class Model {
// Assign an auto-generated name to indexes which are not named by the user
this.options.indexes = this.QueryInterface.nameIndexes(this.options.indexes, this.tableName);
indexes = _.filter(this.options.indexes, item1 => !_.some(indexes, item2 => item1.name === item2.name));
indexes = _.filter(this.options.indexes, (item1) => (
!_.some(indexes, item2 => item1.name === item2.name)
)).sort((index1, index2) => {
if (this.sequelize.options.dialect === 'postgres') {
// move concurrent indexes to the bottom to avoid weird deadlocks
if (index1.concurrently === true) return 1;
if (index2.concurrently === true) return -1;
}
return 0;
});
return Promise.map(indexes, index => this.QueryInterface.addIndex(
this.getTableName(options),
......
......@@ -377,12 +377,18 @@ describe(Support.getTestDialectTeaser('Model'), function() {
fields: ['fieldC'],
concurrently: true
});
indices.push({
type: 'FULLTEXT',
fields: ['fieldD']
});
}
var Model = this.sequelize.define('model', {
fieldA: Sequelize.STRING,
fieldB: Sequelize.INTEGER,
fieldC: Sequelize.STRING
fieldC: Sequelize.STRING,
fieldD: Sequelize.STRING
}, {
indexes: indices,
engine: 'MyISAM'
......@@ -393,7 +399,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}).then(function() {
return this.sequelize.queryInterface.showIndex(Model.tableName);
}).spread(function() {
var primary, idx1, idx2;
var primary, idx1, idx2, idx3;
if (dialect === 'sqlite') {
// PRAGMA index_info does not return the primary index
......@@ -420,6 +426,7 @@ describe(Support.getTestDialectTeaser('Model'), function() {
primary = arguments[2];
idx1 = arguments[0];
idx2 = arguments[1];
idx3 = arguments[2];
expect(idx1.fields).to.deep.equal([
{ attribute: 'fieldB', length: undefined, order: undefined, collate: undefined},
......@@ -429,6 +436,10 @@ describe(Support.getTestDialectTeaser('Model'), function() {
expect(idx2.fields).to.deep.equal([
{ attribute: 'fieldC', length: undefined, order: undefined, collate: undefined}
]);
expect(idx3.fields).to.deep.equal([
{ attribute: 'fieldD', length: undefined, order: undefined, collate: undefined}
]);
} else {
// And finally mysql returns the primary first, and then the rest in the order they were defined
primary = arguments[0];
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!