anydb-sql-migrations
Advanced tools
Comparing version 2.0.0 to 2.1.0
@@ -18,10 +18,9 @@ declare module "anydb-sql-migrations" { | ||
} | ||
export function create(db: AnydbSql, tasks: any): { | ||
export function create(db: AnydbSql, tasks: string | MigrationTask[]): { | ||
run: () => Promise<any>; | ||
migrateTo: (target?: string) => Promise<any>; | ||
check: (f: (m: { | ||
type: string; | ||
items: MigrationTask[]; | ||
}) => any) => Promise<any>; | ||
check: (f: (items: MigrationTask[]) => any) => Promise<any>; | ||
migrate: () => Promise<any>; | ||
undoLast: () => Promise<any>; | ||
drop: () => Promise<any>; | ||
}; | ||
} |
"use strict"; | ||
var Promise = require('bluebird'); | ||
var _ = require('lodash'); | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
exports.__esModule = true; | ||
var Promise = require("bluebird"); | ||
var _ = require("lodash"); | ||
var fs = require("fs"); | ||
var path = require("path"); | ||
function create(db, tasks) { | ||
@@ -41,3 +42,3 @@ var list = []; | ||
function remove(tx, name) { | ||
return migrations.where({ version: name }).delete().execWithin(tx); | ||
return migrations.where({ version: name })["delete"]().execWithin(tx); | ||
} | ||
@@ -64,2 +65,15 @@ function runSingle(tx, type, m) { | ||
} | ||
function undoAll() { | ||
return runMigration(function (tx) { return migrations.select() | ||
.order(migrations.version.descending) | ||
.allWithin(tx).then(function (migrations) { | ||
if (!migrations.length) { | ||
throw new Error("No migrations available to rollback"); | ||
} | ||
return Promise.all(migrations.map(function (mig) { | ||
var task = _.find(list, function (item) { return item.name == mig.version; }); | ||
return runSingle(tx, "down", task); | ||
})); | ||
}); }); | ||
} | ||
function loadFromPath(location) { | ||
@@ -103,3 +117,14 @@ fs.readdirSync(location) | ||
} | ||
console.error("Add a --check, --execute or --rollback argument"); | ||
else if (args.drop) { | ||
return undoAll().done(function (_) { return process.exit(0); }, function (e) { | ||
if (e.message == 'No migrations available to rollback') { | ||
console.error(e.message); | ||
} | ||
else { | ||
console.error(e.stack); | ||
} | ||
process.exit(1); | ||
}); | ||
} | ||
console.error("Add a --check, --execute, --drop or --rollback argument"); | ||
process.exit(1); | ||
@@ -111,4 +136,5 @@ } | ||
tasks.forEach(function (task) { return defineMigration(task.name, task); }); | ||
return { run: run, check: check, migrate: migrate }; | ||
return { run: run, check: check, migrate: migrate, undoLast: undoLast, drop: undoAll }; | ||
} | ||
exports.create = create; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "anydb-sql-migrations", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "Database migrations for anydb-sql", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -56,3 +56,7 @@ require('source-map-support').install() | ||
}, | ||
down: function() {} | ||
down: function(tx) { | ||
return db.user.drop().execWithin(tx) | ||
.then(_ => db.account.drop().execWithin(tx)) | ||
.then(_ => db.storage.drop().execWithin(tx)) | ||
} | ||
}; | ||
@@ -80,5 +84,6 @@ | ||
}).then(function() { | ||
db.account.alter().dropColumn(db.account.credentials); | ||
return Promise.resolve() | ||
}); | ||
} | ||
}, | ||
down: () => {return Promise.resolve()} | ||
}; | ||
@@ -113,4 +118,14 @@ | ||
}); | ||
}); | ||
}).then(function() { | ||
return migc2.drop() | ||
}).then(function() { | ||
db.storage.where({id: 1}).get() | ||
.then(_ => { throw new Error("Table should not exist") }, | ||
e => t.ok(e.message, 'Expecting error trying to access storage table: ' + e.message)) | ||
}).then(function() { | ||
return migc2.drop() | ||
.then(res => {console.log(res); throw new Error('Drop should not work on empty db')}, | ||
e => t.ok(e.message, 'Expecting error trying to run drop on empty db: ' + e.message)) | ||
}) | ||
}); | ||
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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
19247
10
288