From 6f14822413eeb43aae1298163699f87bc1ce11e7 Mon Sep 17 00:00:00 2001 From: BoHong Li Date: Mon, 27 Mar 2017 19:23:00 +0800 Subject: fix: Add missing migration --- lib/migrations/20150702001020-update-to-0_3_1.js | 30 ++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 lib/migrations/20150702001020-update-to-0_3_1.js (limited to 'lib/migrations/20150702001020-update-to-0_3_1.js') diff --git a/lib/migrations/20150702001020-update-to-0_3_1.js b/lib/migrations/20150702001020-update-to-0_3_1.js new file mode 100644 index 00000000..a3163d74 --- /dev/null +++ b/lib/migrations/20150702001020-update-to-0_3_1.js @@ -0,0 +1,30 @@ +'use strict' +module.exports = { + up: function (queryInterface, Sequelize) { + return queryInterface.addColumn('Notes', 'shortid', { + type: Sequelize.STRING, + unique: true, + allowNull: false + }).then(function () { + return queryInterface.addColumn('Notes', 'permission', { + type: Sequelize.STRING, + allowNull: false, + defaultValue: 0 + }) + }).then(function () { + return queryInterface.addColumn('Notes', 'viewcount', { + type: Sequelize.INTEGER + }) + }) + }, + + down: function (queryInterface, Sequelize) { + return queryInterface.removeColumn('Notes', 'viewcount') + .then(function () { + return queryInterface.removeColumn('Notes', 'permission') + }) + .then(function () { + return queryInterface.removeColumn('Notes', 'shortid') + }) + } +} -- cgit v1.2.3 From e26bb0503f962e1ee56dfa138b43af4653065812 Mon Sep 17 00:00:00 2001 From: BoHong Li Date: Tue, 28 Mar 2017 15:16:09 +0800 Subject: fix: Support SQlite Move 'unique' constraint to another statement (SQLite don't support set unique when addColumn) --- lib/migrations/20150702001020-update-to-0_3_1.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'lib/migrations/20150702001020-update-to-0_3_1.js') 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 }) }) }, @@ -23,6 +28,9 @@ module.exports = { .then(function () { return queryInterface.removeColumn('Notes', 'permission') }) + .then(function () { + return queryInterface.removeIndex('Notes', ['shortid']) + }) .then(function () { return queryInterface.removeColumn('Notes', 'shortid') }) -- cgit v1.2.3