mirror of https://gitee.com/bigwinds/arangodb
issue #195: make arango-upgrade write VERSION file, add global Javascript variable DATABASEPATH
This commit is contained in:
parent
28bb0da87f
commit
650261faed
|
@ -740,6 +740,7 @@ int ArangoServer::executeConsole (OperationMode::server_operation_mode_e mode) {
|
||||||
sysTestFiles->Set((uint32_t) i, v8::String::New(_unitTests[i].c_str()));
|
sysTestFiles->Set((uint32_t) i, v8::String::New(_unitTests[i].c_str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
context->_context->Global()->Set(v8::String::New("DATABASEPATH"), v8::String::New(_databasePath.c_str()));
|
||||||
context->_context->Global()->Set(v8::String::New("VALGRIND"), _runningOnValgrind ? v8::True() : v8::False());
|
context->_context->Global()->Set(v8::String::New("VALGRIND"), _runningOnValgrind ? v8::True() : v8::False());
|
||||||
context->_context->Global()->Set(v8::String::New("SYS_UNIT_TESTS"), sysTestFiles);
|
context->_context->Global()->Set(v8::String::New("SYS_UNIT_TESTS"), sysTestFiles);
|
||||||
context->_context->Global()->Set(v8::String::New("SYS_UNIT_TESTS_RESULT"), v8::True());
|
context->_context->Global()->Set(v8::String::New("SYS_UNIT_TESTS_RESULT"), v8::True());
|
||||||
|
@ -774,6 +775,7 @@ int ArangoServer::executeConsole (OperationMode::server_operation_mode_e mode) {
|
||||||
sysTestFiles->Set((uint32_t) i, v8::String::New(_jslint[i].c_str()));
|
sysTestFiles->Set((uint32_t) i, v8::String::New(_jslint[i].c_str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
context->_context->Global()->Set(v8::String::New("DATABASEPATH"), v8::String::New(_databasePath.c_str()));
|
||||||
context->_context->Global()->Set(v8::String::New("VALGRIND"), _runningOnValgrind ? v8::True() : v8::False());
|
context->_context->Global()->Set(v8::String::New("VALGRIND"), _runningOnValgrind ? v8::True() : v8::False());
|
||||||
context->_context->Global()->Set(v8::String::New("SYS_UNIT_TESTS"), sysTestFiles);
|
context->_context->Global()->Set(v8::String::New("SYS_UNIT_TESTS"), sysTestFiles);
|
||||||
context->_context->Global()->Set(v8::String::New("SYS_UNIT_TESTS_RESULT"), v8::True());
|
context->_context->Global()->Set(v8::String::New("SYS_UNIT_TESTS_RESULT"), v8::True());
|
||||||
|
@ -799,6 +801,7 @@ int ArangoServer::executeConsole (OperationMode::server_operation_mode_e mode) {
|
||||||
case OperationMode::MODE_SCRIPT: {
|
case OperationMode::MODE_SCRIPT: {
|
||||||
v8::TryCatch tryCatch;
|
v8::TryCatch tryCatch;
|
||||||
|
|
||||||
|
context->_context->Global()->Set(v8::String::New("DATABASEPATH"), v8::String::New(_databasePath.c_str()));
|
||||||
context->_context->Global()->Set(v8::String::New("VALGRIND"), _runningOnValgrind ? v8::True() : v8::False());
|
context->_context->Global()->Set(v8::String::New("VALGRIND"), _runningOnValgrind ? v8::True() : v8::False());
|
||||||
|
|
||||||
for (size_t i = 0; i < _scriptFile.size(); ++i) {
|
for (size_t i = 0; i < _scriptFile.size(); ++i) {
|
||||||
|
@ -856,6 +859,7 @@ int ArangoServer::executeConsole (OperationMode::server_operation_mode_e mode) {
|
||||||
// .............................................................................
|
// .............................................................................
|
||||||
|
|
||||||
case OperationMode::MODE_CONSOLE: {
|
case OperationMode::MODE_CONSOLE: {
|
||||||
|
context->_context->Global()->Set(v8::String::New("DATABASEPATH"), v8::String::New(_databasePath.c_str()));
|
||||||
context->_context->Global()->Set(v8::String::New("VALGRIND"), _runningOnValgrind ? v8::True() : v8::False());
|
context->_context->Global()->Set(v8::String::New("VALGRIND"), _runningOnValgrind ? v8::True() : v8::False());
|
||||||
V8LineEditor* console = new V8LineEditor(context->_context, ".arango");
|
V8LineEditor* console = new V8LineEditor(context->_context, ".arango");
|
||||||
|
|
||||||
|
|
|
@ -39,11 +39,24 @@ function main (argv) {
|
||||||
var console = require("console");
|
var console = require("console");
|
||||||
var db = internal.db;
|
var db = internal.db;
|
||||||
|
|
||||||
var tasks = [ ];
|
var versionFile = DATABASEPATH + "/VERSION";
|
||||||
|
|
||||||
|
var allTasks = [ ];
|
||||||
|
var activeTasks = [ ];
|
||||||
|
|
||||||
|
var currentVersion = 0;
|
||||||
|
if (FS_EXISTS(versionFile)) {
|
||||||
|
currentVersion = parseInt(SYS_READ(versionFile));
|
||||||
|
}
|
||||||
|
|
||||||
// helper function to define tasks
|
// helper function to define tasks
|
||||||
function addTask (description, code) {
|
function addTask (description, maxVersion, code) {
|
||||||
tasks.push({ description: description, code: code });
|
var task = { description: description, maxVersion: maxVersion, code: code };
|
||||||
|
|
||||||
|
allTasks.push(task);
|
||||||
|
if (currentVersion < parseInt(maxVersion)) {
|
||||||
|
activeTasks.push(task);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
|
@ -51,7 +64,7 @@ function main (argv) {
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
// set up the collection _users
|
// set up the collection _users
|
||||||
addTask("setup _users collection", function () {
|
addTask("setup _users collection", 0, function () {
|
||||||
var users = db._collection("_users");
|
var users = db._collection("_users");
|
||||||
|
|
||||||
if (users == null) {
|
if (users == null) {
|
||||||
|
@ -66,7 +79,7 @@ function main (argv) {
|
||||||
});
|
});
|
||||||
|
|
||||||
// create a unique index on username attribute in _users
|
// create a unique index on username attribute in _users
|
||||||
addTask("create index on username attribute in _users collection", function () {
|
addTask("create index on username attribute in _users collection", 0, function () {
|
||||||
var users = db._collection("_users");
|
var users = db._collection("_users");
|
||||||
if (users == null) {
|
if (users == null) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -78,7 +91,7 @@ function main (argv) {
|
||||||
});
|
});
|
||||||
|
|
||||||
// add a default root user with no passwd
|
// add a default root user with no passwd
|
||||||
addTask("add default root user", function () {
|
addTask("add default root user", 0, function () {
|
||||||
var users = db._collection("_users");
|
var users = db._collection("_users");
|
||||||
if (users == null) {
|
if (users == null) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -93,7 +106,7 @@ function main (argv) {
|
||||||
});
|
});
|
||||||
|
|
||||||
// set up the collection _graphs
|
// set up the collection _graphs
|
||||||
addTask("setup _graphs collection", function () {
|
addTask("setup _graphs collection", 0, function () {
|
||||||
var graphs = db._collection("_graphs");
|
var graphs = db._collection("_graphs");
|
||||||
|
|
||||||
if (graphs == null) {
|
if (graphs == null) {
|
||||||
|
@ -108,7 +121,7 @@ function main (argv) {
|
||||||
});
|
});
|
||||||
|
|
||||||
// create a unique index on name attribute in _graphs
|
// create a unique index on name attribute in _graphs
|
||||||
addTask("create index on name attribute in _graphs collection", function () {
|
addTask("create index on name attribute in _graphs collection", 0, function () {
|
||||||
var graphs = db._collection("_graphs");
|
var graphs = db._collection("_graphs");
|
||||||
if (graphs == null) {
|
if (graphs == null) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -120,7 +133,7 @@ function main (argv) {
|
||||||
});
|
});
|
||||||
|
|
||||||
// make distinction between document and edge collections
|
// make distinction between document and edge collections
|
||||||
addTask("set new collection type for edge collections and update collection version", function () {
|
addTask("set new collection type for edge collections and update collection version", 0, function () {
|
||||||
var collections = db._collections();
|
var collections = db._collections();
|
||||||
|
|
||||||
for (var i in collections) {
|
for (var i in collections) {
|
||||||
|
@ -167,16 +180,24 @@ function main (argv) {
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// create the VERSION file
|
||||||
|
addTask("create VERSION file", 0, function () {
|
||||||
|
SYS_SAVE(versionFile, "1");
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
console.log("Upgrade script " + argv[0] + " started");
|
console.log("Upgrade script " + argv[0] + " started");
|
||||||
|
console.log("Server VERSION is: " + currentVersion);
|
||||||
|
|
||||||
// loop through all tasks and execute them
|
// loop through all tasks and execute them
|
||||||
console.log("Found " + tasks.length + " tasks to run...");
|
console.log("Found " + allTasks.length + " defined task(s), " + activeTasks.length + " task(s) to run");
|
||||||
for (var i in tasks) {
|
|
||||||
var task = tasks[i];
|
|
||||||
|
|
||||||
console.log("Executing task #" + i + ": " + task.description);
|
for (var i in activeTasks) {
|
||||||
|
var task = activeTasks[i];
|
||||||
|
|
||||||
|
console.log("Executing task #" + (i + 1) + ": " + task.description);
|
||||||
|
|
||||||
var result = task.code();
|
var result = task.code();
|
||||||
if (! result) {
|
if (! result) {
|
||||||
|
|
Loading…
Reference in New Issue