fix: Support SQlite

Move 'unique' constraint to another statement (SQLite don't support set unique when addColumn)
This commit is contained in:
BoHong Li 2017-03-28 15:16:09 +08:00
parent 6f14822413
commit e26bb0503f
3 changed files with 25 additions and 7 deletions

View File

@ -3,17 +3,22 @@ module.exports = {
up: function (queryInterface, Sequelize) { up: function (queryInterface, Sequelize) {
return queryInterface.addColumn('Notes', 'shortid', { return queryInterface.addColumn('Notes', 'shortid', {
type: Sequelize.STRING, type: Sequelize.STRING,
unique: true, defaultValue: '0000000000',
allowNull: false allowNull: false
}).then(function () {
return queryInterface.addIndex('Notes', ['shortid'], {
indicesType: 'UNIQUE'
})
}).then(function () { }).then(function () {
return queryInterface.addColumn('Notes', 'permission', { return queryInterface.addColumn('Notes', 'permission', {
type: Sequelize.STRING, type: Sequelize.STRING,
allowNull: false, defaultValue: 'private',
defaultValue: 0 allowNull: false
}) })
}).then(function () { }).then(function () {
return queryInterface.addColumn('Notes', 'viewcount', { return queryInterface.addColumn('Notes', 'viewcount', {
type: Sequelize.INTEGER type: Sequelize.INTEGER,
defaultValue: 0
}) })
}) })
}, },
@ -23,6 +28,9 @@ module.exports = {
.then(function () { .then(function () {
return queryInterface.removeColumn('Notes', 'permission') return queryInterface.removeColumn('Notes', 'permission')
}) })
.then(function () {
return queryInterface.removeIndex('Notes', ['shortid'])
})
.then(function () { .then(function () {
return queryInterface.removeColumn('Notes', 'shortid') return queryInterface.removeColumn('Notes', 'shortid')
}) })

View File

@ -3,12 +3,17 @@ module.exports = {
up: function (queryInterface, Sequelize) { up: function (queryInterface, Sequelize) {
return queryInterface.changeColumn('Notes', 'title', { return queryInterface.changeColumn('Notes', 'title', {
type: Sequelize.TEXT type: Sequelize.TEXT
}).then(function () {
// manual added index will be removed in sqlite
return queryInterface.addIndex('Notes', ['shortid'])
}) })
}, },
down: function (queryInterface, Sequelize) { down: function (queryInterface, Sequelize) {
return queryInterface.changeColumn('Notes', 'title', { return queryInterface.changeColumn('Notes', 'title', {
type: Sequelize.STRING type: Sequelize.STRING
}).then(function () {
return queryInterface.addIndex('Notes', ['shortid'])
}) })
} }
} }

View File

@ -2,12 +2,17 @@
module.exports = { module.exports = {
up: function (queryInterface, Sequelize) { up: function (queryInterface, Sequelize) {
return queryInterface.addColumn('Notes', 'alias', { return queryInterface.addColumn('Notes', 'alias', {
type: Sequelize.STRING, type: Sequelize.STRING
unique: true }).then(function () {
return queryInterface.addIndex('Notes', ['alias'], {
indicesType: 'UNIQUE'
})
}) })
}, },
down: function (queryInterface, Sequelize) { down: function (queryInterface, Sequelize) {
return queryInterface.removeColumn('Notes', 'alias') return queryInterface.removeColumn('Notes', 'alias').then(function () {
return queryInterface.removeIndex('Notes', ['alias'])
})
} }
} }