Exciting news!Announcing our $4.6M Series Seed. Learn more
Socket
LoveBlogFAQ
Install
Log in

loopback-component-migrate

Package Overview
Dependencies
4
Maintainers
1
Versions
13
Issues
File Explorer

Advanced tools

loopback-component-migrate

Migration framework for Loopback.

    0.4.0latest

Version published
Maintainers
1
Yearly downloads
11,960
decreased by-31.72%

Weekly downloads

Changelog

Source

v0.4.0

<a name"0.4.0"></a>

0.4.0 (2017-06-14)

Features

  • update to support both loopback 3.x and 2.x (d0c26e64)

Readme

Source

A library to add simple database migration support to loopback projects.

Dependencies

Migrations that have been run will be stored in a table called 'Migrations'. The library will read the loopback datasources.json files based on the NODE_ENV environment variable just like loopback does. The usage is based on the node-db-migrate project.

Installation

Greenkeeper badge

  1. Install in you loopback project:

npm install --save loopback-component-migrate

  1. Create a component-config.json file in your server folder (if you don't already have one)

  2. Enable the component inside component-config.json.

{ "loopback-component-migrate": { "key": "value" } }

Options:

  • log

    [String] : Name of the logging class to use for log messages. (default: 'console')

  • enableRest

    [Boolean] : A boolean indicating wether migrate/rollback REST api methods should be exposed on the Migration model. (default: false)

  • migrationsDir

    [String] : Directory containing migration scripts. (default: server/migrations)

  • dataSource

    [String] : Datasource to connect the Migration and MigrationMap models to. (default: db)

  • acls

    [Array] : ACLs to apply to Migration and MigrationMap models. (default: [])

Running Migrations

Migrations can be run by calling the static migrate method on the Migration model. If you do not specify a callback, a promise will be returned.

Run all pending migrations:

Migrate.migrate('up', function(err) {});

Run all pending migrations upto and including 0002-somechanges:

Migrate.migrate('up', '0002-somechanges', function(err) {});

Rollback all migrations:

Migrate.migrate('down', function(err) {});

Rollback migrations upto and including 0002-somechanges:

Migrate.migrate('down', '0002-somechanges', function(err) {});

Example migrations

module.exports = { up: function(app, next) { app.models.Users.create({ ... }, next); }, down: function(app, next) { app.models.Users.destroyAll({ ... }, next); } }; /* executing raw sql */ module.exports = { up: function(app, next) { app.dataSources.mysql.connector.query('CREATE TABLE `my_table` ...;', next); }, down: function(app, next) { app.dataSources.mysql.connector.query('DROP TABLE `my_table`;', next); } };

Keywords

Socket

Product

Subscribe to our newsletter

Get open source security insights delivered straight into your inbox. Be the first to learn about new features and product updates.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc