Permalink
Browse files

Created convenience script to reset the db

  • Loading branch information...
1 parent e069233 commit 3968f1c7cd428b902af2199624e0ea66a323dd9a @beatgammit committed Mar 3, 2011
Showing with 54 additions and 20 deletions.
  1. +52 −9 initDb.js
  2. +2 −0 resetDB.sh
  3. +0 −7 server/lib/dbaccess.js
  4. +0 −4 server/server.js
View
@@ -1,21 +1,64 @@
-var couchdb = require('couchdb-tmp'),
- client = couchdb.createClient(5984, 'www.beatgammit.com', "filesync", "Wh1t3Ch3dd3r"),
- db = client.db('filesync'),
+var cradle = require('cradle'),
+ client = new cradle.Connection('http://www.beatgammit.com', 5984, {
+ auth: {username: "filesync", password: "Wh1t3Ch3dd3r"}
+ }),
+ db = client.database('filesync'),
+ userDb = client.database('_users'),
tmd5Proto = function(doc){
emit(doc.tmd5, doc);
};
function initViews(){
var tDesign = {};
- tDesign.views = {};
- tDesign.views.tmd5 = {};
- tDesign.views.tmd5.map = tmd5Proto.toString();
+ tDesign.tmd5 = {};
+ tDesign.tmd5.map = tmd5Proto.toString();
- db.saveDesign('basic', tDesign);
+ db.save('_design/basic', tDesign);
}
db.exists(function(exists){
- if(!exists){
- db.create(initViews);
+ if(exists){
+ db.destroy();
+ }
+ db.create();
+ initViews();
+});
+
+userDb.get('org.couchdb.user:mvndaai', function(err, doc){
+ if(doc){
+ userDb.remove(doc._id, doc._rev, function(error, res){
+ console.log(error);
+ console.log(res);
+ });
+ var tUserDb = client.database(doc.name);
+ tUserDb.exists(function(exists){
+ if(exists){
+ tUserDb.destroy();
+ }
+ });
+ }
+});
+
+userDb.get('org.couchdb.user:coolaj86', function(err, doc){
+ if(doc){
+ userDb.remove(doc._id, doc._rev);
+ var tUserDb = client.database(doc.name);
+ tUserDb.exists(function(exists){
+ if(exists){
+ tUserDb.destroy();
+ }
+ });
+ }
+});
+
+userDb.get('org.couchdb.user:beatgammit', function(err, doc){
+ if(doc){
+ userDb.remove(doc._id, doc._rev);
+ var tUserDb = client.database(doc.name);
+ tUserDb.exists(function(exists){
+ if(exists){
+ tUserDb.destroy();
+ }
+ });
}
});
View
@@ -0,0 +1,2 @@
+node initDb.js
+./regUsers.sh
View
@@ -39,13 +39,10 @@
}
function getByMimeType(username, mimeType, callback){
- console.log("User: " + username);
- console.log("Mime: " + mimeType);
var userDb = client.database(username);
mimeType = mimeType.replace('/', '%2F');
userDb.view('type/' + mimeType, function(error, response){
- console.log(response);
var docArray = [];
if(error){
console.log("Epic error fail: " + JSON.stringify(error));
@@ -54,7 +51,6 @@
}
response['rows'].forEach(function(tDoc){
- console.log(JSON.stringify(tDoc.value));
docArray.push(tDoc.value);
});
@@ -64,7 +60,6 @@
function createViews(username, data){
var userDb;
- console.log("Create Views: " + username);
if(data && data.length){
userDb = client.database(username);
userDb.get('_design/type', function(error, doc){
@@ -124,8 +119,6 @@
function fileExists(filestat, filedata, username, callback){
filesyncdb.view('basic/' + 'tmd5', {startKey: filestat.tmd5, limit: 1},
function(err, response){
- console.log("Filestat:");
- console.log(filestat);
var tDb;
if(err || response.total_rows == 0){
filestat.exists = false;
View
@@ -30,7 +30,6 @@ var require;
}
// backup plan
- //console.log("Move Error: " + err);
var readStream = fs.createReadStream(oldPath),
writeStream = fs.createWriteStream(newPath);
@@ -44,7 +43,6 @@ var require;
};
function validateUserPassword(username, password, onSuccess, onFailure) {
- console.log("Validate");
if (authdb[username] && authdb[username] === password) {
if(onSuccess){
return onSuccess();
@@ -67,7 +65,6 @@ var require;
mimeType = req.params.field + "/" + req.params.value;
dbaccess.getByMimeType(req.remoteUser, mimeType, function(err, docArray){
- console.log(JSON.stringify(docArray));
res.writeHead(200, {'Content-Type': 'application/json'});
res.end(JSON.stringify(docArray));
});
@@ -81,7 +78,6 @@ var require;
var qData;
if(req.method == "GET"){
qData = qs.parse(url.parse(req.url).query);
- console.log(qData);
db.registerUser(qData.name, qData.pass, qData.data, function(cess){
res.writeHead(200, {'Content-Type': 'application/json'});
res.end(JSON.stringify(cess));

0 comments on commit 3968f1c

Please sign in to comment.