New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

js-migrations

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

js-migrations

Migrate a JavaScript object

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5
decreased by-44.44%
Maintainers
1
Weekly downloads
 
Created
Source

JavaScript Migrations

Installation

npm install js-migrations or kanso

Defining Migrations

A migration is an object with a version and one or both of up and down functions, which migrate up to, or down from this version respectively. For example:

var myMigration = {
  version: '1.2.5',
  up: function(obj, callback) {
    var num = parseInt(obj.a);
    if (isNaN(num)) {
      return { error: 'a is not a number' };
    } else {
      obj.a = num
      return { error: false, result: obj };
    }
  },
  down: function(obj, callback) {
    obj.a = obj.a + '';
    return { error: false, result: obj };
  }
};

Version should be unique between migrations or there will be no way to tell which set of migrations have been run.

Running Migrations

var migration = require('js-migrations');
var migrated = migration.migrate(
  { a: '42' },
  [ myMigration ],
  { from: '1.1.5', to: '2.1.3' }
);
if (migrated.err) throw migrated.err;
var obj = migrated.result;

If from or to is omitted above there will be no lower or upper limit respectively. If both are omitted all migrations will be run. If from is greater than to then the down migrations are run.

All versions must follow the semver format.

Build Status

Build Status

Keywords

FAQs

Package last updated on 21 May 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc