npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

loopback-migration-tool

v1.4.0

Published

A Loopback.io tool for easy handly db migrations and seeders

Downloads

75

Readme

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

| Property | Description | Type | Values | Default | As argument | |:--------: |:---------------------------------------------: |:------: |:------: |:--------------------: |:------------------------------------------------------------: | | app | Path 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.

| Property | Description | Type | Values | Default | As argument | |:----------: |:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |:---------------------: |:-----------------: |:-------: |:-----------------------------: | | ds |Datasources that will be migrated.If empty or not present, all datasources will be migrates. | String, [String] | | [] | -d --ds --datasource | | model |Models 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-model |Models in the selected datasourcesthat will be not migrated. | [String] | | [] | --imod --ignored-model | | method |Loopback migration method to use.Loopback uses automigrate and autoupdate methodsfor migrations. | String | update migrate | migrate | -m --method |

seed

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

| Property | Description | Type | Values | Default | As argument | |:--------: |:---------------------------------: |:-----------: |:------: |:----------------: |:-----------------------------: | | src | File 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.
}