1.4.0 • Published 7 years ago

loopback-migration-tool v1.4.0

Weekly downloads
13
License
MIT
Repository
github
Last release
7 years ago

loopback-migration-tool

loopback-migration-tool expose the lb-migration script that ables you easy handle migrations and seeders for Loopback.io

Usage

Install Global

Install with Yarn

yarn global add loopback-migration-tool

or install with NPM

npm i -g loopback-migration-tool

Migrate all your models on all datasources.

lb-migration migrate

Migrate all your models on specific datasources.

lb-migration migrate --ds=datasource1 datasource2

Migrate specific models on specific datasources.

lb-migration migrate --ds=datasource1 datasource2 --model=model1 model2 model3

Migrate specific models using autoupdate method.

lb-migration migrate --model=model1 model2 model3 --method=update

Seed your models with files in ./seeds/*.js.

lb-migration seed

Seed your models with files in multiple locations.

lb-migration seed --src=path/to/files1/*.js path/to/files2/*.js path/to/files3/*.js  

Install as dev dependency

Install with Yarn

yarn add loopback-migration-tool --dev

or install with NPM

npm i loopback-migration-tool --save-dev

In your project root.

node_modules/.bin/lb-migration migrate [options] 

options

.lb-migrationrc.json

You can use a .lb-migrationrc.json to save your common migration settings.

Global options

PropertyDescriptionTypeValuesDefaultAs argument
appPath to your loopback applicationmain file.String./server/server.js-a --app --loopback-app

migrate

Important: Loopback's datasources uses two methods to migrate your models.

  • Auto-migration: Drop existing schema objects if they exist, and re-create them based on model definitions. Existing data will be lost.
  • Auto-update: Detect the difference between schema objects and model definitions, and alter the database schema objects. Keep existing data.

    Be careful what method must you use.

PropertyDescriptionTypeValuesDefaultAs argument
dsDatasources that will be migrated.If empty or not present, all datasources will be migrates.String, String[]-d --ds --datasource
modelModels in the selected datasourcesthat will be migrated. If empty or not present,all models in all selected datasources willbe migrates. Selected Models not presents inselected datasources will be not migrated.String[]--mod --model
ignored-modelModels in the selected datasourcesthat will be not migrated.String[]--imod --ignored-model
methodLoopback migration method to use.Loopback uses automigrate and autoupdate methodsfor migrations.Stringupdate migratemigrate-m --method

seed

Important: seed command will destroy all existing models' data calling to destroyAll method before start to seed them.

PropertyDescriptionTypeValuesDefaultAs argument
srcFile glob to your seeders files.String"./seeds/*.js"-s --src --sources

Seeder file

A seeder file is just a js module that exports a function where you fill your model's data. Seeder files are executed in lexicographic order.

The exported function receive a loopback-app instance as argument where you can find all the loopback app data, that includes the app.models object.

You can find a example here

./seeds/index.js

module.exports = function (app, cb) {
    let Travel = app.models.Travel

    let promises = _.map(data, function (entry) {
        let passengers = entry.passengers
        delete entry.passengers

        return Travel.create(entry)
            .then((travel) => travel.passengers.create(passengers))
    })

    return Promise.all(promises) //Or you can use cb argument when all is done, but not both.
}
1.4.0

7 years ago

1.3.4

7 years ago

1.3.3

7 years ago

1.3.2

7 years ago

1.3.1

7 years ago

1.3.0

7 years ago

1.2.2

7 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.0

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago

0.2.0

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago

0.0.14

7 years ago

0.0.13

7 years ago

0.0.11

7 years ago

0.0.10

7 years ago

0.0.9

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago