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

Commit 1d6fa05c by Mike Committed by Sushant

docs(migrations): add async/await example (#11231)

1 parent 843a8b02
Showing with 51 additions and 0 deletions
...@@ -285,6 +285,57 @@ module.exports = { ...@@ -285,6 +285,57 @@ module.exports = {
``` ```
The next is an example of a migration that has uses async/await where you create an unique index on a new column:
```js
module.exports = {
async up(queryInterface, Sequelize) {
const transaction = await queryInterface.sequelize.transaction();
try {
await queryInterface.addColumn(
'Person',
'petName',
{
type: Sequelize.STRING,
},
{ transaction }
);
await queryInterface.addIndex(
'Person',
'petName',
{
fields: 'petName',
unique: true,
},
{ transaction }
);
await transaction.commit();
} catch (err) {
await transaction.rollback();
throw err;
}
},
async down(queryInterface, Sequelize) {
const transaction = await queryInterface.sequelize.transaction();
try {
await queryInterface.removeColumn(
'Person',
'petName',
{
type: Sequelize.STRING,
},
{ transaction }
);
await transaction.commit();
} catch (err) {
await transaction.rollback();
throw err;
}
},
};
```
### The `.sequelizerc` File ### 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. 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!