node-pg-migrate
Advanced tools
Comparing version 2.18.1 to 2.19.0
# Change Log | ||
## [2.19.0] (2018-02-06) | ||
### Added | ||
- `migration-file-language` can be set in config file [#180](https://github.com/salsita/node-pg-migrate/pull/180) | ||
- Treat number argument to up/down migration as timestamp [#179](https://github.com/salsita/node-pg-migrate/pull/179) | ||
## [2.18.1] (2018-02-06) | ||
@@ -4,0 +11,0 @@ |
@@ -27,6 +27,2 @@ 'use strict'; | ||
var _util = require('util'); | ||
var _util2 = _interopRequireDefault(_util); | ||
var _migrationBuilder = require('./migration-builder'); | ||
@@ -42,2 +38,4 @@ | ||
var SEPARATOR = '_'; | ||
var Migration = function () { | ||
@@ -53,3 +51,3 @@ _createClass(Migration, null, [{ | ||
// file name looks like migrations/1391877300255_migration-title.js | ||
var newFile = _util2.default.format(`%s/%d_%s.${language}`, directory, +new Date(), name); | ||
var newFile = `${directory}/${Date.now()}${SEPARATOR}${name}.${language}`; | ||
@@ -75,3 +73,4 @@ // copy the default migration template to the new file location | ||
this.path = migrationPath; | ||
this.name = migrationPath.split('/').pop().replace(/\.js$/, ''); | ||
this.name = _path2.default.basename(migrationPath, _path2.default.extname(migrationPath)); | ||
this.timestamp = Number(this.name.split(SEPARATOR)[0]) || 0; | ||
this.up = up; | ||
@@ -78,0 +77,0 @@ this.down = down; |
@@ -137,3 +137,3 @@ 'use strict'; | ||
if (options.direction === 'down') { | ||
var toRun = runNames.filter(function (migrationName) { | ||
var downMigrations = runNames.filter(function (migrationName) { | ||
return !options.file || options.file === migrationName; | ||
@@ -145,3 +145,7 @@ }).map(function (migrationName) { | ||
}) || migrationName; | ||
}).slice(-Math.abs(options.count || 1)).reverse(); | ||
}); | ||
var toRun = (options.timestamp ? downMigrations.filter(function (_ref2) { | ||
var timestamp = _ref2.timestamp; | ||
return timestamp >= options.count; | ||
}) : downMigrations.slice(-Math.abs(options.count || 1))).reverse(); | ||
var deletedMigrations = toRun.filter(function (migration) { | ||
@@ -155,6 +159,10 @@ return typeof migration === 'string'; | ||
} | ||
return migrations.filter(function (_ref2) { | ||
var name = _ref2.name; | ||
var upMigrations = migrations.filter(function (_ref3) { | ||
var name = _ref3.name; | ||
return runNames.indexOf(name) < 0 && (!options.file || options.file === name); | ||
}).slice(0, Math.abs(options.count || Infinity)); | ||
}); | ||
return options.timestamp ? upMigrations.filter(function (_ref4) { | ||
var timestamp = _ref4.timestamp; | ||
return timestamp <= options.count; | ||
}) : upMigrations.slice(0, Math.abs(options.count || Infinity)); | ||
}; | ||
@@ -170,6 +178,6 @@ | ||
return Promise.all([loadMigrationFiles(db, options), getRunMigrations(db, options)]); | ||
}).then(function (_ref3) { | ||
var _ref4 = _slicedToArray(_ref3, 2), | ||
migrations = _ref4[0], | ||
runNames = _ref4[1]; | ||
}).then(function (_ref5) { | ||
var _ref6 = _slicedToArray(_ref5, 2), | ||
migrations = _ref6[0], | ||
runNames = _ref6[1]; | ||
@@ -176,0 +184,0 @@ if (options.checkOrder) { |
@@ -33,3 +33,3 @@ { | ||
], | ||
"version": "2.18.1", | ||
"version": "2.19.0", | ||
"engines": { | ||
@@ -36,0 +36,0 @@ "node": ">=4.0.0" |
@@ -93,2 +93,3 @@ # node-pg-migrate | ||
* `migration-file-language` (`j`) - Language of the migration file to create (`js` or `ts`) | ||
* `timestamp` - Treats number argument to up/down migration as timestamp (running up migrations less or equal to timestamp or down migrations greater or equal to timestamp) | ||
@@ -95,0 +96,0 @@ * `check-order` - Check order of migrations before running them (defaults to `true`, to switch it off supply `--no-check-order` on command line). |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
165028
2031
1073