Comparing version 0.3.1 to 0.3.2
@@ -148,6 +148,5 @@ var _ = require('underscore') | ||
if (constraint1) { | ||
if (!_.isEqual(constraint1, constraint2)) { | ||
// TODO: drop current constraint | ||
// constraint1 = null | ||
} | ||
if (_.isEqual(constraint1, constraint2)) return | ||
this._safe(`ALTER TABLE ${tableName} DROP CONSTRAINT "${constraint2.name}";`) | ||
constraint1 = null | ||
} | ||
@@ -154,0 +153,0 @@ if (!constraint1) { |
{ | ||
"name": "dbdiff", | ||
"version": "0.3.1", | ||
"version": "0.3.2", | ||
"description": "Compares two postgresql databases and prints SQL commands to modify the first one in order to match the second one", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -75,1 +75,19 @@ # dbdiff | ||
``` | ||
You can pass connection strings such as `postgres://user:pass@host:5432/dbname1` or objects to these methods. For example: | ||
```javascript | ||
dbdiff.describeDatabase({ | ||
dialect: 'postgres', | ||
username: 'user', | ||
password: 'pass', | ||
database: 'dbname1', | ||
host: 'localhost', | ||
dialectOptions: { | ||
ssl: false | ||
} | ||
}) | ||
.then((schema) => { | ||
// ... | ||
}) | ||
``` |
@@ -260,2 +260,30 @@ /* globals describe it */ | ||
it('should support existing constriants with the same name', () => { | ||
var commands1 = [ | ||
'CREATE TABLE users (email VARCHAR(255), api_key VARCHAR(255));', | ||
'ALTER TABLE users ADD CONSTRAINT a_unique_constraint UNIQUE (email);' | ||
] | ||
var commands2 = [ | ||
'CREATE TABLE users (email VARCHAR(255), api_key VARCHAR(255));', | ||
'ALTER TABLE users ADD CONSTRAINT a_unique_constraint UNIQUE (api_key);' | ||
] | ||
return Promise.resolve() | ||
.then(() => { | ||
var expected = dedent` | ||
ALTER TABLE "public"."users" DROP CONSTRAINT "a_unique_constraint"; | ||
ALTER TABLE "public"."users" ADD CONSTRAINT "a_unique_constraint" UNIQUE ("api_key"); | ||
` | ||
return utils.runAndCompare(commands1, commands2, expected, ['warn', 'drop']) | ||
}) | ||
.then(() => { | ||
var expected = dedent` | ||
ALTER TABLE "public"."users" DROP CONSTRAINT "a_unique_constraint"; | ||
-- ALTER TABLE "public"."users" ADD CONSTRAINT "a_unique_constraint" UNIQUE ("api_key"); | ||
` | ||
return utils.runAndCompare(commands1, commands2, expected, ['safe']) | ||
}) | ||
}) | ||
it('should run as a cli application', () => { | ||
@@ -262,0 +290,0 @@ var conString1 = 'postgres://postgres:postgres@localhost/db1' |
@@ -9,2 +9,13 @@ var Client = require('../dialects/postgres-client') | ||
var conSettings2 = { | ||
dialect: 'postgres', | ||
username: 'postgres', | ||
password: 'postgres', | ||
database: 'db2', | ||
host: 'localhost', | ||
dialectOptions: { | ||
ssl: false | ||
} | ||
} | ||
var client1 = new Client(conString1) | ||
@@ -32,3 +43,3 @@ var client2 = new Client(conString2) | ||
return exports.runCommands(commands1, commands2) | ||
.then(() => dbdiff.compare(conString1, conString2)) | ||
.then(() => dbdiff.compare(conString1, conSettings2)) | ||
.then(() => assert.equal(dbdiff.commands(level), expected)) | ||
@@ -35,0 +46,0 @@ .then(() => client1.query(dbdiff.commands(level))) |
36321
833
93