Last active
August 7, 2017 16:50
-
-
Save todgru/23832db8695ea768d68e04df0a83f675 to your computer and use it in GitHub Desktop.
sequelize migrations, make sure you handle the promises correctly!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
module.exports = { | |
up: function(queryInterface, Sequelize) { | |
// | |
// queryInterface methods DO return promises. Either of the following with work | |
// | |
// return queryInterface.addColumn(...) | |
// .then(() => queryInterface.doSomething(...)) | |
// etc. | |
// ... or this: | |
return Promise.resolve() | |
.then(() => queryInterface.addColumn("foo", "id", { | |
type: Sequelize.INTEGER, | |
autoIncrement: true, | |
}) | |
) | |
.then(() => queryInterface.removeConstraint("foo", "foo_pkey")) | |
.then(() => queryInterface.addConstraint("foo", ["id", "fooId"], { | |
type: "primary key", | |
name: "foo_pkey", | |
}) | |
) | |
.then(() => { | |
// this will also work | |
// multi line function | |
// ...doing work | |
}) | |
.then(/* this notation will not wait for execution of function */) | |
.then(() => /* but this notation will :) */); | |
}, | |
down: function(queryInterface, Sequelize) { | |
queryInterface.sequelize.query(); | |
}, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment