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

anydb-sql-migrations

Package Overview
Dependencies
Maintainers
2
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

anydb-sql-migrations - npm Package Compare versions

Comparing version 1.0.8 to 1.0.10

.idea/.name

10

d.ts/anydb-sql-migrations.d.ts
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

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