fix: Fixed sequelize-cli db:migration cannot stop when occur error

Up and Down method must return a Promise.

breaking changes: docker-hackmd cannot initialize, because db:migration will fail
This commit is contained in:
BoHong Li 2017-03-24 11:24:44 +08:00
parent cdd8a72d04
commit 66fc817ad4
5 changed files with 51 additions and 41 deletions

View file

@ -1,12 +1,14 @@
'use strict' 'use strict'
module.exports = { module.exports = {
up: function (queryInterface, Sequelize) { up: function (queryInterface, Sequelize) {
queryInterface.addColumn('Users', 'accessToken', Sequelize.STRING) return queryInterface.addColumn('Users', 'accessToken', Sequelize.STRING).then(function () {
queryInterface.addColumn('Users', 'refreshToken', Sequelize.STRING) return queryInterface.addColumn('Users', 'refreshToken', Sequelize.STRING)
})
}, },
down: function (queryInterface, Sequelize) { down: function (queryInterface, Sequelize) {
queryInterface.removeColumn('Users', 'accessToken') return queryInterface.removeColumn('Users', 'accessToken').then(function () {
queryInterface.removeColumn('Users', 'refreshToken') return queryInterface.removeColumn('Users', 'refreshToken')
})
} }
} }

View file

@ -1,24 +1,26 @@
'use strict' 'use strict'
module.exports = { module.exports = {
up: function (queryInterface, Sequelize) { up: function (queryInterface, Sequelize) {
queryInterface.addColumn('Notes', 'savedAt', Sequelize.DATE) return queryInterface.addColumn('Notes', 'savedAt', Sequelize.DATE).then(function () {
queryInterface.createTable('Revisions', { return queryInterface.createTable('Revisions', {
id: { id: {
type: Sequelize.UUID, type: Sequelize.UUID,
primaryKey: true primaryKey: true
}, },
noteId: Sequelize.UUID, noteId: Sequelize.UUID,
patch: Sequelize.TEXT, patch: Sequelize.TEXT,
lastContent: Sequelize.TEXT, lastContent: Sequelize.TEXT,
content: Sequelize.TEXT, content: Sequelize.TEXT,
length: Sequelize.INTEGER, length: Sequelize.INTEGER,
createdAt: Sequelize.DATE, createdAt: Sequelize.DATE,
updatedAt: Sequelize.DATE updatedAt: Sequelize.DATE
})
}) })
}, },
down: function (queryInterface, Sequelize) { down: function (queryInterface, Sequelize) {
queryInterface.dropTable('Revisions') return queryInterface.dropTable('Revisions').then(function () {
queryInterface.removeColumn('Notes', 'savedAt') return queryInterface.removeColumn('Notes', 'savedAt')
})
} }
} }

View file

@ -1,25 +1,29 @@
'use strict' 'use strict'
module.exports = { module.exports = {
up: function (queryInterface, Sequelize) { up: function (queryInterface, Sequelize) {
queryInterface.addColumn('Notes', 'authorship', Sequelize.TEXT) return queryInterface.addColumn('Notes', 'authorship', Sequelize.TEXT).then(function () {
queryInterface.addColumn('Revisions', 'authorship', Sequelize.TEXT) return queryInterface.addColumn('Revisions', 'authorship', Sequelize.TEXT)
queryInterface.createTable('Authors', { }).then(function () {
id: { return queryInterface.createTable('Authors', {
type: Sequelize.INTEGER, id: {
primaryKey: true, type: Sequelize.INTEGER,
autoIncrement: true primaryKey: true,
}, autoIncrement: true
color: Sequelize.STRING, },
noteId: Sequelize.UUID, color: Sequelize.STRING,
userId: Sequelize.UUID, noteId: Sequelize.UUID,
createdAt: Sequelize.DATE, userId: Sequelize.UUID,
updatedAt: Sequelize.DATE createdAt: Sequelize.DATE,
updatedAt: Sequelize.DATE
})
}) })
}, },
down: function (queryInterface, Sequelize) { down: function (queryInterface, Sequelize) {
queryInterface.dropTable('Authors') return queryInterface.dropTable('Authors').then(function () {
queryInterface.removeColumn('Revisions', 'authorship') return queryInterface.removeColumn('Revisions', 'authorship')
queryInterface.removeColumn('Notes', 'authorship') }).then(function () {
return queryInterface.removeColumn('Notes', 'authorship')
})
} }
} }

View file

@ -1,10 +1,10 @@
'use strict' 'use strict'
module.exports = { module.exports = {
up: function (queryInterface, Sequelize) { up: function (queryInterface, Sequelize) {
queryInterface.addColumn('Notes', 'deletedAt', Sequelize.DATE) return queryInterface.addColumn('Notes', 'deletedAt', Sequelize.DATE)
}, },
down: function (queryInterface, Sequelize) { down: function (queryInterface, Sequelize) {
queryInterface.removeColumn('Notes', 'deletedAt') return queryInterface.removeColumn('Notes', 'deletedAt')
} }
} }

View file

@ -1,12 +1,14 @@
'use strict' 'use strict'
module.exports = { module.exports = {
up: function (queryInterface, Sequelize) { up: function (queryInterface, Sequelize) {
queryInterface.addColumn('Users', 'email', Sequelize.TEXT) return queryInterface.addColumn('Users', 'email', Sequelize.TEXT).then(function () {
queryInterface.addColumn('Users', 'password', Sequelize.TEXT) return queryInterface.addColumn('Users', 'password', Sequelize.TEXT)
})
}, },
down: function (queryInterface, Sequelize) { down: function (queryInterface, Sequelize) {
queryInterface.removeColumn('Users', 'email') return queryInterface.removeColumn('Users', 'email').then(function () {
queryInterface.removeColumn('Users', 'password') return queryInterface.removeColumn('Users', 'password')
})
} }
} }