loopback-component-mongodb-mt-automigrate

2.1.0 • Public • Published

loopback-component-mongodb-mt-automigrate

Auto migrate with mongodb-mt connector

Instalation

Rum the command npm install loopback-component-mongodb-mt-automigrate or ´yarn add loopback-component-mongodb-mt-automigrate´

Component configurations

Required configurations to using this component

middleware.json

Need the loopback#token middleware in ./server/middleware.json:

{
  "routes:before": {
    "loopback#token": {
      "params": {
        "model": "MyAccessTokenModel"
      }
    }
  }
}

model-config.json

Add Models in ./server/model-config.json

{
  "_meta": {
    "sources": [
      "../node_modules/loopback-component-mongodb-mt-automigrate/src/models"
    ]
  },
  "Automigrate": {
    "dataSource": "db",
    "public": false
  }
}

component-config.json

Add loopback-component-mongodb-mt-automigrate in ./server/component-config.json

{
  "./component/automigration": {
    "method": "autoupdate",
    "dataSource": "db",
    "clustered": true,
    "models": [
      "MyModel",
    ]
  }
}
    • autoupdate: Update the model indexes without change the database data.
    • automigrate: Migrate the model with cleaning the database data.

Models configurations

Use in yours models the version and indexes attributes like this:

{
  "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": {}
}

Package Sidebar

Install

npm i loopback-component-mongodb-mt-automigrate

Weekly Downloads

5

Version

2.1.0

License

MIT

Unpacked Size

7.88 kB

Total Files

8

Last publish

Collaborators

  • selfirius