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

Commit 62f19114 by Valetek Committed by papb

docs(migrations): add example for conditional unique index (#12578)

Co-authored-by: Valentin Almeida--Lemaire <valentin.almeida@onrewind.com>
Co-authored-by: Pedro Augusto de Paula Barbosa <papb1996@gmail.com>
1 parent 45ec1a22
Showing with 29 additions and 2 deletions
......@@ -330,6 +330,34 @@ module.exports = {
};
```
The next example is of a migration that creates an unique index composed of multiple fields with a condition, which allows a relation to exist multiple times but only one can satisfy the condition:
```js
module.exports = {
up: (queryInterface, Sequelize) => {
queryInterface.createTable('Person', {
name: Sequelize.DataTypes.STRING,
bool: {
type: Sequelize.DataTypes.BOOLEAN,
defaultValue: false
}
}).then((queryInterface, Sequelize) => {
queryInterface.addIndex(
'Person',
['name', 'bool'],
{
indicesType: 'UNIQUE',
where: { bool : 'true' },
}
);
});
},
down: (queryInterface, Sequelize) => {
return queryInterface.dropTable('Person');
}
}
```
### The `.sequelizerc` file
This is a special configuration file. It lets you specify the following options that you would usually pass as arguments to CLI:
......@@ -534,4 +562,4 @@ npx sequelize-cli db:migrate --url 'mysql://root:password@mysql_host.com/databas
### Programmatic usage
Sequelize has a sister library called [umzug](https://github.com/sequelize/umzug) for programmatically handling execution and logging of migration tasks.
\ No newline at end of file
Sequelize has a sister library called [umzug](https://github.com/sequelize/umzug) for programmatically handling execution and logging of migration tasks.
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!