You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

database-cleaner

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

database-cleaner - npm Package Compare versions

Comparing version

to
0.10.0

config/cleaner-config.js

@@ -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 @@ ==================

7

lib/database-cleaner.js
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();
});
});
});
});
});