Skip to content

Commit

Permalink
Merge pull request #36 from codeforamerica/clear-test-db
Browse files Browse the repository at this point in the history
Maintenance tool for clearing the test DB
  • Loading branch information
hampelm committed Jan 22, 2013
2 parents f8b6a36 + 9b65add commit 772737a
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions maintenance/clearTestDb.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*jslint node: true */
/*
* Maintenance script to clear the test database
*
* Usage:
* $ node clearTestDb.js
*
*/
'use strict';

var mongo = require('mongodb');

var settings = require('../settings-test.js');
var db = new mongo.Db(settings.mongo_db, new mongo.Server(settings.mongo_host,
settings.mongo_port,
{}), {});

function clearDb(db) {
db.dropDatabase(function (err) {
if (err) {
console.log(err.message);
} else {
console.log('Dropped the database.');
}
db.close();
});
}

db.open(function() {
if (settings.mongo_user !== undefined) {
db.authenticate(settings.mongo_user, settings.mongo_password, function(err, result) {
if (err) {
console.log(err.message);
db.close();
return;
}
clearDb(db);
});
} else {
clearDb(db);
}
});

0 comments on commit 772737a

Please sign in to comment.