Disallow index creation on relationship attributes

This commit is contained in:
Jake Barnby
2023-03-31 18:06:50 +13:00
parent c7201cc417
commit 578d4d1619
2 changed files with 9 additions and 0 deletions
+5
View File
@@ -455,6 +455,11 @@ return [
'description' => 'The attribute value is invalid. Please check the type, range and value of the attribute.',
'code' => 400,
],
Exception::ATTRIBUTE_TYPE_INVALID => [
'name' => Exception::ATTRIBUTE_TYPE_INVALID,
'description' => 'The attribute type is invalid.',
'code' => 400,
],
/** Indexes */
Exception::INDEX_NOT_FOUND => [
+4
View File
@@ -2391,6 +2391,10 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/indexes')
$attributeType = $oldAttributes[$attributeIndex]['type'];
$attributeSize = $oldAttributes[$attributeIndex]['size'];
if ($attributeType === Database::VAR_RELATIONSHIP) {
throw new Exception(Exception::ATTRIBUTE_TYPE_INVALID, 'Cannot create an index for a relationship attribute: ' . $oldAttributes[$attributeIndex]['key']);
}
// ensure attribute is available
if ($attributeStatus !== 'available') {
throw new Exception(Exception::ATTRIBUTE_NOT_AVAILABLE, 'Attribute not available: ' . $oldAttributes[$attributeIndex]['key']);