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

umzug

Package Overview
Dependencies
Maintainers
3
Versions
70
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

umzug - npm Package Compare versions

Comparing version 2.1.0 to 2.2.0

docker-compose.yml

5

.eslintrc.json

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

"rules": {
"prefer-arrow-callback": "error",
"prefer-const": "error",
"arrow-body-style": ["error", "as-needed"],
"no-var": "error",

@@ -29,2 +32,2 @@ "comma-dangle": [

}
}
}
# Change Log
All notable changes to this project will be documented in this file.
## v2.2.0 - 2018-11-18
### Added
- feat: support passing an array of Migrations
[#164](https://github.com/sequelize/umzug/pull/164)
### Changed
- Doc fixes
[#155](https://github.com/sequelize/umzug/pull/155)
- Add support for coffeescript 2
[#157](https://github.com/sequelize/umzug/pull/157)
- throw error if a migration method doesn't return a thenable
[#158](https://github.com/sequelize/umzug/pull/158)
- Update README.md with respect to MongoDBStorage
[#165](https://github.com/sequelize/umzug/pull/165)
- fix multiple jsdoc lines related to MongoDBStorage
[#174](https://github.com/sequelize/umzug/pull/174)
- clarify up/down migrations "to" option
[#176](https://github.com/sequelize/umzug/pull/176)
- Test isolation by using different sqlite databases in each testsuite
[#180](https://github.com/sequelize/umzug/pull/180)
## v2.1.0 - 2017-10-23
### Added
- Ability to traverse sub directories
[#80](https://github.com/sequelize/umzug/pull/80)
## v2.0.0 - 2017-05-10

@@ -5,0 +33,0 @@ ### Added

8

lib/helper.js

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

'use strict';
"use strict";
var _resolve2 = require('resolve');
module.exports = {

@@ -14,6 +12,6 @@ /**

resolve: function resolve(packageName) {
var result = void 0;
let result;
try {
result = (0, _resolve2.sync)(packageName, { basedir: process.cwd() });
result = require.resolve(packageName, { basedir: process.cwd() });
result = require(result);

@@ -20,0 +18,0 @@ } catch (e) {

'use strict';
var _keys = require('babel-runtime/core-js/object/keys');
var _keys2 = _interopRequireDefault(_keys);
var _extends2 = require('babel-runtime/helpers/extends');

@@ -7,26 +11,2 @@

var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _createClass2 = require('babel-runtime/helpers/createClass');
var _createClass3 = _interopRequireDefault(_createClass2);
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
var _inherits2 = require('babel-runtime/helpers/inherits');
var _inherits3 = _interopRequireDefault(_inherits2);
var _lodash = require('lodash');
var _lodash2 = _interopRequireDefault(_lodash);
var _bluebird = require('bluebird');

@@ -72,5 +52,3 @@

*/
module.exports = function (_EventEmitter) {
(0, _inherits3.default)(Umzug, _EventEmitter);
module.exports = class Umzug extends _events.EventEmitter {
/**

@@ -81,3 +59,3 @@ * Constructs Umzug instance.

* @param {String} [options.storage='json'] - The storage. Possible values:
* 'json', 'sequelize', an argument for `require()`, including absolute paths.
* 'json', 'sequelize', 'mongodb', an argument for `require()`, including absolute paths.
* @param {function|false} [options.logging=false] - The logging function.

@@ -91,3 +69,4 @@ * A function that gets executed every time migrations start and have ended.

* Check the available storages for further details.
* @param {Object} [options.migrations] -
* @param {Object|Array} [options.migrations] - options for loading migration
* files, or (advanced) an array of Migration instances
* @param {Array} [options.migrations.params] - The params that gets passed to

@@ -109,9 +88,6 @@ * the migrations. Might be an array or a synchronous function which returns

*/
function Umzug() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
(0, _classCallCheck3.default)(this, Umzug);
constructor(options = {}) {
super();
var _this = (0, _possibleConstructorReturn3.default)(this, (Umzug.__proto__ || (0, _getPrototypeOf2.default)(Umzug)).call(this));
_this.options = (0, _extends3.default)({
this.options = (0, _extends3.default)({
storage: 'json',

@@ -124,18 +100,17 @@ storageOptions: {},

if (_this.options.logging && !_lodash2.default.isFunction(_this.options.logging)) {
if (this.options.logging && typeof this.options.logging !== 'function') {
throw new Error('The logging-option should be either a function or false');
}
_this.options.migrations = (0, _extends3.default)({
params: [],
path: _path2.default.resolve(process.cwd(), 'migrations'),
pattern: /^\d+[\w-]+\.js$/,
traverseDirectories: false,
wrap: function wrap(fun) {
return fun;
}
}, _this.options.migrations);
if (!Array.isArray(this.options.migrations)) {
this.options.migrations = (0, _extends3.default)({
params: [],
path: _path2.default.resolve(process.cwd(), 'migrations'),
pattern: /^\d+[\w-]+\.js$/,
traverseDirectories: false,
wrap: fun => fun
}, this.options.migrations);
}
_this.storage = _this._initStorage();
return _this;
this.storage = this._initStorage();
}

@@ -151,533 +126,447 @@

*/
execute(options = {}) {
const self = this;
options = (0, _extends3.default)({
migrations: [],
method: 'up'
}, options);
(0, _createClass3.default)(Umzug, [{
key: 'execute',
value: function execute() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
return _bluebird2.default.map(options.migrations, migration => self._findMigration(migration)).then(migrations => (0, _extends3.default)({}, options, {
migrations
})).then(options => _bluebird2.default.each(options.migrations, migration => {
const name = _path2.default.basename(migration.file, _path2.default.extname(migration.file));
let startTime;
return self._wasExecuted(migration).catch(() => false).then(executed => typeof executed === 'undefined' ? true : executed).tap(executed => {
if (!executed || options.method === 'down') {
const fun = migration[options.method] || _bluebird2.default.resolve;
let params = self.options.migrations.params;
var self = this;
if (typeof params === 'function') {
params = params();
}
options = (0, _extends3.default)({
migrations: [],
method: 'up'
}, options);
if (options.method === 'up') {
self.log('== ' + name + ': migrating =======');
self.emit('migrating', name, migration);
} else {
self.log('== ' + name + ': reverting =======');
self.emit('reverting', name, migration);
}
return _bluebird2.default.map(options.migrations, function (migration) {
return self._findMigration(migration);
}).then(function (migrations) {
return (0, _extends3.default)({}, options, {
migrations
});
}).then(function (options) {
return _bluebird2.default.each(options.migrations, function (migration) {
var name = _path2.default.basename(migration.file, _path2.default.extname(migration.file));
var startTime = void 0;
return self._wasExecuted(migration).catch(function () {
return false;
}).then(function (executed) {
return typeof executed === 'undefined' ? true : executed;
}).tap(function (executed) {
if (!executed || options.method === 'down') {
var fun = migration[options.method] || _bluebird2.default.resolve;
var params = self.options.migrations.params;
startTime = new Date();
if (typeof params === 'function') {
params = params();
}
return fun.apply(migration, params);
}
}).then(executed => {
if (!executed && options.method === 'up') {
return _bluebird2.default.resolve(self.storage.logMigration(migration.file));
} else if (options.method === 'down') {
return _bluebird2.default.resolve(self.storage.unlogMigration(migration.file));
}
}).tap(() => {
const duration = ((new Date() - startTime) / 1000).toFixed(3);
if (options.method === 'up') {
self.log('== ' + name + ': migrated (' + duration + 's)\n');
self.emit('migrated', name, migration);
} else {
self.log('== ' + name + ': reverted (' + duration + 's)\n');
self.emit('reverted', name, migration);
}
});
}));
}
if (options.method === 'up') {
self.log('== ' + name + ': migrating =======');
self.emit('migrating', name, migration);
} else {
self.log('== ' + name + ': reverting =======');
self.emit('reverting', name, migration);
}
/**
* Lists executed migrations.
*
* @returns {Promise.<Migration>}
*/
executed() {
return _bluebird2.default.resolve(this.storage.executed()).bind(this).map(file => new _migration3.default(file));
}
startTime = new Date();
/**
* Lists pending migrations.
*
* @returns {Promise.<Migration[]>}
*/
pending() {
return this._findMigrations().bind(this).then(function (all) {
return _bluebird2.default.join(all, this.executed());
}).spread((all, executed) => {
const executedFiles = executed.map(migration => migration.file);
return fun.apply(migration, params);
}
}).then(function (executed) {
if (!executed && options.method === 'up') {
return _bluebird2.default.resolve(self.storage.logMigration(migration.file));
} else if (options.method === 'down') {
return _bluebird2.default.resolve(self.storage.unlogMigration(migration.file));
}
}).tap(function () {
var duration = ((new Date() - startTime) / 1000).toFixed(3);
if (options.method === 'up') {
self.log('== ' + name + ': migrated (' + duration + 's)\n');
self.emit('migrated', name, migration);
} else {
self.log('== ' + name + ': reverted (' + duration + 's)\n');
self.emit('reverted', name, migration);
}
});
});
return all.filter(migration => executedFiles.indexOf(migration.file) === -1);
});
}
/**
* Execute migrations up.
*
* If options is a migration name (String), it will be executed.
* If options is a list of migration names (String[]), them will be executed.
* If options is Object:
* - { from: 'migration-1', to: 'migration-n' } - execute migrations in range.
* - { migrations: [] } - execute migrations in array.
*
* @param {String|String[]|Object} options
* @param {String} [options.from] - The first migration to execute (exc).
* @param {String} [options.to] - The last migration to execute (inc).
* @param {String[]} [options.migrations] - List of migrations to execute.
* @returns {Promise}
*/
up(options) {
return this._run('up', options, this.pending.bind(this));
}
/**
* Execute migrations down.
*
* If options is a migration name (String), it will be executed.
* If options is a list of migration names (String[]), them will be executed.
* If options is Object:
* - { from: 'migration-n', to: 'migration-1' } - execute migrations in range.
* - { migrations: [] } - execute migrations in array.
*
* @param {String|String[]|Object} options
* @param {String} [options.from] - The first migration to execute (exc).
* @param {String} [options.to] - The last migration to execute (inc).
* @param {String[]} [options.migrations] - List of migrations to execute.
* @returns {Promise}
*/
down(options) {
const getExecuted = function () {
return this.executed().bind(this).then(migrations => migrations.reverse());
}.bind(this);
if (typeof options === 'undefined' || !(0, _keys2.default)(options).length) {
return getExecuted().bind(this).then(function (migrations) {
return migrations[0] ? this.down(migrations[0].file) : _bluebird2.default.resolve([]);
});
} else {
return this._run('down', options, getExecuted.bind(this));
}
}
/**
* Lists executed migrations.
*
* @returns {Promise.<Migration>}
*/
/**
* Callback function to get migrations in right order.
*
* @callback Umzug~rest
* @return {Promise.<Migration[]>}
*/
}, {
key: 'executed',
value: function executed() {
return _bluebird2.default.resolve(this.storage.executed()).bind(this).map(function (file) {
return new _migration3.default(file);
/**
* Execute migrations either down or up.
*
* If options is a migration name (String), it will be executed.
* If options is a list of migration names (String[]), them will be executed.
* If options is Object:
* - { from: 'migration-1', to: 'migration-n' } - execute migrations in range.
* - { migrations: [] } - execute migrations in array.
*
* @param {String} method - Method to run. Either 'up' or 'down'.
* @param {String|String[]|Object} options
* @param {String} [options.from] - The first migration to execute (exc).
* @param {String} [options.to] - The last migration to execute (inc).
* @param {String[]} [options.migrations] - List of migrations to execute.
* @param {Umzug~rest} [rest] - Function to get migrations in right order.
* @returns {Promise}
* @private
*/
_run(method, options, rest) {
if (typeof options === 'string') {
return this._run(method, [options]);
} else if (Array.isArray(options)) {
return _bluebird2.default.resolve(options).bind(this).map(function (migration) {
return this._findMigration(migration);
}).then(function (migrations) {
return method === 'up' ? this._arePending(migrations) : this._wereExecuted(migrations);
}).then(function () {
return this._run(method, { migrations: options });
});
}
/**
* Lists pending migrations.
*
* @returns {Promise.<Migration[]>}
*/
options = (0, _extends3.default)({
to: null,
from: null,
migrations: null
}, options || {});
}, {
key: 'pending',
value: function pending() {
return this._findMigrations().bind(this).then(function (all) {
return _bluebird2.default.join(all, this.executed());
}).spread(function (all, executed) {
var executedFiles = executed.map(function (migration) {
return migration.file;
});
if (options.migrations) {
return this.execute({
migrations: options.migrations,
method: method
});
} else {
return rest().bind(this).then(function (migrations) {
let result = _bluebird2.default.resolve().bind(this);
return all.filter(function (migration) {
return executedFiles.indexOf(migration.file) === -1;
});
if (options.to) {
result = result.then(function () {
// There must be a migration matching to options.to...
return this._findMigration(options.to);
}).then(function (migration) {
// ... and it must be pending/executed.
return method === 'up' ? this._isPending(migration) : this._wasExecuted(migration);
});
}
return result.then(() => _bluebird2.default.resolve(migrations));
}).then(function (migrations) {
if (options.from) {
return this._findMigrationsFromMatch(options.from, method);
} else {
return migrations;
}
}).then(function (migrations) {
return this._findMigrationsUntilMatch(options.to, migrations);
}).then(function (migrationFiles) {
return this._run(method, { migrations: migrationFiles });
});
}
}
/**
* Execute migrations up.
*
* If options is a migration name (String), it will be executed.
* If options is a list of migration names (String[]), them will be executed.
* If options is Object:
* - { from: 'migration-1', to: 'migration-n' } - execute migrations in range.
* - { migrations: [] } - execute migrations in array.
*
* @param {String|String[]|Object} options
* @param {String} [options.from] - The first migration to execute (exc).
* @param {String} [options.to] - The last migration to execute (inc).
* @param {String[]} [options.migrations] - List of migrations to execute.
* @returns {Promise}
*/
/**
* Lists pending/executed migrations depending on method from a given
* migration excluding it.
*
* @param {String} from - Migration name to be searched.
* @param {String} method - Either 'up' or 'down'. If method is 'up', only
* pending migrations will be accepted. Otherwise only executed migrations
* will be accepted.
* @returns {Promise.<Migration[]>}
* @private
*/
_findMigrationsFromMatch(from, method) {
// We'll fetch all migrations and work our way from start to finish
return this._findMigrations().bind(this).then(migrations => {
let found = false;
return migrations.filter(migration => {
if (migration.testFileName(from)) {
found = true;
return false;
}
return found;
});
}).filter(function (fromMigration) {
// now check if they need to be run based on status and method
return this._wasExecuted(fromMigration).then(() => {
if (method === 'up') {
return false;
} else {
return true;
}
}).catch(() => {
if (method === 'up') {
return true;
} else {
return false;
}
});
});
}
}, {
key: 'up',
value: function up(options) {
return this._run('up', options, this.pending.bind(this));
/**
* Pass message to logger if logging is enabled.
*
* @param {*} message - Message to be logged.
*/
log(message) {
if (this.options.logging) {
this.options.logging(message);
}
}
/**
* Execute migrations down.
*
* If options is a migration name (String), it will be executed.
* If options is a list of migration names (String[]), them will be executed.
* If options is Object:
* - { from: 'migration-n', to: 'migration-1' } - execute migrations in range.
* - { migrations: [] } - execute migrations in array.
*
* @param {String|String[]|Object} options
* @param {String} [options.from] - The first migration to execute (exc).
* @param {String} [options.to] - The last migration to execute (inc).
* @param {String[]} [options.migrations] - List of migrations to execute.
* @returns {Promise}
*/
/**
* Try to require and initialize storage.
*
* @returns {*|SequelizeStorage|JSONStorage|MongoDBStorage|Storage}
* @private
*/
_initStorage() {
if (typeof this.options.storage !== 'string') {
return this.options.storage;
}
}, {
key: 'down',
value: function down(options) {
var getExecuted = function () {
return this.executed().bind(this).then(function (migrations) {
return migrations.reverse();
});
}.bind(this);
let StorageClass;
try {
StorageClass = this._getStorageClass();
} catch (e) {
throw new Error('Unable to resolve the storage: ' + this.options.storage + ', ' + e);
}
if (typeof options === 'undefined' || _lodash2.default.isEqual(options, {})) {
return getExecuted().bind(this).then(function (migrations) {
return migrations[0] ? this.down(migrations[0].file) : _bluebird2.default.resolve([]);
});
} else {
return this._run('down', options, getExecuted.bind(this));
}
let storage = new StorageClass(this.options.storageOptions);
if (storage && storage.options && storage.options.storageOptions) {
console.warn('Deprecated: Umzug Storage constructor has changed!', 'old syntax: new Storage({ storageOptions: { ... } })', 'new syntax: new Storage({ ... })', 'where ... represents the same storageOptions passed to Umzug constructor.', 'For more information: https://github.com/sequelize/umzug/pull/137');
storage = new StorageClass(this.options);
}
/**
* Callback function to get migrations in right order.
*
* @callback Umzug~rest
* @return {Promise.<Migration[]>}
*/
return storage;
}
/**
* Execute migrations either down or up.
*
* If options is a migration name (String), it will be executed.
* If options is a list of migration names (String[]), them will be executed.
* If options is Object:
* - { from: 'migration-1', to: 'migration-n' } - execute migrations in range.
* - { migrations: [] } - execute migrations in array.
*
* @param {String} method - Method to run. Either 'up' or 'down'.
* @param {String|String[]|Object} options
* @param {String} [options.from] - The first migration to execute (exc).
* @param {String} [options.to] - The last migration to execute (inc).
* @param {String[]} [options.migrations] - List of migrations to execute.
* @param {Umzug~rest} [rest] - Function to get migrations in right order.
* @returns {Promise}
* @private
*/
_getStorageClass() {
switch (this.options.storage) {
case 'none':
return _Storage2.default;
case 'json':
return _JSONStorage2.default;
case 'mongodb':
return _MongoDBStorage2.default;
case 'sequelize':
return _SequelizeStorage2.default;
default:
return require(this.options.storage);
}
}
}, {
key: '_run',
value: function _run(method, options, rest) {
if (typeof options === 'string') {
return this._run(method, [options]);
} else if (Array.isArray(options)) {
return _bluebird2.default.resolve(options).bind(this).map(function (migration) {
return this._findMigration(migration);
}).then(function (migrations) {
return method === 'up' ? this._arePending(migrations) : this._wereExecuted(migrations);
}).then(function () {
return this._run(method, { migrations: options });
});
/**
* Loads all migrations in ascending order.
*
* @returns {Promise.<Migration[]>}
* @private
*/
_findMigrations(migrationPath) {
if (Array.isArray(this.options.migrations)) {
return _bluebird2.default.resolve(this.options.migrations);
}
const isRoot = !migrationPath;
if (isRoot) {
migrationPath = this.options.migrations.path;
}
return _bluebird2.default.promisify(_fs2.default.readdir)(migrationPath).bind(this).map(function (file) {
const filePath = _path2.default.resolve(migrationPath, file);
if (this.options.migrations.traverseDirectories) {
if (_fs2.default.lstatSync(filePath).isDirectory()) {
return this._findMigrations(filePath).then(migrations => migrations);
}
}
options = (0, _extends3.default)({
to: null,
from: null,
migrations: null
}, options || {});
if (options.migrations) {
return this.execute({
migrations: options.migrations,
method: method
});
} else {
return rest().bind(this).then(function (migrations) {
var result = _bluebird2.default.resolve().bind(this);
if (options.to) {
result = result.then(function () {
// There must be a migration matching to options.to...
return this._findMigration(options.to);
}).then(function (migration) {
// ... and it must be pending/executed.
return method === 'up' ? this._isPending(migration) : this._wasExecuted(migration);
});
}
return result.then(function () {
return _bluebird2.default.resolve(migrations);
});
}).then(function (migrations) {
if (options.from) {
return this._findMigrationsFromMatch(options.from, method);
} else {
return migrations;
}
}).then(function (migrations) {
return this._findMigrationsUntilMatch(options.to, migrations);
}).then(function (migrationFiles) {
return this._run(method, { migrations: migrationFiles });
});
if (this.options.migrations.pattern.test(file)) {
return new _migration3.default(filePath, this.options);
}
}
/**
* Lists pending/executed migrations depending on method from a given
* migration excluding it.
*
* @param {String} from - Migration name to be searched.
* @param {String} method - Either 'up' or 'down'. If method is 'up', only
* pending migrations will be accepted. Otherwise only executed migrations
* will be accepted.
* @returns {Promise.<Migration[]>}
* @private
*/
}, {
key: '_findMigrationsFromMatch',
value: function _findMigrationsFromMatch(from, method) {
// We'll fetch all migrations and work our way from start to finish
return this._findMigrations().bind(this).then(function (migrations) {
var found = false;
return migrations.filter(function (migration) {
if (migration.testFileName(from)) {
found = true;
return false;
}
return found;
});
}).filter(function (fromMigration) {
// now check if they need to be run based on status and method
return this._wasExecuted(fromMigration).then(function () {
if (method === 'up') {
return false;
this.log('File: ' + file + ' does not match pattern: ' + this.options.migrations.pattern);
return file;
}).reduce((a, b) => a.concat(b), []) // flatten the result to an array
.filter(file => file instanceof _migration3.default // only care about Migration
).then(migrations => {
if (isRoot) {
// only sort if its root
return migrations.sort((a, b) => {
if (a.file > b.file) {
return 1;
} else if (a.file < b.file) {
return -1;
} else {
return true;
return 0;
}
}).catch(function () {
if (method === 'up') {
return true;
} else {
return false;
}
});
});
}
/**
* Pass message to logger if logging is enabled.
*
* @param {*} message - Message to be logged.
*/
}, {
key: 'log',
value: function log(message) {
if (this.options.logging) {
this.options.logging(message);
}
}
return migrations;
});
}
/**
* Try to require and initialize storage.
*
* @returns {*|SequelizeStorage|JSONStorage|Storage}
* @private
*/
}, {
key: '_initStorage',
value: function _initStorage() {
if (typeof this.options.storage !== 'string') {
return this.options.storage;
/**
* Gets a migration with a given name.
*
* @param {String} needle - Name of the migration.
* @returns {Promise.<Migration>}
* @private
*/
_findMigration(needle) {
return this._findMigrations().then(migrations => migrations.filter(migration => migration.testFileName(needle))[0]).then(migration => {
if (migration) {
return migration;
} else {
return _bluebird2.default.reject(new Error('Unable to find migration: ' + needle));
}
});
}
var StorageClass = void 0;
try {
StorageClass = this._getStorageClass();
} catch (e) {
throw new Error('Unable to resolve the storage: ' + this.options.storage + ', ' + e);
/**
* Checks if migration is executed. It will success if and only if there is
* an executed migration with a given name.
*
* @param {String} _migration - Name of migration to be checked.
* @returns {Promise}
* @private
*/
_wasExecuted(_migration) {
return this.executed().filter(migration => migration.testFileName(_migration.file)).then(migrations => {
if (migrations[0]) {
return _bluebird2.default.resolve();
} else {
return _bluebird2.default.reject(new Error('Migration was not executed: ' + _migration.file));
}
});
}
var storage = new StorageClass(this.options.storageOptions);
if (_lodash2.default.has(storage, 'options.storageOptions')) {
console.warn('Deprecated: Umzug Storage constructor has changed!', 'old syntax: new Storage({ storageOptions: { ... } })', 'new syntax: new Storage({ ... })', 'where ... represents the same storageOptions passed to Umzug constructor.', 'For more information: https://github.com/sequelize/umzug/pull/137');
storage = new StorageClass(this.options);
}
/**
* Checks if a list of migrations are all executed. It will success if and
* only if there is an executed migration for each given name.
*
* @param {String[]} migrationNames - List of migration names to be checked.
* @returns {Promise}
* @private
*/
_wereExecuted(migrationNames) {
return _bluebird2.default.resolve(migrationNames).bind(this).map(function (migration) {
return this._wasExecuted(migration);
});
}
return storage;
}
}, {
key: '_getStorageClass',
value: function _getStorageClass() {
switch (this.options.storage) {
case 'none':
return _Storage2.default;
case 'json':
return _JSONStorage2.default;
case 'mongodb':
return _MongoDBStorage2.default;
case 'sequelize':
return _SequelizeStorage2.default;
default:
return require(this.options.storage);
/**
* Checks if migration is pending. It will success if and only if there is
* a pending migration with a given name.
*
* @param {String} _migration - Name of migration to be checked.
* @returns {Promise}
* @private
*/
_isPending(_migration) {
return this.pending().filter(migration => migration.testFileName(_migration.file)).then(migrations => {
if (migrations[0]) {
return _bluebird2.default.resolve();
} else {
return _bluebird2.default.reject(new Error('Migration is not pending: ' + _migration.file));
}
}
});
}
/**
* Loads all migrations in ascending order.
*
* @returns {Promise.<Migration[]>}
* @private
*/
/**
* Checks if a list of migrations are all pending. It will success if and only
* if there is a pending migration for each given name.
*
* @param {String[]} migrationNames - List of migration names to be checked.
* @returns {Promise}
* @private
*/
_arePending(migrationNames) {
return _bluebird2.default.resolve(migrationNames).bind(this).map(function (migration) {
return this._isPending(migration);
});
}
}, {
key: '_findMigrations',
value: function _findMigrations(migrationPath) {
var isRoot = !migrationPath;
if (isRoot) {
migrationPath = this.options.migrations.path;
}
return _bluebird2.default.promisify(_fs2.default.readdir)(migrationPath).bind(this).map(function (file) {
var filePath = _path2.default.resolve(migrationPath, file);
if (this.options.migrations.traverseDirectories) {
if (_fs2.default.lstatSync(filePath).isDirectory()) {
return this._findMigrations(filePath).then(function (migrations) {
return migrations;
});
}
}
if (this.options.migrations.pattern.test(file)) {
return new _migration3.default(filePath, this.options);
}
this.log('File: ' + file + ' does not match pattern: ' + this.options.migrations.pattern);
return file;
}).reduce(function (a, b) {
return a.concat(b);
}, []) // flatten the result to an array
.filter(function (file) {
return file instanceof _migration3.default; // only care about Migration
}).then(function (migrations) {
if (isRoot) {
// only sort if its root
return migrations.sort(function (a, b) {
if (a.file > b.file) {
return 1;
} else if (a.file < b.file) {
return -1;
} else {
return 0;
}
});
}
return migrations;
});
}
/**
* Skip migrations in a given migration list after `to` migration.
*
* @param {String} to - The last one migration to be accepted.
* @param {Migration[]} migrations - Migration list to be filtered.
* @returns {Promise.<String>} - List of migrations before `to`.
* @private
*/
_findMigrationsUntilMatch(to, migrations) {
return _bluebird2.default.resolve(migrations).map(migration => migration.file).reduce((acc, migration) => {
if (acc.add) {
acc.migrations.push(migration);
/**
* Gets a migration with a given name.
*
* @param {String} needle - Name of the migration.
* @returns {Promise.<Migration>}
* @private
*/
}, {
key: '_findMigration',
value: function _findMigration(needle) {
return this._findMigrations().then(function (migrations) {
return migrations.filter(function (migration) {
return migration.testFileName(needle);
})[0];
}).then(function (migration) {
if (migration) {
return migration;
} else {
return _bluebird2.default.reject(new Error('Unable to find migration: ' + needle));
if (to && migration.indexOf(to) === 0) {
// Stop adding the migrations once the final migration
// has been added.
acc.add = false;
}
});
}
}
/**
* Checks if migration is executed. It will success if and only if there is
* an executed migration with a given name.
*
* @param {String} _migration - Name of migration to be checked.
* @returns {Promise}
* @private
*/
}, {
key: '_wasExecuted',
value: function _wasExecuted(_migration) {
return this.executed().filter(function (migration) {
return migration.testFileName(_migration.file);
}).then(function (migrations) {
if (migrations[0]) {
return _bluebird2.default.resolve();
} else {
return _bluebird2.default.reject(new Error('Migration was not executed: ' + _migration.file));
}
});
}
/**
* Checks if a list of migrations are all executed. It will success if and
* only if there is an executed migration for each given name.
*
* @param {String[]} migrationNames - List of migration names to be checked.
* @returns {Promise}
* @private
*/
}, {
key: '_wereExecuted',
value: function _wereExecuted(migrationNames) {
return _bluebird2.default.resolve(migrationNames).bind(this).map(function (migration) {
return this._wasExecuted(migration);
});
}
/**
* Checks if migration is pending. It will success if and only if there is
* a pending migration with a given name.
*
* @param {String} _migration - Name of migration to be checked.
* @returns {Promise}
* @private
*/
}, {
key: '_isPending',
value: function _isPending(_migration) {
return this.pending().filter(function (migration) {
return migration.testFileName(_migration.file);
}).then(function (migrations) {
if (migrations[0]) {
return _bluebird2.default.resolve();
} else {
return _bluebird2.default.reject(new Error('Migration is not pending: ' + _migration.file));
}
});
}
/**
* Checks if a list of migrations are all pending. It will success if and only
* if there is a pending migration for each given name.
*
* @param {String[]} migrationNames - List of migration names to be checked.
* @returns {Promise}
* @private
*/
}, {
key: '_arePending',
value: function _arePending(migrationNames) {
return _bluebird2.default.resolve(migrationNames).bind(this).map(function (migration) {
return this._isPending(migration);
});
}
/**
* Skip migrations in a given migration list after `to` migration.
*
* @param {String} to - The last one migration to be accepted.
* @param {Migration[]} migrations - Migration list to be filtered.
* @returns {Promise.<String>} - List of migrations before `to`.
* @private
*/
}, {
key: '_findMigrationsUntilMatch',
value: function _findMigrationsUntilMatch(to, migrations) {
return _bluebird2.default.resolve(migrations).map(function (migration) {
return migration.file;
}).reduce(function (acc, migration) {
if (acc.add) {
acc.migrations.push(migration);
if (to && migration.indexOf(to) === 0) {
// Stop adding the migrations once the final migration
// has been added.
acc.add = false;
}
}
return acc;
}, { migrations: [], add: true }).get('migrations');
}
}]);
return Umzug;
}(_events.EventEmitter);
return acc;
}, { migrations: [], add: true }).get('migrations');
}
};
'use strict';
var _regenerator = require('babel-runtime/regenerator');
var _regenerator2 = _interopRequireDefault(_regenerator);
var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator');

@@ -11,10 +7,2 @@

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _createClass2 = require('babel-runtime/helpers/createClass');
var _createClass3 = _interopRequireDefault(_createClass2);
var _path2 = require('path');

@@ -33,3 +21,3 @@

*/
module.exports = function () {
module.exports = class Migration {
/**

@@ -61,5 +49,3 @@ * Wrapper function for migration methods.

*/
function Migration(path, options) {
(0, _classCallCheck3.default)(this, Migration);
constructor(path, options) {
this.path = _path3.default.resolve(path);

@@ -78,119 +64,79 @@ this.file = _path3.default.basename(this.path);

*/
(0, _createClass3.default)(Migration, [{
key: 'migration',
value: function migration() {
if (typeof this.options.migrations.customResolver === 'function') {
return this.options.migrations.customResolver(this.path);
}
if (this.path.match(/\.coffee$/)) {
// 1.7.x compiler registration
_helper2.default.resolve('coffee-script/register') ||
// Prior to 1.7.x compiler registration
_helper2.default.resolve('coffee-script') ||
/* jshint expr: true */
function () {
console.error('You have to add "coffee-script" to your package.json.');
process.exit(1);
}();
}
return require(this.path);
migration() {
if (typeof this.options.migrations.customResolver === 'function') {
return this.options.migrations.customResolver(this.path);
}
if (this.path.match(/\.coffee$/)) {
// 2.x compiler registration
_helper2.default.resolve('coffeescript/register') ||
/**
* Executes method `up` of migration.
*
* @returns {Promise}
*/
// 1.7.x compiler registration
_helper2.default.resolve('coffee-script/register') ||
}, {
key: 'up',
value: function up() {
return this._exec(this.options.upName, [].slice.apply(arguments));
// Prior to 1.7.x compiler registration
_helper2.default.resolve('coffee-script') ||
/* jshint expr: true */
function () {
console.error('You have to add "coffee-script" to your package.json.');
process.exit(1);
}();
}
/**
* Executes method `down` of migration.
*
* @returns {Promise}
*/
return require(this.path);
}
}, {
key: 'down',
value: function down() {
return this._exec(this.options.downName, [].slice.apply(arguments));
}
/**
* Executes method `up` of migration.
*
* @returns {Promise}
*/
up() {
return this._exec(this.options.upName, [].slice.apply(arguments));
}
/**
* Check if migration file name is starting with needle.
* @param {String} needle - The beginning of the file name.
* @returns {boolean}
*/
/**
* Executes method `down` of migration.
*
* @returns {Promise}
*/
down() {
return this._exec(this.options.downName, [].slice.apply(arguments));
}
}, {
key: 'testFileName',
value: function testFileName(needle) {
return this.file.indexOf(needle) === 0;
}
/**
* Check if migration file name is starting with needle.
* @param {String} needle - The beginning of the file name.
* @returns {boolean}
*/
testFileName(needle) {
return this.file.indexOf(needle) === 0;
}
/**
* Executes a given method of migration with given arguments.
*
* @param {String} method - Name of the method to be called.
* @param {*} args - Arguments to be used when called the method.
* @returns {Promise}
* @private
*/
/**
* Executes a given method of migration with given arguments.
*
* @param {String} method - Name of the method to be called.
* @param {*} args - Arguments to be used when called the method.
* @returns {Promise}
* @private
*/
_exec(method, args) {
var _this = this;
}, {
key: '_exec',
value: function () {
var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(method, args) {
var migration, fun, wrappedFun;
return _regenerator2.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.next = 2;
return this.migration();
case 2:
migration = _context.sent;
fun = migration[method];
if (migration.default) {
fun = migration.default[method] || migration[method];
}
if (fun) {
_context.next = 7;
break;
}
throw new Error('Could not find migration method: ' + method);
case 7:
wrappedFun = this.options.migrations.wrap(fun);
_context.next = 10;
return wrappedFun.apply(migration, args);
case 10:
case 'end':
return _context.stop();
}
}
}, _callee, this);
}));
function _exec(_x, _x2) {
return _ref.apply(this, arguments);
return (0, _asyncToGenerator3.default)(function* () {
const migration = yield _this.migration();
let fun = migration[method];
if (migration.default) {
fun = migration.default[method] || migration[method];
}
if (!fun) throw new Error('Could not find migration method: ' + method);
const wrappedFun = _this.options.migrations.wrap(fun);
const result = wrappedFun.apply(migration, args);
if (!result || typeof result.then !== 'function') {
throw new Error(`Migration ${_this.file} (or wrapper) didn't return a promise`);
}
return _exec;
}()
}]);
return Migration;
}();
yield result;
})();
}
};

@@ -11,26 +11,2 @@ 'use strict';

var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _createClass2 = require('babel-runtime/helpers/createClass');
var _createClass3 = _interopRequireDefault(_createClass2);
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
var _inherits2 = require('babel-runtime/helpers/inherits');
var _inherits3 = _interopRequireDefault(_inherits2);
var _lodash = require('lodash');
var _lodash2 = _interopRequireDefault(_lodash);
var _bluebird = require('bluebird');

@@ -48,5 +24,5 @@

var _Storage2 = require('./Storage');
var _Storage = require('./Storage');
var _Storage3 = _interopRequireDefault(_Storage2);
var _Storage2 = _interopRequireDefault(_Storage);

@@ -58,5 +34,3 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

*/
var JSONStorage = function (_Storage) {
(0, _inherits3.default)(JSONStorage, _Storage);
class JSONStorage extends _Storage2.default {
/**

@@ -69,13 +43,5 @@ * Constructs JSON file storage.

*/
function JSONStorage() {
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
_ref$path = _ref.path,
path = _ref$path === undefined ? _path3.default.resolve(process.cwd(), 'umzug.json') : _ref$path;
(0, _classCallCheck3.default)(this, JSONStorage);
var _this = (0, _possibleConstructorReturn3.default)(this, (JSONStorage.__proto__ || (0, _getPrototypeOf2.default)(JSONStorage)).call(this));
_this.path = path;
return _this;
constructor({ path = _path3.default.resolve(process.cwd(), 'umzug.json') } = {}) {
super();
this.path = path;
}

@@ -89,67 +55,42 @@

*/
logMigration(migrationName) {
const filePath = this.path;
const readfile = _bluebird2.default.promisify(_fs2.default.readFile);
const writefile = _bluebird2.default.promisify(_fs2.default.writeFile);
return readfile(filePath).catch(() => '[]').then(content => JSON.parse(content)).then(content => {
content.push(migrationName);
return writefile(filePath, (0, _stringify2.default)(content, null, ' '));
});
}
(0, _createClass3.default)(JSONStorage, [{
key: 'logMigration',
value: function logMigration(migrationName) {
var filePath = this.path;
var readfile = _bluebird2.default.promisify(_fs2.default.readFile);
var writefile = _bluebird2.default.promisify(_fs2.default.writeFile);
/**
* Unlogs migration to be considered as pending.
*
* @param {String} migrationName - Name of the migration to be unlogged.
* @returns {Promise}
*/
unlogMigration(migrationName) {
const filePath = this.path;
const readfile = _bluebird2.default.promisify(_fs2.default.readFile);
const writefile = _bluebird2.default.promisify(_fs2.default.writeFile);
return readfile(filePath).catch(function () {
return '[]';
}).then(function (content) {
return JSON.parse(content);
}).then(function (content) {
content.push(migrationName);
return writefile(filePath, (0, _stringify2.default)(content, null, ' '));
});
}
return readfile(filePath).catch(() => '[]').then(content => JSON.parse(content)).then(content => {
content = content.filter(m => m !== migrationName);
return writefile(filePath, (0, _stringify2.default)(content, null, ' '));
});
}
/**
* Unlogs migration to be considered as pending.
*
* @param {String} migrationName - Name of the migration to be unlogged.
* @returns {Promise}
*/
/**
* Gets list of executed migrations.
*
* @returns {Promise.<String[]>}
*/
executed() {
const filePath = this.path;
const readfile = _bluebird2.default.promisify(_fs2.default.readFile);
}, {
key: 'unlogMigration',
value: function unlogMigration(migrationName) {
var filePath = this.path;
var readfile = _bluebird2.default.promisify(_fs2.default.readFile);
var writefile = _bluebird2.default.promisify(_fs2.default.writeFile);
return readfile(filePath).catch(function () {
return '[]';
}).then(function (content) {
return JSON.parse(content);
}).then(function (content) {
content = _lodash2.default.without(content, migrationName);
return writefile(filePath, (0, _stringify2.default)(content, null, ' '));
});
}
/**
* Gets list of executed migrations.
*
* @returns {Promise.<String[]>}
*/
}, {
key: 'executed',
value: function executed() {
var filePath = this.path;
var readfile = _bluebird2.default.promisify(_fs2.default.readFile);
return readfile(filePath).catch(function () {
return '[]';
}).then(function (content) {
return JSON.parse(content);
});
}
}]);
return JSONStorage;
}(_Storage3.default);
return readfile(filePath).catch(() => '[]').then(content => JSON.parse(content));
}
}
exports.default = JSONStorage;

@@ -7,113 +7,65 @@ 'use strict';

var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');
var _Storage = require('./Storage');
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
var _Storage2 = _interopRequireDefault(_Storage);
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _createClass2 = require('babel-runtime/helpers/createClass');
var _createClass3 = _interopRequireDefault(_createClass2);
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
var _inherits2 = require('babel-runtime/helpers/inherits');
var _inherits3 = _interopRequireDefault(_inherits2);
var _lodash = require('lodash');
var _lodash2 = _interopRequireDefault(_lodash);
var _Storage2 = require('./Storage');
var _Storage3 = _interopRequireDefault(_Storage2);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* @class JSONStorage
* @class MongoDBStorage
*/
var MongoDBStorage = function (_Storage) {
(0, _inherits3.default)(MongoDBStorage, _Storage);
class MongoDBStorage extends _Storage2.default {
/**
* Constructs MongoDB collection storage.
*
* @param {Object} [options]
* Required either connection and collectionName OR collection
* @param {String} [options.connection] - a connection to target database established with MongoDB Driver
* @param {String} [options.collectionName] - name of migration collection in MongoDB
* @param {String} [options.collection] - reference to a MongoDB Driver collection
*/
function MongoDBStorage(_ref) {
var connection = _ref.connection,
collectionName = _ref.collectionName,
collection = _ref.collection;
(0, _classCallCheck3.default)(this, MongoDBStorage);
* Constructs MongoDB collection storage.
*
* @param {Object} [options]
* Required either connection and collectionName OR collection
* @param {String} [options.connection] - a connection to target database established with MongoDB Driver
* @param {String} [options.collectionName] - name of migration collection in MongoDB
* @param {String} [options.collection] - reference to a MongoDB Driver collection
*/
constructor({ connection, collectionName, collection }) {
super();
this.connection = connection;
this.collection = collection;
this.collectionName = collectionName || 'migrations';
var _this = (0, _possibleConstructorReturn3.default)(this, (MongoDBStorage.__proto__ || (0, _getPrototypeOf2.default)(MongoDBStorage)).call(this));
_this.connection = connection;
_this.collection = collection;
_this.collectionName = collectionName || 'migrations';
if (!_this.connection && !_this.collection) {
if (!this.connection && !this.collection) {
throw new Error('MongoDB Connection or Collection required');
}
if (!_this.collection) {
_this.collection = _this.connection.collection(_this.collectionName);
if (!this.collection) {
this.collection = this.connection.collection(this.collectionName);
}
return _this;
}
/**
* Logs migration to be considered as executed.
*
* @param {String} migrationName - Name of the migration to be logged.
* @returns {Promise}
*/
* Logs migration to be considered as executed.
*
* @param {String} migrationName - Name of the migration to be logged.
* @returns {Promise}
*/
logMigration(migrationName) {
return this.collection.insertOne({ migrationName });
}
/**
* Unlogs migration to be considered as pending.
*
* @param {String} migrationName - Name of the migration to be unlogged.
* @returns {Promise}
*/
unlogMigration(migrationName) {
return this.collection.removeOne({ migrationName });
}
(0, _createClass3.default)(MongoDBStorage, [{
key: 'logMigration',
value: function logMigration(migrationName) {
return this.collection.insertOne({ migrationName });
}
/**
* Unlogs migration to be considered as pending.
*
* @param {String} migrationName - Name of the migration to be unlogged.
* @returns {Promise}
*/
}, {
key: 'unlogMigration',
value: function unlogMigration(migrationName) {
return this.collection.removeOne({ migrationName });
}
/**
* Gets list of executed migrations.
*
* @returns {Promise.<String[]>}
*/
}, {
key: 'executed',
value: function executed() {
return this.collection.find({}).sort({ migrationName: 1 }).toArray().then(function (records) {
return _lodash2.default.map(records, 'migrationName');
});
}
}]);
return MongoDBStorage;
}(_Storage3.default);
/**
* Gets list of executed migrations.
*
* @returns {Promise.<String[]>}
*/
executed() {
return this.collection.find({}).sort({ migrationName: 1 }).toArray().then(records => records.map(r => r.migrationName));
}
}
exports.default = MongoDBStorage;

@@ -7,26 +7,6 @@ 'use strict';

var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');
var _Storage = require('./Storage');
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
var _Storage2 = _interopRequireDefault(_Storage);
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _createClass2 = require('babel-runtime/helpers/createClass');
var _createClass3 = _interopRequireDefault(_createClass2);
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
var _inherits2 = require('babel-runtime/helpers/inherits');
var _inherits3 = _interopRequireDefault(_inherits2);
var _Storage2 = require('./Storage');
var _Storage3 = _interopRequireDefault(_Storage2);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -37,5 +17,3 @@

*/
var SequelizeStorage = function (_Storage) {
(0, _inherits3.default)(SequelizeStorage, _Storage);
class SequelizeStorage extends _Storage2.default {
/**

@@ -74,20 +52,13 @@ * Constructs Sequelize based storage.

*/
function SequelizeStorage() {
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
sequelize = _ref.sequelize,
model = _ref.model,
_ref$modelName = _ref.modelName,
modelName = _ref$modelName === undefined ? 'SequelizeMeta' : _ref$modelName,
tableName = _ref.tableName,
schema = _ref.schema,
_ref$columnName = _ref.columnName,
columnName = _ref$columnName === undefined ? 'name' : _ref$columnName,
columnType = _ref.columnType,
_ref$timestamps = _ref.timestamps,
timestamps = _ref$timestamps === undefined ? false : _ref$timestamps;
(0, _classCallCheck3.default)(this, SequelizeStorage);
var _this = (0, _possibleConstructorReturn3.default)(this, (SequelizeStorage.__proto__ || (0, _getPrototypeOf2.default)(SequelizeStorage)).call(this));
constructor({
sequelize,
model,
modelName = 'SequelizeMeta',
tableName,
schema,
columnName = 'name',
columnType,
timestamps = false
} = {}) {
super();
if (!model && !sequelize) {

@@ -97,122 +68,98 @@ throw new Error('One of "sequelize" or "model" storage option is required');

_this.sequelize = sequelize || model.sequelize;
this.sequelize = sequelize || model.sequelize;
var Sequelize = _this.sequelize.constructor;
const Sequelize = this.sequelize.constructor;
_this.columnType = columnType || Sequelize.STRING;
_this.columnName = columnName;
_this.timestamps = timestamps;
_this.modelName = modelName;
_this.tableName = tableName;
_this.schema = schema;
_this.model = model || _this.getModel();
return _this;
this.columnType = columnType || Sequelize.STRING;
this.columnName = columnName;
this.timestamps = timestamps;
this.modelName = modelName;
this.tableName = tableName;
this.schema = schema;
this.model = model || this.getModel();
}
(0, _createClass3.default)(SequelizeStorage, [{
key: 'getModel',
value: function getModel() {
if (this.sequelize.isDefined(this.modelName)) {
return this.sequelize.model(this.modelName);
}
return this.sequelize.define(this.modelName, {
[this.columnName]: {
type: this.columnType,
allowNull: false,
unique: true,
primaryKey: true,
autoIncrement: false
}
}, {
tableName: this.tableName,
schema: this.schema,
timestamps: this.timestamps,
charset: 'utf8',
collate: 'utf8_unicode_ci'
});
getModel() {
if (this.sequelize.isDefined(this.modelName)) {
return this.sequelize.model(this.modelName);
}
/**
* Logs migration to be considered as executed.
*
* @param {String} migrationName - Name of the migration to be logged.
* @returns {Promise}
*/
return this.sequelize.define(this.modelName, {
[this.columnName]: {
type: this.columnType,
allowNull: false,
unique: true,
primaryKey: true,
autoIncrement: false
}
}, {
tableName: this.tableName,
schema: this.schema,
timestamps: this.timestamps,
charset: 'utf8',
collate: 'utf8_unicode_ci'
});
}
}, {
key: 'logMigration',
value: function logMigration(migrationName) {
var self = this;
/**
* Logs migration to be considered as executed.
*
* @param {String} migrationName - Name of the migration to be logged.
* @returns {Promise}
*/
logMigration(migrationName) {
const self = this;
return this._model().sync().then(function (Model) {
var migration = {};
migration[self.columnName] = migrationName;
return Model.create(migration);
});
}
return this._model().sync().then(Model => {
const migration = {};
migration[self.columnName] = migrationName;
return Model.create(migration);
});
}
/**
* Unlogs migration to be considered as pending.
*
* @param {String} migrationName - Name of the migration to be unlogged.
* @returns {Promise}
*/
/**
* Unlogs migration to be considered as pending.
*
* @param {String} migrationName - Name of the migration to be unlogged.
* @returns {Promise}
*/
unlogMigration(migrationName) {
const self = this;
const sequelize = this.sequelize;
const sequelizeVersion = sequelize.modelManager ? 2 : 1;
}, {
key: 'unlogMigration',
value: function unlogMigration(migrationName) {
var self = this;
var sequelize = this.sequelize;
var sequelizeVersion = sequelize.modelManager ? 2 : 1;
return this._model().sync().then(Model => {
let where = {};
where[self.columnName] = migrationName;
return this._model().sync().then(function (Model) {
var where = {};
where[self.columnName] = migrationName;
if (sequelizeVersion > 1) {
// This is an ugly hack to find out which function signature we have to use.
where = { where: where };
}
if (sequelizeVersion > 1) {
// This is an ugly hack to find out which function signature we have to use.
where = { where: where };
}
return Model.destroy(where);
});
}
return Model.destroy(where);
});
}
/**
* Gets list of executed migrations.
*
* @returns {Promise.<String[]>}
*/
executed() {
const self = this;
/**
* Gets list of executed migrations.
*
* @returns {Promise.<String[]>}
*/
return this._model().sync().then(Model => Model.findAll({ order: [[self.columnName, 'ASC']] })).then(migrations => migrations.map(migration => migration[self.columnName]));
}
}, {
key: 'executed',
value: function executed() {
var self = this;
return this._model().sync().then(function (Model) {
return Model.findAll({ order: [[self.columnName, 'ASC']] });
}).then(function (migrations) {
return migrations.map(function (migration) {
return migration[self.columnName];
});
});
}
/**
* Gets Sequelize model used as a storage.
*
* @returns {Sequelize.Model}
* @private
*/
}, {
key: '_model',
value: function _model() {
return this.model;
}
}]);
return SequelizeStorage;
}(_Storage3.default);
/**
* Gets Sequelize model used as a storage.
*
* @returns {Sequelize.Model}
* @private
*/
_model() {
return this.model;
}
}
exports.default = SequelizeStorage;

@@ -7,10 +7,2 @@ 'use strict';

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _createClass2 = require('babel-runtime/helpers/createClass');
var _createClass3 = _interopRequireDefault(_createClass2);
var _bluebird = require('bluebird');

@@ -25,48 +17,32 @@

*/
var Storage = function () {
function Storage() {
(0, _classCallCheck3.default)(this, Storage);
class Storage {
/**
* Does nothing.
*
* @param {String} migrationName - Name of migration to be logged.
* @returns {Promise}
*/
logMigration(migrationName) {
return _bluebird2.default.resolve();
}
(0, _createClass3.default)(Storage, [{
key: 'logMigration',
/**
* Does nothing.
*
* @param {String} migrationName - Name of migration to unlog.
* @returns {Promise}
*/
unlogMigration(migrationName) {
return _bluebird2.default.resolve();
}
/**
* Does nothing.
*
* @param {String} migrationName - Name of migration to be logged.
* @returns {Promise}
*/
value: function logMigration(migrationName) {
return _bluebird2.default.resolve();
}
/**
* Does nothing.
*
* @param {String} migrationName - Name of migration to unlog.
* @returns {Promise}
*/
}, {
key: 'unlogMigration',
value: function unlogMigration(migrationName) {
return _bluebird2.default.resolve();
}
/**
* Does nothing.
*
* @returns {Promise.<String[]>}
*/
}, {
key: 'executed',
value: function executed() {
return _bluebird2.default.resolve([]);
}
}]);
return Storage;
}();
/**
* Does nothing.
*
* @returns {Promise.<String[]>}
*/
executed() {
return _bluebird2.default.resolve([]);
}
}
exports.default = Storage;
{
"name": "umzug",
"version": "2.1.0",
"version": "2.2.0",
"description": "Framework agnostic migration tool for Node.JS",

@@ -14,37 +14,34 @@ "keywords": [

"babel-runtime": "^6.23.0",
"bluebird": "^3.4.1",
"lodash": "^4.17.0",
"resolve": "^1.0.0"
"bluebird": "^3.5.3"
},
"devDependencies": {
"babel-cli": "^6.24.1",
"babel-plugin-dynamic-import-node": "^1.1.0",
"babel-plugin-dynamic-import-node": "^2.2.0",
"babel-plugin-syntax-dynamic-import": "^6.18.0",
"babel-plugin-transform-object-rest-spread": "^6.23.0",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-env": "^1.4.0",
"babel-preset-env": "^1.7.0",
"babel-register": "^6.24.1",
"chai": "^3.5.0",
"chai": "^4.2.0",
"coffee-script": "^1.8.0",
"eslint-config-standard": "^10.2.1",
"eslint-plugin-import": "^2.7.0",
"eslint-plugin-mocha": "^4.11.0",
"eslint-plugin-node": "^5.2.0",
"eslint-plugin-promise": "^3.5.0",
"eslint-plugin-standard": "^3.0.1",
"gulp": "^3.8.10",
"gulp-babel": "^7.0.0",
"gulp-eslint": "^4.0.0",
"gulp-mocha": "^4.3.0",
"mocha": "^3.5.3",
"sequelize": "^3.30.4",
"sinon": "^2.1.0",
"sinon-chai": "^2.14.0",
"sqlite3": "^3.1.13",
"typescript": "^2.5.2",
"yargs": "^8.0.1"
"eslint": "^5.9.0",
"eslint-config-standard": "^12.0.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-mocha": "^5.2.0",
"eslint-plugin-node": "^8.0.0",
"eslint-plugin-promise": "^4.0.1",
"eslint-plugin-standard": "^4.0.0",
"lodash": "^4.17.11",
"mocha": "^5.2.0",
"sequelize": "^4.41.2",
"sinon": "^7.1.1",
"sinon-chai": "^3.2.0",
"sqlite3": "^4.0.4",
"typescript": "^3.1.6",
"uuid": "^3.3.2"
},
"scripts": {
"build": "gulp build",
"test": "gulp test"
"build": "babel src --out-dir lib",
"lint": "eslint src test",
"test": "mocha -r babel-register --check-leaks test/index.js"
},

@@ -60,2 +57,6 @@ "repository": {

"email": "hyytiala.jukka@gmail.com"
},
{
"name": "Pascal Pflaum",
"email": "mail@pascalpflaum.de"
}

@@ -69,4 +70,4 @@ ],

"engines": {
"node": ">=4.0.0"
"node": ">=6.0.0"
}
}

@@ -57,3 +57,3 @@ # Umzug [![Build Status](https://travis-ci.org/sequelize/umzug.svg?branch=master)](https://travis-ci.org/sequelize/umzug)

### MongoDBStorage
Using the [SequelizeStorage](src/storages/MongoDBStorage.js) will create a collection in your MongoDB database called `migrations` containing an entry for each executed migration. You will have either to pass a MongoDB Driver Collection as `collection` property. Alternatively you can pass a established MongoDB Driver connection and a collection name.
Using the [MongoDBStorage](src/storages/MongoDBStorage.js) will create a collection in your MongoDB database called `migrations` containing an entry for each executed migration. You will have either to pass a MongoDB Driver Collection as `collection` property. Alternatively you can pass a established MongoDB Driver connection and a collection name.

@@ -143,3 +143,3 @@ #### Options

## Migrations
Migrations are basically files that describe ways of executing and reverting tasks. In order to allow asynchronicity, tasks have return a Promise object which provides a `then` method.
Migrations are basically files that describe ways of executing and reverting tasks. In order to allow asynchronicity, tasks return a Promise object which provides a `then` method.

@@ -185,3 +185,3 @@ ### Format

### API
The basic usage of *umzug* is as simple as that:
The basic usage of *umzug* is as simple as:

@@ -238,3 +238,3 @@ ```js

It is also possible to pass the name of a migration in order to just run the migrations from the current state to the passed migration name.
It is also possible to pass the name of a migration in order to just run the migrations from the current state to the passed migration name (inclusive).

@@ -251,3 +251,3 @@ ```js

In the above example umzug will execute all the pending migrations found **after** the specified migration. This is particularly usefull if you are using migrations on your native desktop application and you don't need to run past migrations on new installs while they need to run on updated installations.
In the above example umzug will execute all the pending migrations found **after** the specified migration. This is particularly useful if you are using migrations on your native desktop application and you don't need to run past migrations on new installs while they need to run on updated installations.

@@ -284,3 +284,3 @@ You can combine `from` and `to` options to select a specific subset:

It is possible to pass the name of a migration until which the migrations should be reverted. This allows the reverse of multiple migrations at once.
It is possible to pass the name of a migration until which (inclusive) the migrations should be reverted. This allows the reverting of multiple migrations at once.

@@ -314,3 +314,3 @@ ```js

It is possible to configure *umzug* instance via passing an object to the constructor. The possible options are:
It is possible to configure *umzug* instance by passing an object to the constructor. The possible options are:

@@ -320,3 +320,3 @@ ```js

// The storage.
// Possible values: 'json', 'sequelize', an argument for `require()`, including absolute paths
// Possible values: 'none', 'json', 'mongodb', 'sequelize', an argument for `require()`, including absolute paths
storage: 'json',

@@ -338,2 +338,3 @@

// (advanced) you can pass an array of Migration instances instead of the options below
migrations: {

@@ -340,0 +341,0 @@ // The params that gets passed to the migrations.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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