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

sql-ddl-sync

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sql-ddl-sync - npm Package Compare versions

Comparing version 0.1.2 to 0.1.3

lib/Dialects/sqlite.js

10

lib/Dialects/mysql.js

@@ -113,2 +113,6 @@ var SQL = require("../SQL");

if (column.serial) {
column.type = "serial";
}
columns[cols[i].Field] = column;

@@ -194,2 +198,8 @@ }

break;
case "serial":
property.type = "number";
property.serial = true;
property.primary = true;
type = "INT(11)";
break;
case "boolean":

@@ -196,0 +206,0 @@ type = "TINYINT(1)";

10

lib/Dialects/postgresql.js

@@ -213,7 +213,3 @@ var util = require("util");

case "text":
if (property.big) {
type = "TEXT";
} else {
type = "VARCHAR(" + Math.min(Math.max(parseInt(property.size, 10) || 255, 1), 65535) + ")";
}
type = "TEXT";
break;

@@ -227,2 +223,6 @@ case "number":

break;
case "serial":
property.serial = true;
type = "SERIAL";
break;
case "boolean":

@@ -229,0 +229,0 @@ type = "BOOLEAN";

@@ -30,3 +30,3 @@ exports.Queue = Queue;

return this;
}
};

@@ -37,2 +37,2 @@ Queue.prototype.check = function () {

}
}
};

@@ -12,2 +12,3 @@ var Queue = require("./Queue").Queue;

var collections = [];
var types = {};
var total_changes;

@@ -77,2 +78,6 @@

if (typeof Dialect.checkPrimary == "function") {
primary = Dialect.checkPrimary(primary);
}
total_changes += 1;

@@ -84,3 +89,5 @@

var createColumn = function (collection, name, property) {
var type = Dialect.getType(collection, name, property);
var type = types.hasOwnProperty(property.type)
? types[property.type].datastoreType(property)
: Dialect.getType(collection, name, property);

@@ -90,2 +97,5 @@ if (type === false) {

}
if (typeof type == "string") {
type = { value : type };
}

@@ -306,4 +316,12 @@ return {

if (property.type != column.type) {
return true;
if (typeof Dialect.supportsType != "function") {
return true;
}
if (Dialect.supportsType(property.type) != column.type) {
return true;
}
}
if (property.type == "serial") {
return false; // serial columns have a fixed form, nothing more to check
}
if (property.required != column.required && !property.primary) {

@@ -316,3 +334,3 @@ return true;

if (property.type == "number") {
if ((property.size || 4) != column.size) {
if (column.hasOwnProperty("size") && (property.size || 4) != column.size) {
return true;

@@ -324,3 +342,3 @@ }

}
if (property.type == "enum") {
if (property.type == "enum" && column.type == "enum") {
if (_.difference(property.values, column.values).length > 0

@@ -336,3 +354,3 @@ || _.difference(column.values, property.values).length > 0) {

return {
define : function (collection, properties) {
defineCollection : function (collection, properties) {
collections.push({

@@ -342,3 +360,8 @@ name : collection,

});
return this;
},
defineType : function (type, proto) {
types[type] = proto;
return this;
},
sync : function (cb) {

@@ -345,0 +368,0 @@ var i = 0;

{
"author" : "Diogo Resende <dresende@thinkdigital.pt>",
"name" : "sql-ddl-sync",
"description" : "NodeJS SQL DDL Synchronization",
"keywords" : [ "sql", "ddl", "sync", "mysql", "postgres", "sqlite" ],
"version" : "0.1.2",
"license" : "MIT",
"repository" : "http://github.com/dresende/node-sql-ddl-sync.git",
"main" : "./lib/Sync",
"scripts" : { "test": "make test" },
"engines" : { "node": "*" },
"analyse" : false,
"dependencies" : {
"lodash" : "2.0.0"
},
"devDependencies" : {
"mocha" : "1.12.1",
"should" : "1.2.2",
"commander" : "~2.0.0"
}
"author" : "Diogo Resende <dresende@thinkdigital.pt>",
"name" : "sql-ddl-sync",
"description" : "NodeJS SQL DDL Synchronization",
"keywords" : [ "sql", "ddl", "sync", "mysql", "postgres", "sqlite" ],
"version" : "0.1.3",
"license" : "MIT",
"repository" : "http://github.com/dresende/node-sql-ddl-sync.git",
"main" : "./lib/Sync",
"scripts" : { "test": "make test" },
"engines" : { "node": "*" },
"analyse" : false,
"dependencies" : {
"lodash" : "2.2.1"
},
"devDependencies" : {
"mocha" : "1.14.0",
"should" : "2.0.2",
"commander" : "~2.0.0"
}
}

@@ -29,2 +29,4 @@ exports.dialect = null;

return exports.db.query("ALTER TABLE " + exports.table + " ADD " + column + " INTEGER NOT NULL", done);
case "sqlite":
return exports.db.all("ALTER TABLE " + exports.table + " ADD " + column + " INTEGER", done);
}

@@ -42,2 +44,4 @@ return done(unknownProtocol());

return exports.db.query("ALTER TABLE " + exports.table + " ALTER " + column + " TYPE DOUBLE PRECISION", done);
case "sqlite":
return exports.db.all("ALTER TABLE " + exports.table + " MODIFY " + column + " INTEGER NOT NULL", done);
}

@@ -55,2 +59,4 @@ return done(unknownProtocol());

return exports.db.query("CREATE " + (unique ? "UNIQUE" : "") + " INDEX " + exports.table + "_" + name + " ON " + exports.table + " (" + column + ")", done);
case "sqlite":
return exports.db.all("CREATE " + (unique ? "UNIQUE" : "") + " INDEX " + name + " ON " + exports.table + " (" + column + ")", done);
}

@@ -68,2 +74,4 @@ return done(unknownProtocol());

return exports.db.query("DROP INDEX " + exports.table + "_" + name, done);
case "sqlite":
return exports.db.all("DROP INDEX " + name, done);
}

@@ -70,0 +78,0 @@ return done(unknownProtocol());

@@ -12,3 +12,3 @@ var Sync = require("../../lib/Sync").Sync;

sync.define(common.table, {
sync.defineCollection(common.table, {
id : { type: "number", primary: true, serial: true },

@@ -51,73 +51,75 @@ name : { type: "text", required: true, defaultValue: 'John' },

describe("Dropping a column", function () {
before(common.dropColumn('dt'));
if (common.dialect != "sqlite") {
describe("Dropping a column", function () {
before(common.dropColumn('dt'));
it("should recreate it on first call", function (done) {
sync.sync(function (err, info) {
should.not.exist(err);
should.exist(info);
info.should.have.property("changes", 1);
it("should recreate it on first call", function (done) {
sync.sync(function (err, info) {
should.not.exist(err);
should.exist(info);
info.should.have.property("changes", 1);
return done();
return done();
});
});
});
it("should have no changes on second call", function (done) {
sync.sync(function (err, info) {
should.not.exist(err);
should.exist(info);
info.should.have.property("changes", 0);
it("should have no changes on second call", function (done) {
sync.sync(function (err, info) {
should.not.exist(err);
should.exist(info);
info.should.have.property("changes", 0);
return done();
return done();
});
});
});
});
describe("Dropping a column that has an index", function () {
before(common.dropColumn('dttm'));
describe("Dropping a column that has an index", function () {
before(common.dropColumn('dttm'));
it("should recreate column and index on first call", function (done) {
sync.sync(function (err, info) {
should.not.exist(err);
should.exist(info);
info.should.have.property("changes", 2);
it("should recreate column and index on first call", function (done) {
sync.sync(function (err, info) {
should.not.exist(err);
should.exist(info);
info.should.have.property("changes", 2);
return done();
return done();
});
});
});
it("should have no changes on second call", function (done) {
sync.sync(function (err, info) {
should.not.exist(err);
should.exist(info);
info.should.have.property("changes", 0);
it("should have no changes on second call", function (done) {
sync.sync(function (err, info) {
should.not.exist(err);
should.exist(info);
info.should.have.property("changes", 0);
return done();
return done();
});
});
});
});
describe("Adding a column", function () {
before(common.addColumn('unknown_col'));
describe("Adding a column", function () {
before(common.addColumn('unknown_col'));
it("should drop column on first call", function (done) {
sync.sync(function (err, info) {
should.not.exist(err);
should.exist(info);
info.should.have.property("changes", 1);
it("should drop column on first call", function (done) {
sync.sync(function (err, info) {
should.not.exist(err);
should.exist(info);
info.should.have.property("changes", 1);
return done();
return done();
});
});
});
it("should have no changes on second call", function (done) {
sync.sync(function (err, info) {
should.not.exist(err);
should.exist(info);
info.should.have.property("changes", 0);
it("should have no changes on second call", function (done) {
sync.sync(function (err, info) {
should.not.exist(err);
should.exist(info);
info.should.have.property("changes", 0);
return done();
return done();
});
});
});
});
}

@@ -124,0 +126,0 @@ describe("Changing a column", function () {

@@ -8,5 +8,5 @@ var common = require("../common");

it("should detect text", function (done) {
Dialect.getType(null, null, { type: "text" }).value.should.equal("VARCHAR(255)");
Dialect.getType(null, null, { type: "text", size: 150 }).value.should.equal("VARCHAR(150)");
Dialect.getType(null, null, { type: "text", size: 1000 }).value.should.equal("VARCHAR(1000)");
Dialect.getType(null, null, { type: "text" }).value.should.equal("TEXT");
Dialect.getType(null, null, { type: "text", size: 150 }).value.should.equal("TEXT");
Dialect.getType(null, null, { type: "text", size: 1000 }).value.should.equal("TEXT");

@@ -13,0 +13,0 @@ return done();

@@ -38,2 +38,10 @@ var program = require("commander");

break;
case "sqlite:":
case "sqlite3:":
common.dialect = "sqlite";
common.db = new (require("sqlite3").Database)(uri.pathname);
testDatabase();
// common.db.connect(testDatabase);
break;
default:

@@ -40,0 +48,0 @@ process.stdout.write("Database protocol not supported.\n");

@@ -1,19 +0,21 @@

var common = require("./common");
var Mocha = require("mocha");
var path = require("path");
var fs = require("fs");
var test_folder = __dirname + "/integration/";
var location = __dirname + "/integration/";
var mocha = new Mocha({
reporter : "progress"
var Mocha = require("mocha");
var path = require("path");
var fs = require("fs");
var is_tty = require("tty").isatty(process.stdout);
if (!is_tty) {
Mocha.reporters.Base.useColors = false;
}
var mocha = new Mocha({
reporter : (is_tty ? "spec" : "dot")
});
fs.readdirSync(location).filter(function (file) {
if (file == "db.js") {
return false;
}
return (file.substr(-3) === '.js');
fs.readdirSync(test_folder).filter(function (file) {
return (file.substr(-3) === ".js" && file != "db.js");
}).forEach(function (file) {
mocha.addFile(
path.join(location, file)
path.join(test_folder, file)
);

@@ -20,0 +22,0 @@ });

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