db-migrate-shared
Advanced tools
Comparing version 1.0.2 to 1.1.0
{ | ||
"name": "db-migrate-shared", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"description": "Shared resources of db-migrate for drivers and also used internally.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
58
util.js
@@ -12,5 +12,23 @@ var log = require('./log'); | ||
exports.filterUp = function(allMigrations, completedMigrations, destination, count) { | ||
function isIncludedInDown(migration, destination) { | ||
if(!destination) { | ||
return true; | ||
} | ||
var migrationTest = migration.name.substring(0, Math.min(migration.name.length, destination.length)); | ||
var destinationTest = destination.substring(0, Math.min(migration.name.length, destination.length)); | ||
return migrationTest >= destinationTest; | ||
} | ||
function filterCompleted(allMigrations, completedMigrations) { | ||
var sortFn = function(a, b) { | ||
return a.name.slice(0, a.name.indexOf('-')) - b.name.slice(0, b.name.indexOf('-')); | ||
a = a.name.slice(0, a.name.indexOf('-')); | ||
b = b.name.slice(0, b.name.indexOf('-')); | ||
if(!isNaN(a)) { | ||
return a - b; | ||
} | ||
return a.localeCompare(b); | ||
}; | ||
@@ -24,9 +42,34 @@ | ||
return !hasRun; | ||
}) | ||
}); | ||
} | ||
exports.filterUp = function(allMigrations, completedMigrations, destination, count) { | ||
return filterCompleted(allMigrations, completedMigrations) | ||
.filter(function(migration) { | ||
return isIncludedInUp(migration, destination); | ||
}) | ||
.slice(0, count); | ||
}).slice(0, count); | ||
}; | ||
exports.filterDown = function(completedMigrations, destination, count) { | ||
return completedMigrations | ||
.filter(function(migration) { | ||
return isIncludedInDown(migration, destination); | ||
}).slice(0, count); | ||
}; | ||
exports.syncMode = function(completedMigrations, destination) { | ||
var isDown = isIncludedInDown( | ||
completedMigrations[completedMigrations.length -1], | ||
destination | ||
); | ||
if(isDown) | ||
return 1; | ||
else | ||
return 0; | ||
}; | ||
/** | ||
@@ -127,7 +170,2 @@ * Similar to the shadow driver, but we reduce to a subset of an existing | ||
exports.filterDown = function(completedMigrations, count) { | ||
return completedMigrations.slice(0, count); | ||
}; | ||
exports.lpad = function(str, padChar, totalLength) { | ||
@@ -134,0 +172,0 @@ str = str.toString(); |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
10686
285
0