Socket
Socket
Sign inDemoInstall

db-migrate

Package Overview
Dependencies
Maintainers
1
Versions
139
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

db-migrate - npm Package Compare versions

Comparing version 0.2.8 to 0.3.0

8

CHANGELOG.md

@@ -94,1 +94,9 @@ ## 0.1.0

- Added support for additional MySQL data types #58 (via @jpravetz)
## 0.3.0
Improvement:
- Added support for MySQLs LONGTEXT #62 (via @joeferner)
New Feature:
- Added dry-run support for migrations #55 (via @joeferner)

5

lib/driver/base.js

@@ -64,2 +64,3 @@ var util = require('util');

createTable: function(tableName, options, callback) {
log.verbose('creating table:', tableName);
var columnSpecs = options;

@@ -210,7 +211,7 @@ var tableOptions = {};

runSql: function() {
throw new Error('not yet implemented');
throw new Error('not implemented');
},
all: function(sql, params, callback) {
throw new Error('not yet implemented');
throw new Error('not implemented');
},

@@ -217,0 +218,0 @@

8

lib/driver/index.js

@@ -0,1 +1,3 @@

var log = require('../log');
exports.connect = function(config, callback) {

@@ -6,7 +8,11 @@ if (config.driver === undefined) {

var driver = require('./' + config.driver);
var req = './' + config.driver;
log.verbose('require:', req);
var driver = require(req);
log.verbose('connecting');
driver.connect(config, function(err, db) {
if (err) { callback(err); return; }
log.verbose('connected');
callback(null, db);
});
};

@@ -6,2 +6,3 @@ var util = require('util');

var type = require('../data_type');
var log = require('../log');

@@ -14,8 +15,19 @@ var MysqlDriver = Base.extend({

mapDataType: function(str) {
switch(str) {
mapDataType: function(spec) {
var len;
switch(spec.type) {
case type.STRING:
return 'VARCHAR';
case type.TEXT:
return 'TEXT';
len = parseInt(spec.length) || 1000;
if(len > 16777216) {
return 'LONGTEXT';
}
if(len > 65536) {
return 'MEDIUMTEXT';
}
if(len > 256) {
return 'TEXT';
}
return 'TINYTEXT';
case type.INTEGER:

@@ -28,3 +40,13 @@ return 'INTEGER';

case type.BLOB:
return 'BLOB';
len = parseInt(spec.length) || 1000;
if(len > 16777216) {
return 'LONGBLOB';
}
if(len > 65536) {
return 'MEDIUMBLOB';
}
if(len > 256) {
return 'BLOB';
}
return 'TINYBLOB';
case type.TIMESTAMP:

@@ -40,9 +62,12 @@ return 'TIMESTAMP';

createColumnDef: function(name, spec, options) {
var type = this.mapDataType(spec.type);
var len = spec.length ? util.format('(%s)', spec.length) : '';
if (type === 'VARCHAR' && len === '') {
len = '(255)';
var t = this.mapDataType(spec);
var len;
if(spec.type !== type.TEXT && spec.type !== type.BLOB) {
len = spec.length ? util.format('(%s)', spec.length) : '';
if (t === 'VARCHAR' && len === '') {
len = '(255)';
}
}
var constraint = this.createColumnConstraint(spec, options);
return [name, type, len, constraint].join(' ');
return [name, t, len, constraint].join(' ');
},

@@ -127,7 +152,12 @@

runSql: function() {
this.connection.query.apply(this.connection, arguments);
var callback = arguments[arguments.length - 1];
log.sql.apply(null, arguments);
if(global.dryRun) {
return callback();
}
return this.connection.query.apply(this.connection, arguments);
},
all: function() {
this.connection.query.apply(this.connection, arguments);
return this.connection.query.apply(this.connection, arguments);
},

@@ -134,0 +164,0 @@

@@ -165,2 +165,4 @@ var util = require('util');

runSql: function() {
var callback = arguments[arguments.length - 1];
params = arguments;

@@ -178,3 +180,7 @@ if (params.length > 2){

}
log.verbose('pg.runSql', params);
log.sql.apply(null, params);
if(global.dryRun) {
return callback();
}
this.connection.query.apply(this.connection, params);

@@ -181,0 +187,0 @@ },

var util = require('util');
var sqlite3 = require('sqlite3').verbose();
var Base = require('./base');
var log = require('../log');
var type = require('../data_type');

@@ -54,2 +55,8 @@

runSql: function() {
var callback = arguments[arguments.length - 1];
log.sql.apply(null, arguments);
if(global.dryRun) {
return callback();
}
this.connection.run.apply(this.connection, arguments);

@@ -56,0 +63,0 @@ },

exports.info = console.info.bind(console, '[INFO]');
exports.warn = console.warn.bind(console, '[WARN]');
exports.error = console.error.bind(console, '[ERROR]');
exports.sql = function(sql) {
if (global.dryRun || global.verbose) {
var args = Array.prototype.slice.call(arguments).slice(1);
args = args.slice(0, args.length - 1);
if(global.verbose) {
if(args.length > 0) {
console.log('[SQL]', sql, args);
} else {
console.log('[SQL]', sql);
}
}
if (global.dryRun) {
if(args.length > 0) {
console.log(sql, args);
} else {
console.log(sql);
}
}
}
};
exports.verbose = function() {

@@ -5,0 +25,0 @@ if (global.verbose) {

@@ -6,2 +6,3 @@ var fs = require('fs');

var config = require('./config');
var log = require('./log');

@@ -103,2 +104,3 @@ function formatPath(dir, name) {

Migration.loadFromFilesystem = function(dir, callback) {
log.verbose('loading migrations from dir', dir);
fs.readdir(dir, function(err, files) {

@@ -117,2 +119,3 @@ if (err) { callback(err); return; }

Migration.loadFromDatabase = function(dir, driver, callback) {
log.verbose('loading migrations from database');
driver.all('SELECT * FROM migrations ORDER BY name DESC', function(err, dbResults) {

@@ -119,0 +122,0 @@ if (err) { callback(err); return; }

@@ -111,6 +111,6 @@ var async = require('async');

var self = this;
var all = Migration.loadFromFilesystem(self.migrationsDir, function(err, allMigrations) {
Migration.loadFromFilesystem(self.migrationsDir, function(err, allMigrations) {
if (err) { callback(err); return; }
var complete = Migration.loadFromDatabase(self.migrationsDir, self.driver, function(err, completedMigrations) {
Migration.loadFromDatabase(self.migrationsDir, self.driver, function(err, completedMigrations) {
if (err) { callback(err); return; }

@@ -126,2 +126,3 @@ var toRun = filterUp(allMigrations, completedMigrations, partialName, count);

async.forEachSeries(toRun, function(migration, next) {
log.verbose('preparing to run up migration:', migration.name);
self.driver.startMigration(function() {

@@ -148,4 +149,4 @@ self.up(migration.up.bind(migration), function(err) {

var self = this;
var complete = Migration.loadFromDatabase(self.migrationsDir, self.driver, function(err, completedMigrations) {
if (err) { callback(err); return; }
Migration.loadFromDatabase(self.migrationsDir, self.driver, function(err, completedMigrations) {
if (err) { return callback(err); }

@@ -161,2 +162,3 @@ var toRun = filterDown(completedMigrations, partialName, count);

async.forEachSeries(toRun, function(migration, next) {
log.verbose('preparing to run down migration:', migration.name);
self.down(migration.down.bind(migration), function(err) {

@@ -163,0 +165,0 @@ if (err) { callback(err); return; }

@@ -14,3 +14,3 @@ {

],
"version": "0.2.8",
"version": "0.3.0",
"engines": {

@@ -17,0 +17,0 @@ "node": ">=0.6.0"

@@ -24,2 +24,3 @@ # db-migrate

--count, -c Max number of migrations to run.
--dry-run Prints the SQL but doesn't run it. [boolean]
--verbose, -v Verbose mode. [default: false]

@@ -26,0 +27,0 @@ --config Location of the database.json file. [default: "./database.json"]

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