🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

db-migrate-boilerplate

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

db-migrate-boilerplate

Reduce the amount of boilerplate in your project needed to support raw SQL migrations using db-migrate.

1.0.0
latest
Source
npm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

db-migrate-boilerplate

Reduce the amount of boilerplate in your project needed to support raw SQL migrations using db-migrate.

Usage

Install via npm:

$ npm install db-migrate-boilerplate

Replace the default migration handler generated by db-migrate with this:

'use strict'

const path = require('path')
const boilerplate = require('db-migrate-boilerplate')

module.exports = boilerplate({
  // TODO replace with your correct paths
  upPath: path.join(__dirname, 'sqls', '20161226111110-test-up.sql'),
  downPath: path.join(__dirname, 'sqls', '20161226111110-test-down.sql')
})

Make sure to replace the paths with your expected values.

Why?

db-migrate generates a lot of boilerplate code when creating a raw SQL migration. Here is an example:

'use strict';

var dbm;
var type;
var seed;
var fs = require('fs');
var path = require('path');
var Promise;

/**
  * We receive the dbmigrate dependency from dbmigrate initially.
  * This enables us to not have to rely on NODE_PATH.
  */
exports.setup = function(options, seedLink) {
  dbm = options.dbmigrate;
  type = dbm.dataType;
  seed = seedLink;
  Promise = options.Promise;
};

exports.up = function(db) {
  var filePath = path.join(__dirname, 'sqls', '20161226111110-test-up.sql');
  return new Promise( function( resolve, reject ) {
    fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){
      if (err) return reject(err);
      console.log('received data: ' + data);

      resolve(data);
    });
  })
  .then(function(data) {
    return db.runSql(data);
  });
};

exports.down = function(db) {
  var filePath = path.join(__dirname, 'sqls', '20161226111110-test-down.sql');
  return new Promise( function( resolve, reject ) {
    fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){
      if (err) return reject(err);
      console.log('received data: ' + data);

      resolve(data);
    });
  })
  .then(function(data) {
    return db.runSql(data);
  });
};

exports._meta = {
  "version": 1
};

License

MIT

Keywords

db-migrate

FAQs

Package last updated on 02 Jan 2017

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