database-cleaner
Advanced tools
Comparing version
@@ -0,1 +1,6 @@ | ||
0.10.0 / 2015-07-20 | ||
================== | ||
* Allow skip tables during tests. Supports MySQL and Postgres | ||
0.9.2 / 2015-07-15 | ||
@@ -2,0 +7,0 @@ ================== |
var DatabaseCleaner = module.exports = function(type) { | ||
var cleaner = {}; | ||
var config = require("../config/cleaner-config.js"); | ||
@@ -38,5 +39,6 @@ cleaner['mongodb'] = function(db, callback) { | ||
var tableName = 'Tables_in_' + db.config.database; | ||
var skippedTables = config.mysql.skipTables; | ||
tables.forEach(function(table) { | ||
if (table[tableName] != 'schema_migrations') { | ||
if (skippedTables.indexOf(table[tableName]) === -1) { | ||
db.query("DELETE FROM " + table[tableName], function() { | ||
@@ -62,5 +64,6 @@ count++; | ||
var length = tables.rows.length; | ||
var skippedTables = config.postgresql.skipTables; | ||
tables.rows.forEach(function(table) { | ||
if (table['table_name'] != 'schema_migrations') { | ||
if (skippedTables.indexOf(table['table_name']) === -1) { | ||
db.query("DELETE FROM " + "\"" + table['table_name'] + "\"", function() { | ||
@@ -67,0 +70,0 @@ count++; |
@@ -5,3 +5,3 @@ { | ||
"keywords" : [ "database", "cleaner", "mongodb", "redis", "couchdb", "tests", "package.json" ], | ||
"version" : "0.9.2", | ||
"version" : "0.10.0", | ||
"author" : "Emerson Macedo <emerleite@gmail.com>", | ||
@@ -8,0 +8,0 @@ "repository" : { |
@@ -23,7 +23,10 @@ var should = require('should'), | ||
client.query('INSERT INTO test1(title) VALUES(?)', ["foobar"], function() { | ||
client.query('INSERT INTO test2(title) VALUES(?)', ["foobar"], done); | ||
client.query('INSERT INTO test2(title) VALUES(?)', ["foobar"], function() { | ||
client.query('CREATE TABLE schema_migrations (id INTEGER NOT NULL AUTO_INCREMENT, version VARCHAR(255) NOT NULL, PRIMARY KEY(id));', function() { | ||
client.query('INSERT INTO schema_migrations(version) VALUES(?)', ["20150716190240"], done); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
@@ -34,4 +37,5 @@ | ||
client.query("DROP TABLE test2", function() { | ||
client.end(); | ||
done(); | ||
client.query("DROP TABLE schema_migrations", function() { | ||
done(); | ||
}) | ||
}); | ||
@@ -41,3 +45,3 @@ }); | ||
it('should delete all records', function(done) { | ||
it('should delete all not skippedTables records', function(done) { | ||
databaseCleaner.clean(client, function() { | ||
@@ -54,2 +58,10 @@ client.query("SELECT * FROM test1", function(err, result_test1) { | ||
it('should retain schema_migrations', function(done) { | ||
databaseCleaner.clean(client, function() { | ||
client.query("SELECT * FROM schema_migrations", function(err, result) { | ||
result.length.should.equal(1); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
@@ -31,7 +31,11 @@ var should = require('should'), | ||
client.query('CREATE TABLE \"Test3\" (id SERIAL, title VARCHAR(255) NOT NULL, PRIMARY KEY(id));', function() { | ||
client.query('INSERT INTO test1 (title) VALUES ($1);', ["foobar"], function() { | ||
client.query('INSERT INTO test2 (title) VALUES ($1);', ["foobar"], function() { | ||
client.query('INSERT INTO \"Test3\" (title) VALUES ($1);', ["foobar"], function() { | ||
done(); | ||
_done(); | ||
client.query('CREATE TABLE schema_migrations (id SERIAL, version VARCHAR(255) NOT NULL, PRIMARY KEY(id));', function() { | ||
client.query('INSERT INTO test1 (title) VALUES ($1);', ["foobar"], function() { | ||
client.query('INSERT INTO test2 (title) VALUES ($1);', ["foobar"], function() { | ||
client.query('INSERT INTO \"Test3\" (title) VALUES ($1);', ["foobar"], function() { | ||
client.query('INSERT INTO schema_migrations (version) VALUES ($1);', ["20150716190240"], function() { | ||
done(); | ||
_done(); | ||
}); | ||
}); | ||
}); | ||
@@ -44,3 +48,2 @@ }); | ||
}); | ||
}); | ||
@@ -55,4 +58,6 @@ | ||
client.query("DROP TABLE \"Test3\"", function() { | ||
done(); | ||
_done(); | ||
client.query("DROP TABLE schema_migrations", function() { | ||
done(); | ||
_done(); | ||
}); | ||
}); | ||
@@ -64,3 +69,3 @@ }); | ||
it('should delete all records', function(done) { | ||
it('should delete all non skippedTable records', function(done) { | ||
_done = done; | ||
@@ -102,2 +107,15 @@ | ||
it('should retain schema_migrations', function(done) { | ||
_done = done; | ||
pg.connect(connectionString, function(err, client, done) { | ||
databaseCleaner.clean(client, function() { | ||
client.query("SELECT * FROM schema_migrations", function(err, result) { | ||
result.rows.length.should.equal(1); | ||
done(); | ||
_done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
18899
10.91%14
7.69%357
13.33%0
-100%