From 6d2861ec5e8de4d234f99c0725199b3470c4545b Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Tue, 23 Oct 2012 15:54:52 +0200 Subject: [PATCH] fixed arango-upgrade --- js/server/arango-upgrade.js | 86 +++++++++++++++---------------------- 1 file changed, 34 insertions(+), 52 deletions(-) diff --git a/js/server/arango-upgrade.js b/js/server/arango-upgrade.js index 121dbe8be8..30b9714aec 100644 --- a/js/server/arango-upgrade.js +++ b/js/server/arango-upgrade.js @@ -71,6 +71,30 @@ function main (argv) { } } + function getCollection (name) { + return db._collection(name); + } + + function collectionExists (name) { + var collection = getCollection(name); + return (collection != undefined) && (collection != null) && (collection.name() == name); + } + + function createSystemCollection (name, attributes) { + if (collectionExists(name)) { + return true; + } + + var realAttributes = attributes || { }; + realAttributes['isSystem'] = true; + + if (db._create(name, realAttributes)) { + return true; + } + + return collectionExists(name); + } + // -------------------------------------------------------------------------- // the actual upgrade tasks. all tasks defined here should be "re-entrant" @@ -78,25 +102,13 @@ function main (argv) { // set up the collection _users addTask("setup _users collection", 1, function () { - var users = db._collection("_users"); - - if (users == null) { - users = db._create("_users", { isSystem: true, waitForSync: true }); - - if (users == null) { - console.error("creating users collection '_users' failed"); - return false; - } - } - - return true; + return createSystemCollection("_users", { waitForSync : true }); }); // create a unique index on username attribute in _users addTask("create index on username attribute in _users collection", 1, function () { - var users = db._collection("_users"); - - if (users == null) { + var users = getCollection("_users"); + if (! users) { return false; } @@ -107,9 +119,8 @@ function main (argv) { // add a default root user with no passwd addTask("add default root user", 1, function () { - var users = db._collection("_users"); - - if (users == null) { + var users = getCollection("_users"); + if (! users) { return false; } @@ -123,25 +134,14 @@ function main (argv) { // set up the collection _graphs addTask("setup _graphs collection", 1, function () { - var graphs = db._collection("_graphs"); - - if (graphs == null) { - graphs = db._create("_graphs", { isSystem: true, waitForSync: true }); - - if (graphs == null) { - console.error("creating graphs collection '_graphs' failed"); - return false; - } - } - - return true; + return createSystemCollection("_graphs", { waitForSync : true }); }); // create a unique index on name attribute in _graphs addTask("create index on name attribute in _graphs collection", 1, function () { - var graphs = db._collection("_graphs"); + var graphs = getCollection("_graphs"); - if (graphs == null) { + if (! graphs) { return false; } @@ -202,30 +202,12 @@ function main (argv) { // create the _modules collection addTask("setup _modules collection", 1, function () { - // create a collection named "_modules" - if (db._modules !== undefined) { - var modules = db._create("_modules", { isSystem: true }); - - if (modules == null) { - console.error("creating modules collection '_modules' failed"); - return false; - } - } - return true; + return createSystemCollection("_modules"); }); // create the _routing collection addTask("setup _routing collection", 1, function () { - // create a collection named "_routing" - if (db._routing !== undefined) { - var routing = db._create("_routing", { isSystem: true }); - - if (routing == null) { - console.error("creating routing collection '_routing' failed"); - return false; - } - } - return true; + return createSystemCollection("_routing"); }); // create the VERSION file