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

node-mini-migrations

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-mini-migrations

A very small, lightweight and flexible migrations library unconcerned with what database you use

  • 0.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
31
increased by6.9%
Maintainers
1
Weekly downloads
 
Created
Source

Mini Migrator

A really simple node migrations library that is completly independant of any database or file system

Example Usage

You need to define a driver for example:

Setup

# migrations/driver.js
const fs = require('fs')

// db could be an instance of a database, like mysql, postgres, mongodb, or
// anything you want. It's just an object that gets passed to migrations.
const db = {
  tableCreate: (table) => {
    console.log('would create a table', table)
  },

  tableDrop: (table) => {
    console.log('would drop a table', table)
  },

  insert: (row) => {
    console.log('would insert a row', row)
  },

  remove: (row) => {
    console.log('would remove a row', row)
  }
}

module.exports = {
  init: () => {
    if (!fs.existsSync('test_state.json')) {
      fs.writeFileSync('test_state.json', JSON.stringify({}))
    }
  },

  get: (key) => {
    const state = JSON.parse(
      fs.readFileSync('test_state.json', 'utf8')
    )
    return state[key]
  },

  set: (key, value) => {
    const state = JSON.parse(
      fs.readFileSync('test_state.json', 'utf8')
    )
    state[key] = value
    fs.writeFileSync('test_state.json', JSON.stringify(state))
  },

  del: (key) => {
    const state = JSON.parse(
      fs.readFileSync('test_state.json', 'utf8')
    )
    delete state[key]
    fs.writeFileSync('test_state.json', JSON.stringify(state))
  },

  db
}

Migration files

You can then create typical migrations files like:

# migrations/1-my-migration-example.js
module.exports = {
  up: db => {
    return db.tableCreate('test_table')
  },

  down: db => {
    return db.tableDrop('test_table')
  }
}

Usage

You run migrator up to bring up any migrations or migrator down to bring them down.

License

This project is licensed under the terms of the GPLv3 license.

FAQs

Package last updated on 07 Mar 2019

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