mirror of https://gitee.com/bigwinds/arangodb
handle id and isSystem when creating collections
This commit is contained in:
parent
36eac6ffd0
commit
3cfd8214a9
|
@ -1628,6 +1628,9 @@ static void CreateVocBase (const v8::FunctionCallbackInfo<v8::Value>& args,
|
|||
TRI_GET_GLOBAL_STRING(IsSystemKey);
|
||||
if (p->Has(IsSystemKey)) {
|
||||
parameters._isSystem = TRI_ObjectToBoolean(p->Get(IsSystemKey));
|
||||
if (name.empty() || name[0] != '_') {
|
||||
parameters._isSystem = false;
|
||||
}
|
||||
}
|
||||
|
||||
TRI_GET_GLOBAL_STRING(IsVolatileKey);
|
||||
|
|
|
@ -118,31 +118,35 @@ function parseBodyForCreateCollection (req, res) {
|
|||
else {
|
||||
r.name = body.name;
|
||||
}
|
||||
r.parameter = { waitForSync : false };
|
||||
r.parameters = { waitForSync : false };
|
||||
r.type = arangodb.ArangoCollection.TYPE_DOCUMENT;
|
||||
|
||||
if (body.hasOwnProperty("doCompact")) {
|
||||
r.parameter.doCompact = body.doCompact;
|
||||
r.parameters.doCompact = body.doCompact;
|
||||
}
|
||||
|
||||
if (body.hasOwnProperty("isSystem")) {
|
||||
r.parameter.isSystem = body.isSystem;
|
||||
r.parameters.isSystem = (body.isSystem && r.name[0] === '_');
|
||||
}
|
||||
|
||||
if (body.hasOwnProperty("id")) {
|
||||
r.parameters.id = body.id;
|
||||
}
|
||||
|
||||
if (body.hasOwnProperty("isVolatile")) {
|
||||
r.parameter.isVolatile = body.isVolatile;
|
||||
r.parameters.isVolatile = body.isVolatile;
|
||||
}
|
||||
|
||||
if (body.hasOwnProperty("journalSize")) {
|
||||
r.parameter.journalSize = body.journalSize;
|
||||
r.parameters.journalSize = body.journalSize;
|
||||
}
|
||||
|
||||
if (body.hasOwnProperty("indexBuckets")) {
|
||||
r.parameter.indexBuckets = body.indexBuckets;
|
||||
r.parameters.indexBuckets = body.indexBuckets;
|
||||
}
|
||||
|
||||
if (body.hasOwnProperty("keyOptions")) {
|
||||
r.parameter.keyOptions = body.keyOptions;
|
||||
r.parameters.keyOptions = body.keyOptions;
|
||||
}
|
||||
|
||||
if (body.hasOwnProperty("type")) {
|
||||
|
@ -150,19 +154,19 @@ function parseBodyForCreateCollection (req, res) {
|
|||
}
|
||||
|
||||
if (body.hasOwnProperty("waitForSync")) {
|
||||
r.parameter.waitForSync = body.waitForSync;
|
||||
r.parameters.waitForSync = body.waitForSync;
|
||||
}
|
||||
|
||||
if (body.hasOwnProperty("shardKeys") && cluster.isCoordinator()) {
|
||||
r.parameter.shardKeys = body.shardKeys || { };
|
||||
r.parameters.shardKeys = body.shardKeys || { };
|
||||
}
|
||||
|
||||
if (body.hasOwnProperty("numberOfShards") && cluster.isCoordinator()) {
|
||||
r.parameter.numberOfShards = body.numberOfShards || 0;
|
||||
r.parameters.numberOfShards = body.numberOfShards || 0;
|
||||
}
|
||||
|
||||
if (body.hasOwnProperty("distributeShardsLike") && cluster.isCoordinator()) {
|
||||
r.parameter.distributeShardsLike = body.distributeShardsLike || "";
|
||||
r.parameters.distributeShardsLike = body.distributeShardsLike || "";
|
||||
}
|
||||
|
||||
return r;
|
||||
|
@ -348,19 +352,19 @@ function post_api_collection (req, res) {
|
|||
}
|
||||
}
|
||||
if (r.type === arangodb.ArangoCollection.TYPE_EDGE) {
|
||||
collection = arangodb.db._createEdgeCollection(r.name, r.parameter);
|
||||
collection = arangodb.db._createEdgeCollection(r.name, r.parameters);
|
||||
}
|
||||
else {
|
||||
collection = arangodb.db._createDocumentCollection(r.name, r.parameter);
|
||||
collection = arangodb.db._createDocumentCollection(r.name, r.parameters);
|
||||
}
|
||||
|
||||
var result = {};
|
||||
|
||||
result.id = collection._id;
|
||||
result.name = collection.name();
|
||||
result.waitForSync = r.parameter.waitForSync || false;
|
||||
result.isVolatile = r.parameter.isVolatile || false;
|
||||
result.isSystem = r.parameter.isSystem || false;
|
||||
result.waitForSync = r.parameters.waitForSync || false;
|
||||
result.isVolatile = r.parameters.isVolatile || false;
|
||||
result.isSystem = r.parameters.isSystem || false;
|
||||
result.status = collection.status();
|
||||
result.type = collection.type();
|
||||
result.keyOptions = collection.keyOptions;
|
||||
|
|
|
@ -315,7 +315,7 @@ ArangoDatabase.prototype._create = function (name, properties, type) {
|
|||
if (properties !== undefined) {
|
||||
[ "waitForSync", "journalSize", "isSystem", "isVolatile",
|
||||
"doCompact", "keyOptions", "shardKeys", "numberOfShards",
|
||||
"distributeShardsLike", "indexBuckets" ].forEach(function(p) {
|
||||
"distributeShardsLike", "indexBuckets", "id" ].forEach(function(p) {
|
||||
if (properties.hasOwnProperty(p)) {
|
||||
body[p] = properties[p];
|
||||
}
|
||||
|
|
|
@ -695,7 +695,6 @@ function processQuery (query, explain) {
|
|||
rc += " , " + variableName(node.pathOutVariable) +
|
||||
" " + annotation("/* paths */");
|
||||
}
|
||||
require("internal").print(node);
|
||||
rc += " " +
|
||||
keyword("IN") + " " +
|
||||
value(node.minMaxDepth) + " " + annotation("/* min..maxPathDepth */") + " ";
|
||||
|
|
|
@ -314,7 +314,7 @@ ArangoDatabase.prototype._create = function (name, properties, type) {
|
|||
if (properties !== undefined) {
|
||||
[ "waitForSync", "journalSize", "isSystem", "isVolatile",
|
||||
"doCompact", "keyOptions", "shardKeys", "numberOfShards",
|
||||
"distributeShardsLike", "indexBuckets" ].forEach(function(p) {
|
||||
"distributeShardsLike", "indexBuckets", "id" ].forEach(function(p) {
|
||||
if (properties.hasOwnProperty(p)) {
|
||||
body[p] = properties[p];
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*jshint globalstrict:false, strict:false */
|
||||
/*global assertEqual, assertTypeOf, assertNotEqual, assertTrue, assertNull, assertUndefined, fail */
|
||||
/*global assertEqual, assertTypeOf, assertNotEqual, assertTrue, assertFalse, assertNull, assertUndefined, fail */
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief test the collection interface
|
||||
|
@ -205,6 +205,80 @@ function CollectionSuiteErrorHandling () {
|
|||
function CollectionSuite () {
|
||||
return {
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief create with id
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
testCreateWithId : function () {
|
||||
var cn = "example", id = "1234567890";
|
||||
|
||||
db._drop(cn);
|
||||
db._drop(id);
|
||||
var c1 = db._create(cn, { id: id });
|
||||
|
||||
assertTypeOf("string", c1._id);
|
||||
assertEqual(id, c1._id);
|
||||
assertEqual(cn, c1.name());
|
||||
assertTypeOf("number", c1.status());
|
||||
|
||||
var c2 = db._collection(cn);
|
||||
|
||||
assertEqual(c1._id, c2._id);
|
||||
assertEqual(c1.name(), c2.name());
|
||||
assertEqual(c1.status(), c2.status());
|
||||
|
||||
db._drop(cn);
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief isSystem
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
testCreateWithIsSystem : function () {
|
||||
var cn = "example";
|
||||
|
||||
db._drop(cn);
|
||||
var c1 = db._create(cn, { isSystem: true });
|
||||
|
||||
assertTypeOf("string", c1._id);
|
||||
assertEqual(cn, c1.name());
|
||||
assertFalse(c1.properties().isSystem);
|
||||
|
||||
db._drop(cn);
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief isSystem
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
testCreateWithUnderscoreNoIsSystem : function () {
|
||||
var cn = "_example";
|
||||
|
||||
db._drop(cn);
|
||||
try {
|
||||
db._create(cn, { isSystem: false });
|
||||
fail();
|
||||
}
|
||||
catch (err) {
|
||||
assertEqual(ERRORS.ERROR_ARANGO_ILLEGAL_NAME.code, err.errorNum);
|
||||
}
|
||||
|
||||
db._drop(cn);
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief isSystem
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
testCreateWithUnderscoreWithIsSystem : function () {
|
||||
var cn = "_example";
|
||||
|
||||
db._drop(cn);
|
||||
var c1 = db._create(cn, { isSystem: true });
|
||||
assertTrue(c1.properties().isSystem);
|
||||
db._drop(cn);
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief long name
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
Loading…
Reference in New Issue