anydb-sql-migrations
Advanced tools
Comparing version 1.0.8 to 1.0.10
declare module "anydb-sql-migrations" { | ||
import anydbSQL = require('anydb-sql'); | ||
import Promise = require('bluebird'); | ||
import { Column, Table, Transaction, AnydbSql } from 'anydb-sql'; | ||
export interface Migration { | ||
version: string; | ||
} | ||
export interface MigrationsTable extends anydbSQL.Table<Migration> { | ||
version: anydbSQL.Column<string>; | ||
export interface MigrationsTable extends Table<Migration> { | ||
version: Column<string>; | ||
} | ||
export interface MigFn { | ||
(tx: anydbSQL.Transaction): Promise<any>; | ||
(tx: Transaction): Promise<any>; | ||
} | ||
@@ -18,3 +18,3 @@ export interface MigrationTask { | ||
} | ||
export function create(db: anydbSQL.AnydbSql, tasks: any): { | ||
export function create(db: AnydbSql, tasks: any): { | ||
run: () => Promise<any>; | ||
@@ -21,0 +21,0 @@ migrateTo: (target?: string) => Promise<any>; |
@@ -10,3 +10,3 @@ var Promise = require('bluebird'); | ||
columns: { | ||
version: { dataType: 'text', notNull: true, primaryKey: true } | ||
version: { dataType: db.dialect() === 'mysql' ? 'text' : 'varchar(255)', notNull: true, primaryKey: true } | ||
} | ||
@@ -16,3 +16,5 @@ }); | ||
return db.transaction(function (tx) { | ||
return migrations.create().ifNotExists().execWithin(tx).then(function (_) { return migfn(tx); }).thenReturn(); | ||
return migrations.create().ifNotExists().execWithin(tx) | ||
.then(function (_) { return migfn(tx); }) | ||
.thenReturn(); | ||
}); | ||
@@ -45,12 +47,21 @@ } | ||
function getMigrationList(tx, target) { | ||
return migrations.select().order(migrations.version.descending).getWithin(tx).then(function (current) { return findChain(current && current.version, target); }); | ||
return migrations.select() | ||
.order(migrations.version.descending) | ||
.getWithin(tx) | ||
.then(function (current) { return findChain(current && current.version, target); }); | ||
} | ||
function runSingle(tx, type, m) { | ||
return type == 'up' ? Promise.join(add(tx, m.name), m.up(tx)) : Promise.join(remove(tx, m.name), m.down(tx)); | ||
return type == 'up' ? | ||
m.up(tx).then(function () { return add(tx, m.name); }) : | ||
m.down(tx).then(function () { return remove(tx, m.name); }); | ||
} | ||
function migrateTo(target) { | ||
return runMigration(function (tx) { return getMigrationList(tx, target).then(function (migration) { return migration.items.reduce(function (acc, m) { return acc.then(function (_) { return runSingle(tx, migration.type, m); }).then(function (_) { return console.log("Completed:", m.name); }).thenReturn(); }, Promise.resolve()); }); }); | ||
return runMigration(function (tx) { return getMigrationList(tx, target).then(function (migration) { return migration.items.reduce(function (acc, m) { return acc.then(function (_) { return runSingle(tx, migration.type, m); }) | ||
.then(function (_) { return console.log("Completed:", m.name); }) | ||
.thenReturn(); }, Promise.resolve()); }); }); | ||
} | ||
function loadFromPath(location) { | ||
fs.readdirSync(location).filter(function (file) { return (/\.js$/.test(file)); }).forEach(function (file) { return defineMigration(file.replace(/\.js$/, ''), require(path.resolve(location, file))); }); | ||
fs.readdirSync(location) | ||
.filter(function (file) { return (/\.js$/.test(file)); }) | ||
.forEach(function (file) { return defineMigration(file.replace(/\.js$/, ''), require(path.resolve(location, file))); }); | ||
} | ||
@@ -57,0 +68,0 @@ function check(f) { |
{ | ||
"name": "anydb-sql-migrations", | ||
"version": "1.0.8", | ||
"version": "1.0.10", | ||
"description": "Database migrations for anydb-sql", | ||
@@ -25,3 +25,3 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"anydb-sql": "^0.6.23", | ||
"anydb-sql": "^0.6.39", | ||
"bluebird": "^2.3.11", | ||
@@ -28,0 +28,0 @@ "lodash": "^2.4.1", |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
56326
23
315
4
1
Updatedanydb-sql@^0.6.39