fix: Other dialect duplicated add index problem

Detect is using SQLite to add index
This commit is contained in:
BoHong Li 2017-03-28 15:25:36 +08:00
parent e26bb0503f
commit e46874d04a
2 changed files with 14 additions and 3 deletions

View File

@ -1,11 +1,14 @@
'use strict'
const isSQLite = require('../utils').isSQLite
module.exports = {
up: function (queryInterface, Sequelize) {
return queryInterface.changeColumn('Notes', 'title', {
type: Sequelize.TEXT
}).then(function () {
// manual added index will be removed in sqlite
return queryInterface.addIndex('Notes', ['shortid'])
if (isSQLite(queryInterface.sequelize)) {
// manual added index will be removed in sqlite
return queryInterface.addIndex('Notes', ['shortid'])
}
})
},
@ -13,7 +16,10 @@ module.exports = {
return queryInterface.changeColumn('Notes', 'title', {
type: Sequelize.STRING
}).then(function () {
return queryInterface.addIndex('Notes', ['shortid'])
if (isSQLite(queryInterface.sequelize)) {
// manual added index will be removed in sqlite
return queryInterface.addIndex('Notes', ['shortid'])
}
})
}
}

5
lib/utils.js Normal file
View File

@ -0,0 +1,5 @@
'use strict'
exports.isSQLite = function isSQLite (sequelize) {
return sequelize.options.dialect === 'sqlite'
}