loopback-component-mongodb-mt-automigrate
Version:
Auto migrate with mongodb-mt connector
98 lines (93 loc) • 1.97 kB
Markdown
Auto migrate with mongodb-mt connector
Rum the command
`npm install loopback-component-mongodb-mt-automigrate`
or
´yarn add loopback-component-mongodb-mt-automigrate´
Required configurations to using this component
Need the loopback
```json
{
"routes:before": {
"loopback#token": {
"params": {
"model": "MyAccessTokenModel"
}
}
}
}
```
Add Models in `./server/model-config.json`
```json
{
"_meta": {
"sources": [
"../node_modules/loopback-component-mongodb-mt-automigrate/src/models"
]
},
"Automigrate": {
"dataSource": "db",
"public": false
}
}
```
Add `loopback-component-mongodb-mt-automigrate` in `./server/component-config.json`
```json
{
"./component/automigration": {
"method": "autoupdate",
"dataSource": "db",
"clustered": true,
"models": [
"MyModel",
]
}
}
```
* [method]: The method to automigration using:
* `autoupdate`: Update the model indexes without change the database data.
* `automigrate`: Migrate the model with cleaning the database data.
* [dataSource]: The data source to using in the migration.
* [models]: Models to migrate.
Use in yours models the `version` and `indexes` attributes like this:
```json
{
"name": "MyModel",
"base": "PersistedModel",
"idInjection": true,
"options": {
"validateUpsert": true
},
"indexes": {
"idx_foo": {
"keys": {
"foo": 1
}
},
},
"options": {
"validateUpsert": true
},
"version": 1,
"properties": {
"foo": {
"type": "string",
"required": true
},
"bar": {
"type": "boolean",
"default": true
}
},
"validations": [],
"relations": {},
"acls": [],
"methods": {}
}
```