不要怂,就是干,撸起袖子干!

Commit f2cafcc4 by Diogo Simões Committed by Sushant

docs(migrations): added advanced skeleton example (#10190)

1 parent 946fb729
Showing with 28 additions and 1 deletions
......@@ -185,7 +185,7 @@ module.exports = {
up: (queryInterface, Sequelize) => {
// logic for transforming into the new state
},
 
down: (queryInterface, Sequelize) => {
// logic for reverting the changes
}
......@@ -212,6 +212,33 @@ module.exports = {
}
```
The following is an example of a migration that performs two changes in the database, using a transaction to ensure that all instructions are successfully executed or rolled back in case of failure:
```js
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.sequelize.transaction((t) => {
return Promise.all([
queryInterface.addColumn('Person', 'petName', {
type: Sequelize.STRING
}, { transaction: t }),
queryInterface.addColumn('Person', 'favoriteColor', {
type: Sequelize.STRING,
}, { transaction: t })
])
})
},
down: (queryInterface, Sequelize) => {
return queryInterface.sequelize.transaction((t) => {
return Promise.all([
queryInterface.removeColumn('Person', 'petName', { transaction: t }),
queryInterface.removeColumn('Person', 'favoriteColor', { transaction: t })
])
})
}
};
```
### The `.sequelizerc` File
This is a special configuration file. It lets you specify various options that you would usually pass as arguments to CLI. Some scenarios where you can use it.
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!