Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
public
/
sequelize
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
不要怂,就是干,撸起袖子干!
Commit 1d6fa05c
authored
Jul 27, 2019
by
Mike
Committed by
Sushant
Jul 27, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
docs(migrations): add async/await example (#11231)
1 parent
843a8b02
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
0 deletions
docs/migrations.md
docs/migrations.md
View file @
1d6fa05
...
...
@@ -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
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.
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment