couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From robertkowal...@apache.org
Subject fauxton commit: updated refs/heads/master to bb920c6
Date Tue, 01 Nov 2016 18:21:29 GMT
Repository: couchdb-fauxton
Updated Branches:
  refs/heads/master e118d93b2 -> bb920c60f


add script to create/delete a lot dbs

this is useful to create a lot of dbs for testing and later to
get rid of them

PR: #791
PR-URL: https://github.com/apache/couchdb-fauxton/pull/791
Reviewed-By: garren smith <garren.smith@gmail.com>
Reviewed-By: Ryan Millay


Project: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/commit/bb920c60
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/tree/bb920c60
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/diff/bb920c60

Branch: refs/heads/master
Commit: bb920c60fdbd49d6dcdd44bcb6cb198a709d648b
Parents: e118d93
Author: Robert Kowalski <robertkowalski@apache.org>
Authored: Fri Oct 21 15:02:33 2016 +0200
Committer: Robert Kowalski <robertkowalski@apache.org>
Committed: Tue Nov 1 19:21:19 2016 +0100

----------------------------------------------------------------------
 bin/create-n-dbs | 131 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 131 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/bb920c60/bin/create-n-dbs
----------------------------------------------------------------------
diff --git a/bin/create-n-dbs b/bin/create-n-dbs
new file mode 100755
index 0000000..2874e9e
--- /dev/null
+++ b/bin/create-n-dbs
@@ -0,0 +1,131 @@
+#!/usr/bin/env node
+
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
+
+const optimist = require('optimist');
+const nano = require('nano');
+
+const {parallelLimit} = require('async');
+
+
+const NAMESPACE = 'test-db-';
+const PARALLEL_LIMIT = 50;
+const URL = 'http://localhost:5984';
+
+optimist
+  .usage('Create a certain amount of dbs \nUsage: $0')
+
+  .options('help', {
+    alias: 'h',
+    describe: 'Show this message'
+  })
+  .options('number', {
+    alias: 'n',
+    describe: 'The amount of databases to create'
+  })
+  .options('delete', {
+    alias: 'd',
+    default: false,
+    describe: 'Delete databases'
+  });
+
+const argv = optimist.argv;
+
+if (argv.help || argv.h) {
+  return optimist.showHelp(console.log);
+}
+
+const isDelete = (argv.d || argv.delete);
+const isCreate = (argv.n || argv.number);
+
+if (!isDelete && !isCreate) {
+  console.error('[ERROR] Please provide -d or -n to delete or create test-databases \n');
+  optimist.showHelp(console.log);
+  process.exit(1);
+}
+
+const nClient = nano(URL)
+
+if (isCreate) {
+  return createNdbs(argv.n || argv.number);
+}
+
+if (isDelete) {
+  return deleteDbs();
+}
+
+function getExistingDbs (cb) {
+  nClient.db.list((err, body) => {
+    if (err) {
+      throw err;
+    }
+
+    const list = body.filter(db => {
+      return new RegExp(NAMESPACE).test(db);
+    });
+
+    cb(null, list);
+  });
+}
+
+function createNdbs (number) {
+  getExistingDbs((err, dbs) => {
+    const offset = dbs.length;
+
+    const newDbs = [];
+    for (let i = offset; i < offset + number; i++) {
+      newDbs.push(NAMESPACE + i);
+    }
+
+    const tasks = newDbs.map((db) => {
+      return function task (cb) {
+        nClient.db.create(db, (err, body) => {
+          if (err) {
+            console.error(err);
+          }
+
+          cb(null);
+        });
+      }
+    });
+
+    parallelLimit(tasks, PARALLEL_LIMIT, (err) => {
+      if (err) {
+        console.error(err);
+      }
+    });
+  });
+}
+
+function deleteDbs () {
+  getExistingDbs((err, dbs) => {
+    const list = dbs.map(db => {
+      return (cb) => {
+        nClient.db.destroy(db, (err, resp) => {
+          if (err) {
+            cb(err);
+            return;
+          }
+
+          cb(null);
+        });
+      };
+    });
+
+    parallelLimit(list, PARALLEL_LIMIT, (err) => {
+      if (err) {
+        console.error(err);
+      }
+    });
+  });
+}


Mime
View raw message