summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBoHong Li2017-03-28 15:16:09 +0800
committerBoHong Li2017-03-28 15:16:09 +0800
commite26bb0503f962e1ee56dfa138b43af4653065812 (patch)
tree32703ec0cb7ad9050e107da9d2dff60f59554f16 /lib
parent6f14822413eeb43aae1298163699f87bc1ce11e7 (diff)
fix: Support SQlite
Move 'unique' constraint to another statement (SQLite don't support set unique when addColumn)
Diffstat (limited to '')
-rw-r--r--lib/migrations/20150702001020-update-to-0_3_1.js16
-rw-r--r--lib/migrations/20150915153700-change-notes-title-to-text.js5
-rw-r--r--lib/migrations/20160420180355-note-add-alias.js11
3 files changed, 25 insertions, 7 deletions
diff --git a/lib/migrations/20150702001020-update-to-0_3_1.js b/lib/migrations/20150702001020-update-to-0_3_1.js
index a3163d74..40d9c97a 100644
--- a/lib/migrations/20150702001020-update-to-0_3_1.js
+++ b/lib/migrations/20150702001020-update-to-0_3_1.js
@@ -3,17 +3,22 @@ module.exports = {
up: function (queryInterface, Sequelize) {
return queryInterface.addColumn('Notes', 'shortid', {
type: Sequelize.STRING,
- unique: true,
+ defaultValue: '0000000000',
allowNull: false
}).then(function () {
+ return queryInterface.addIndex('Notes', ['shortid'], {
+ indicesType: 'UNIQUE'
+ })
+ }).then(function () {
return queryInterface.addColumn('Notes', 'permission', {
type: Sequelize.STRING,
- allowNull: false,
- defaultValue: 0
+ defaultValue: 'private',
+ allowNull: false
})
}).then(function () {
return queryInterface.addColumn('Notes', 'viewcount', {
- type: Sequelize.INTEGER
+ type: Sequelize.INTEGER,
+ defaultValue: 0
})
})
},
@@ -24,6 +29,9 @@ module.exports = {
return queryInterface.removeColumn('Notes', 'permission')
})
.then(function () {
+ return queryInterface.removeIndex('Notes', ['shortid'])
+ })
+ .then(function () {
return queryInterface.removeColumn('Notes', 'shortid')
})
}
diff --git a/lib/migrations/20150915153700-change-notes-title-to-text.js b/lib/migrations/20150915153700-change-notes-title-to-text.js
index 6f7307d1..2b3a82bf 100644
--- a/lib/migrations/20150915153700-change-notes-title-to-text.js
+++ b/lib/migrations/20150915153700-change-notes-title-to-text.js
@@ -3,12 +3,17 @@ 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'])
})
},
down: function (queryInterface, Sequelize) {
return queryInterface.changeColumn('Notes', 'title', {
type: Sequelize.STRING
+ }).then(function () {
+ return queryInterface.addIndex('Notes', ['shortid'])
})
}
}
diff --git a/lib/migrations/20160420180355-note-add-alias.js b/lib/migrations/20160420180355-note-add-alias.js
index 2c3e453b..a043cd5c 100644
--- a/lib/migrations/20160420180355-note-add-alias.js
+++ b/lib/migrations/20160420180355-note-add-alias.js
@@ -2,12 +2,17 @@
module.exports = {
up: function (queryInterface, Sequelize) {
return queryInterface.addColumn('Notes', 'alias', {
- type: Sequelize.STRING,
- unique: true
+ type: Sequelize.STRING
+ }).then(function () {
+ return queryInterface.addIndex('Notes', ['alias'], {
+ indicesType: 'UNIQUE'
+ })
})
},
down: function (queryInterface, Sequelize) {
- return queryInterface.removeColumn('Notes', 'alias')
+ return queryInterface.removeColumn('Notes', 'alias').then(function () {
+ return queryInterface.removeIndex('Notes', ['alias'])
+ })
}
}