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

nohm-migrations

Package Overview
Dependencies
Maintainers
2
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nohm-migrations - npm Package Compare versions

Comparing version 0.1.4 to 0.1.5

33

lib/nohm-migrations.js

@@ -9,12 +9,13 @@ var fs = require('fs');

function collectMigrations(client, versionKey, migrationsFolder, done) {
client.smembers(versionKey, function (err, migrations) {
function collectMigrations(client, key, folder, done) {
client.smembers(key, function (err, applied) {
if (err) {
return done(err);
}
fs.readdir(migrationsFolder, function (err, files) {
fs.readdir(folder, function (err, files) {
if (err) {
return done(err);
}
done(null, _.difference(files, migrations).sort());
var pending = _.difference(files, applied).sort();
done(null, pending);
});

@@ -24,6 +25,7 @@ });

function runMigrations(client, versionKey, migrationsFolder, nohm, done) {
log('Running migrations in ' + migrationsFolder + ' for environment ' + (process.env.NODE_ENV || 'development'));
function runMigrations(client, key, folder, nohm, done) {
var options = {nohm: nohm, client: client};
log('Running migrations in ' + folder + ' for environment ' + (process.env.NODE_ENV || 'development'));
collectMigrations(client, versionKey, migrationsFolder, function (err, migrationsToRun) {
collectMigrations(client, key, folder, function (err, migrationsToRun) {
if (err) {

@@ -43,3 +45,4 @@ return done(err);

var finished = false;
require(path.join(process.cwd(), migrationsFolder, file)).run(function (err) {
var migration = require(path.join(process.cwd(), folder, file));
migration.run.call(options, function (err) {
if (finished) {

@@ -55,3 +58,3 @@ log('ERROR! ' + file + ' called callback multiple times');

log('Done ' + file);
client.sadd(versionKey, file);
client.sadd(key, file);
nextMigration();

@@ -66,4 +69,4 @@ }

module.exports.migrate = function (key, redisPort, redisHost, prefix, nohm, done) {
var versionKey = key || 'migrations';
var migrationsFolder = versionKey;
key = key || 'migrations';
var folder = key;
done = done || function (err) {

@@ -77,3 +80,3 @@ if (err) {

if (nohm) {
runMigrations(nohm.client, versionKey, migrationsFolder, nohm, done);
runMigrations(nohm.client, key, folder, nohm, done);
} else {

@@ -83,3 +86,3 @@ var port = redisPort || 6379;

log('version key:', versionKey);
log('version key:', key);
log('redis port:', port);

@@ -95,4 +98,4 @@ log('redis host:', host);

runMigrations(client, versionKey, migrationsFolder, nohm, function (err) {
client.end();
runMigrations(client, key, folder, nohm, function (err) {
client.quit();
done(err);

@@ -99,0 +102,0 @@ });

@@ -5,3 +5,3 @@ {

"author": "Pulse Energy",
"version": "0.1.4",
"version": "0.1.5",
"repository": {

@@ -8,0 +8,0 @@ "type": "git",

@@ -1,3 +0,3 @@

exports.run = function (done, nohm) {
nohm.client.rpush('nohm-migrations-test-key', 'first', done);
exports.run = function (done) {
this.client.rpush('nohm-migrations-test-key', 'first', done);
};

@@ -23,5 +23,5 @@ var assert = require('assert');

assert.deepEqual(values, ['first', 'second']);
client.end();
client.quit();
});
});
});
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