Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

json-migrator

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-migrator

define a json document to perform your database migrations

  • 1.0.0
  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

#Document Migrator

###Using the migrator

The migrator takes in two inputs

  • doc - the document to be modified by the migration
  • migrationPath - the file location of the migration (a JSON file)

###Migration format

The migration is an object with the following properties

  • target - which field on the document should updated by the migration
  • value - what should the 'target' field be updated with (can include references to other fields in the same document)
  • delete - delete this field (or fields) from the document (occurs AFTER the target field has been updated)

###Example

Your Migration (JSON Document)

{
  "target": "fullName",
  "value": ["Mr ",{"field": "firstName"}," ",{"field": "lastName"}],
  "delete": ["firstName", "lastName"]
}

The Code

//not yet published on NPM, assuming 'document-migrator' is the module name
var migrate = require('document-migrator').migrate;

var doc = {
  firstName: "Simon",
  lastName: "Taylor"
}

//the location of the file containing your migration JSON document (as above)
var migrationPath = './migrations/generate-fullname.json';

var result = migrate(doc, migrationPath);

//result === {fullName: "Mr Simon Taylor"}

Features to add

  • support for referencing nested properties using "."
  • support for multiple consecutive updates by passing an array
  • add support for other patterns i.e. split, maybe substring??
  • add safe fail for patterns (what if position does not exist)

FAQs

Package last updated on 20 Apr 2015

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