Skip to content

Commit e46874d

Browse files
committed
fix: Other dialect duplicated add index problem
Detect is using SQLite to add index
1 parent e26bb05 commit e46874d

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
'use strict'
2+
const isSQLite = require('../utils').isSQLite
23
module.exports = {
34
up: function (queryInterface, Sequelize) {
45
return queryInterface.changeColumn('Notes', 'title', {
56
type: Sequelize.TEXT
67
}).then(function () {
7-
// manual added index will be removed in sqlite
8-
return queryInterface.addIndex('Notes', ['shortid'])
8+
if (isSQLite(queryInterface.sequelize)) {
9+
// manual added index will be removed in sqlite
10+
return queryInterface.addIndex('Notes', ['shortid'])
11+
}
912
})
1013
},
1114

1215
down: function (queryInterface, Sequelize) {
1316
return queryInterface.changeColumn('Notes', 'title', {
1417
type: Sequelize.STRING
1518
}).then(function () {
16-
return queryInterface.addIndex('Notes', ['shortid'])
19+
if (isSQLite(queryInterface.sequelize)) {
20+
// manual added index will be removed in sqlite
21+
return queryInterface.addIndex('Notes', ['shortid'])
22+
}
1723
})
1824
}
1925
}

lib/utils.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict'
2+
3+
exports.isSQLite = function isSQLite (sequelize) {
4+
return sequelize.options.dialect === 'sqlite'
5+
}

0 commit comments

Comments
 (0)