Socket
Socket
Sign inDemoInstall

loopback-component-migrate

Package Overview
Dependencies
428
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.3.4 to 0.3.5

test/fixtures/simple-app/server/component-config.json

55

lib/models/migration.js

@@ -66,3 +66,3 @@ 'use strict';

if (Migration.app.migrating) {
Migration.log.warn('Unable to start migration: already running');
Migration.log.warn('Migration: Unable to start migration (already running)');
process.nextTick(function() {

@@ -77,3 +77,3 @@ cb();

Migration.log.info(name, 'running.');
Migration.log.info('Migration: running script', name);
const scriptPath = path.resolve(path.join(Migration.migrationsDir, name));

@@ -83,7 +83,3 @@

require(scriptPath).up(Migration.app, function(err) {
if (err) {
Migration.log.error(`Error running migration script ${name}:`, err);
Migration.finish(err);
return cb(err);
} else if (record) {
if (record) {
Migration.create({

@@ -94,7 +90,7 @@ name: name,

}
Migration.finish();
cb();
Migration.finish(err);
return cb();
});
} catch (err) {
Migration.log.error(`Error running migration script ${name}:`, err);
Migration.log.error(`Migration: Error running script ${name}:`, err);
Migration.finish(err);

@@ -130,3 +126,3 @@ cb(err);

if (Migration.app.migrating) {
Migration.log.warn('Unable to start migrations: already running');
Migration.log.warn('Migration: Unable to start migrations (already running)');
process.nextTick(function() {

@@ -147,3 +143,3 @@ cb();

if (scriptsToRun.length) {
Migration.log.info('Running migrations: \n', scriptsToRun);
Migration.log.info('Migration: Running migration scripts', scriptsToRun);
}

@@ -159,4 +155,3 @@

if (err) {
Migration.log.error('Error saving migration', localScriptName, 'to database!');
Migration.log.error(err);
Migration.log.error('Migration: Error saving migration %s to database', localScriptName);
Migration.finish(err);

@@ -167,3 +162,3 @@ return cb(err);

var migrationEndTime = process.hrtime(migrationStartTime);
Migration.log.info('%s finished sucessfully. Migration time was %ds %dms',
Migration.log.info('Migration: %s finished sucessfully. Migration time was %ds %dms',
localScriptName, migrationEndTime[0], migrationEndTime[1] / 1000000);

@@ -174,3 +169,3 @@ migrationCallIndex++;

} else {
Migration.finish();
Migration.finish(err);
return cb();

@@ -183,8 +178,6 @@ }

migrationStartTime = process.hrtime();
Migration.log.info(localScriptName, 'running.');
Migration.log.info('Migration: Running script', localScriptName);
const scriptPath = path.resolve(path.join(Migration.migrationsDir, localScriptName));
require(scriptPath)[upOrDown](Migration.app, function(err) {
if (err) {
Migration.log.error(localScriptName, 'error:');
Migration.log.error(err.stack);
Migration.finish(err);

@@ -204,4 +197,2 @@ return cb(err);

} catch (err) {
Migration.log.error('Error running migration', localScriptName);
Migration.log.error(err.stack);
Migration.finish(err);

@@ -219,3 +210,3 @@ cb(err);

Migration.emit('complete');
Migration.log.info('No new migrations to run.');
Migration.log.info('Migration: No new migrations to run.');
return cb();

@@ -230,11 +221,6 @@ }

if (err) {
Migration.log.error('Migrations did not complete. An error was encountered:', err);
Migration.emit('error', err);
} else {
Migration.log.info('All migrations have run without any errors.');
Migration.emit('complete');
}
delete Migration.app.migrating;
var hrend = process.hrtime(Migration.hrstart);
Migration.log.info('Total migration time was %ds %dms', hrend[0], hrend[1] / 1000000);
};

@@ -337,4 +323,3 @@

.catch(function(err) {
Migration.log.error('Error retrieving migrations:');
Migration.log.error(err.stack);
Migration.log.error('Migration: Error retrieving migrations', err);
cb(err);

@@ -350,3 +335,15 @@ });

Migration.on('error', (err) => {
Migration.log.error('Migration: Migrations did not complete. An error was encountered:', err);
delete Migration.app.migrating;
});
Migration.on('complete', (err) => {
var hrend = process.hrtime(Migration.hrstart);
Migration.log.info('Migration: All migrations have run without any errors.');
Migration.log.info('Migration: Total migration time was %ds %dms', hrend[0], hrend[1] / 1000000);
delete Migration.app.migrating;
});
return Migration;
};
{
"name": "loopback-component-migrate",
"version": "0.3.4",
"version": "0.3.5",
"description": "Migration framework for Loopback.",

@@ -59,3 +59,3 @@ "author": {

"devDependencies": {
"bluebird": "latest",
"bluebird": "^3.5.0",
"chai": "latest",

@@ -62,0 +62,0 @@ "condition-circle": "^1.5.0",

@@ -5,5 +5,2 @@ {

"../common/models"
],
"mixins": [
"../../../../"
]

@@ -10,0 +7,0 @@ },

@@ -24,13 +24,2 @@ var loopback = require('loopback');

var migrate = require(path.join(__dirname, '..', '..', '..', '..', 'lib'));
var options = {
// dataSource: ds, // Data source for migrate data persistence,
migrationsDir: path.join(__dirname, 'migrations'), // Migrations directory.
enableRest: true
};
migrate(
app, // The app instance
options // The options
);
// Register explorer using component-centric API:

@@ -37,0 +26,0 @@ explorer(app, { basePath: '/api', mountPath: '/explorer' });

@@ -77,4 +77,4 @@ 'use strict';

// Delete all data after each test.
beforeEach(function(done) {
Promise.all([
beforeEach(function() {
return Promise.all([
app.models.Migration.destroyAll(),

@@ -84,5 +84,7 @@ app.models.Migration.destroyAll()

.then(function() {
done();
return app.models.Migration.create({
name: '0000-error.js',
runDtTm: new Date()
})
})
.catch(done);
});

@@ -102,6 +104,13 @@

});
it('should log errors', function() {
return app.models.Migration.migrateByName('0000-error.js')
.catch(function(err) {
expect(err).to.not.be.undefined;
})
});
});
describe('migrate', function() {
it('should set a property on app to indicate that migrations are running', function(done) {
it('should set a property on app to indicate that migrations are running', function() {
var self = this;

@@ -111,7 +120,5 @@ expect(app.migrating).to.be.undefined;

expect(app.migrating).to.be.true;
promise.then(function() {
return promise.then(function() {
expect(app.migrating).to.be.undefined;
done();
})
.catch(done);
});

@@ -121,5 +128,5 @@ });

describe('up', function() {
it('should run all migration scripts', function(done) {
it('should run all migration scripts', function() {
var self = this;
app.models.Migration.migrate()
return app.models.Migration.migrate()
.then(function() {

@@ -130,9 +137,7 @@ expect(self.spies.m1Up).to.have.been.called;

self.expectNoDown();
done();
})
.catch(done);
});
it('should run migrations up to the specificed point only', function(done) {
it('should run migrations up to the specificed point only', function() {
var self = this;
app.models.Migration.migrate('up', '0002-somechanges')
return app.models.Migration.migrate('up', '0002-somechanges')
.then(function() {

@@ -143,9 +148,7 @@ expect(self.spies.m1Up).to.have.been.calledBefore(self.spies.m2Up);

self.expectNoDown();
done();
})
.catch(done);
});
it('should not rerun migrations that hae already been run', function(done) {
it('should not rerun migrations that hae already been run', function() {
var self = this;
app.models.Migration.migrate('up', '0002-somechanges')
return app.models.Migration.migrate('up', '0002-somechanges')
.then(function() {

@@ -160,5 +163,3 @@ self.resetSpies();

self.expectNoDown();
done();
})
.catch(done);
});

@@ -168,5 +169,5 @@ });

describe('down', function() {
it('should run all rollback scripts in reverse order', function(done) {
it('should run all rollback scripts in reverse order', function() {
var self = this;
app.models.Migration.migrate('up')
return app.models.Migration.migrate('up')
.then(function() {

@@ -182,9 +183,7 @@ self.expectNoDown();

self.expectNoUp();
done();
})
.catch(done);
});
it('should run rollbacks up to the specificed point only', function(done) {
it('should run rollbacks up to the specificed point only', function() {
var self = this;
app.models.Migration.migrate('up')
return app.models.Migration.migrate('up')
.then(function() {

@@ -200,9 +199,7 @@ self.expectNoDown();

self.expectNoUp();
done();
})
.catch(done);
});
it('should not rerun rollbacks that hae already been run', function(done) {
it('should not rerun rollbacks that hae already been run', function() {
var self = this;
app.models.Migration.migrate('up')
return app.models.Migration.migrate('up')
.then(function() {

@@ -220,9 +217,7 @@ return app.models.Migration.migrate('down', '0001-initialize');

self.expectNoUp();
done();
})
.catch(done);
});
it('should rollback a single migration that has not already run', function(done) {
it('should rollback a single migration that has not already run', function() {
var self = this;
app.models.Migration.migrate('up', '0002-somechanges')
return app.models.Migration.migrate('up', '0002-somechanges')
.then(function() {

@@ -237,5 +232,3 @@ self.resetSpies();

self.expectNoUp();
done();
})
.catch(done);
});

@@ -242,0 +235,0 @@ });

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc