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/20150504155329-create-users.js | 24 +++++++++++++++++ lib/migrations/20150508114741-create-notes.js | 21 +++++++++++++++ lib/migrations/20150515125813-create-temp.js | 18 +++++++++++++ lib/migrations/20150702001020-update-to-0_3_1.js | 30 ++++++++++++++++++++++ .../20150915153700-change-notes-title-to-text.js | 14 ++++++++++ .../20160112220142-note-add-lastchange.js | 19 ++++++++++++++ lib/migrations/20160420180355-note-add-alias.js | 13 ++++++++++ 7 files changed, 139 insertions(+) create mode 100644 lib/migrations/20150504155329-create-users.js create mode 100644 lib/migrations/20150508114741-create-notes.js create mode 100644 lib/migrations/20150515125813-create-temp.js create mode 100644 lib/migrations/20150702001020-update-to-0_3_1.js create mode 100644 lib/migrations/20150915153700-change-notes-title-to-text.js create mode 100644 lib/migrations/20160112220142-note-add-lastchange.js create mode 100644 lib/migrations/20160420180355-note-add-alias.js (limited to 'lib/migrations') diff --git a/lib/migrations/20150504155329-create-users.js b/lib/migrations/20150504155329-create-users.js new file mode 100644 index 00000000..51e6b29c --- /dev/null +++ b/lib/migrations/20150504155329-create-users.js @@ -0,0 +1,24 @@ +'use strict' +module.exports = { + up: function (queryInterface, Sequelize) { + return queryInterface.createTable('Users', { + id: { + type: Sequelize.UUID, + primaryKey: true, + defaultValue: Sequelize.UUIDV4 + }, + profileid: { + type: Sequelize.STRING, + unique: true + }, + profile: Sequelize.TEXT, + history: Sequelize.TEXT, + createdAt: Sequelize.DATE, + updatedAt: Sequelize.DATE + }) + }, + + down: function (queryInterface, Sequelize) { + return queryInterface.dropTable('Users') + } +} diff --git a/lib/migrations/20150508114741-create-notes.js b/lib/migrations/20150508114741-create-notes.js new file mode 100644 index 00000000..660d40a6 --- /dev/null +++ b/lib/migrations/20150508114741-create-notes.js @@ -0,0 +1,21 @@ +'use strict' +module.exports = { + up: function (queryInterface, Sequelize) { + return queryInterface.createTable('Notes', { + id: { + type: Sequelize.UUID, + primaryKey: true, + defaultValue: Sequelize.UUIDV4 + }, + ownerId: Sequelize.UUID, + content: Sequelize.TEXT, + title: Sequelize.STRING, + createdAt: Sequelize.DATE, + updatedAt: Sequelize.DATE + }) + }, + + down: function (queryInterface, Sequelize) { + return queryInterface.dropTable('Notes') + } +} diff --git a/lib/migrations/20150515125813-create-temp.js b/lib/migrations/20150515125813-create-temp.js new file mode 100644 index 00000000..ee7b9789 --- /dev/null +++ b/lib/migrations/20150515125813-create-temp.js @@ -0,0 +1,18 @@ +'use strict' +module.exports = { + up: function (queryInterface, Sequelize) { + return queryInterface.createTable('Temp', { + id: { + type: Sequelize.STRING, + primaryKey: true + }, + date: Sequelize.TEXT, + createdAt: Sequelize.DATE, + updatedAt: Sequelize.DATE + }) + }, + + down: function (queryInterface, Sequelize) { + return queryInterface.dropTable('Temp') + } +} 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') + }) + } +} diff --git a/lib/migrations/20150915153700-change-notes-title-to-text.js b/lib/migrations/20150915153700-change-notes-title-to-text.js new file mode 100644 index 00000000..6f7307d1 --- /dev/null +++ b/lib/migrations/20150915153700-change-notes-title-to-text.js @@ -0,0 +1,14 @@ +'use strict' +module.exports = { + up: function (queryInterface, Sequelize) { + return queryInterface.changeColumn('Notes', 'title', { + type: Sequelize.TEXT + }) + }, + + down: function (queryInterface, Sequelize) { + return queryInterface.changeColumn('Notes', 'title', { + type: Sequelize.STRING + }) + } +} diff --git a/lib/migrations/20160112220142-note-add-lastchange.js b/lib/migrations/20160112220142-note-add-lastchange.js new file mode 100644 index 00000000..b4e111b3 --- /dev/null +++ b/lib/migrations/20160112220142-note-add-lastchange.js @@ -0,0 +1,19 @@ +'use strict' +module.exports = { + up: function (queryInterface, Sequelize) { + return queryInterface.addColumn('Notes', 'lastchangeuserId', { + type: Sequelize.UUID + }).then(function () { + return queryInterface.addColumn('Notes', 'lastchangeAt', { + type: Sequelize.DATE + }) + }) + }, + + down: function (queryInterface, Sequelize) { + return queryInterface.removeColumn('Notes', 'lastchangeAt') + .then(function () { + return queryInterface.removeColumn('Notes', 'lastchangeuserId') + }) + } +} diff --git a/lib/migrations/20160420180355-note-add-alias.js b/lib/migrations/20160420180355-note-add-alias.js new file mode 100644 index 00000000..2c3e453b --- /dev/null +++ b/lib/migrations/20160420180355-note-add-alias.js @@ -0,0 +1,13 @@ +'use strict' +module.exports = { + up: function (queryInterface, Sequelize) { + return queryInterface.addColumn('Notes', 'alias', { + type: Sequelize.STRING, + unique: true + }) + }, + + down: function (queryInterface, Sequelize) { + return queryInterface.removeColumn('Notes', 'alias') + } +} -- 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 ++++++++++++---- .../20150915153700-change-notes-title-to-text.js | 5 +++++ lib/migrations/20160420180355-note-add-alias.js | 11 ++++++++--- 3 files changed, 25 insertions(+), 7 deletions(-) (limited to 'lib/migrations') 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') }) 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']) + }) } } -- cgit v1.2.3 From e46874d04a4974ddb655962b6da8afb2928bc991 Mon Sep 17 00:00:00 2001 From: BoHong Li Date: Tue, 28 Mar 2017 15:25:36 +0800 Subject: fix: Other dialect duplicated add index problem Detect is using SQLite to add index --- lib/migrations/20150915153700-change-notes-title-to-text.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'lib/migrations') diff --git a/lib/migrations/20150915153700-change-notes-title-to-text.js b/lib/migrations/20150915153700-change-notes-title-to-text.js index 2b3a82bf..9d00f15f 100644 --- a/lib/migrations/20150915153700-change-notes-title-to-text.js +++ b/lib/migrations/20150915153700-change-notes-title-to-text.js @@ -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']) + } }) } } -- cgit v1.2.3