From 734173f7c54c3e7283d1dcd2ad9499bc0a93cb9b Mon Sep 17 00:00:00 2001 From: fogelito Date: Sun, 20 Jul 2025 10:53:16 +0300 Subject: [PATCH 1/5] Disable array index through validator --- src/Database/Database.php | 17 ++++++----------- src/Database/Validator/Index.php | 10 +++++++++- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/Database/Database.php b/src/Database/Database.php index 3cba68080..0abc10afc 100644 --- a/src/Database/Database.php +++ b/src/Database/Database.php @@ -1242,10 +1242,6 @@ public function createCollection(string $id, array $attributes = [], array $inde $isArray = $collectionAttribute->getAttribute('array', false); if ($isArray) { - if (!$this->adapter->getSupportForIndexArray()) { - throw new IndexException('Indexing an array attribute is not supported'); - } - if ($this->adapter->getMaxIndexLength() > 0) { $lengths[$i] = self::ARRAY_INDEX_LENGTH; } @@ -1274,7 +1270,8 @@ public function createCollection(string $id, array $attributes = [], array $inde $validator = new IndexValidator( $attributes, $this->adapter->getMaxIndexLength(), - $this->adapter->getInternalIndexesKeys() + $this->adapter->getInternalIndexesKeys(), + $this->adapter->getSupportForIndexArray() ); foreach ($indexes as $index) { if (!$validator->isValid($index)) { @@ -2199,7 +2196,8 @@ public function updateAttribute(string $collection, string $id, ?string $type = $validator = new IndexValidator( $attributes, $this->adapter->getMaxIndexLength(), - $this->adapter->getInternalIndexesKeys() + $this->adapter->getInternalIndexesKeys(), + $this->adapter->getSupportForIndexArray() ); foreach ($indexes as $index) { @@ -3079,10 +3077,6 @@ public function createIndex(string $collection, string $id, string $type, array $isArray = $collectionAttribute->getAttribute('array', false); if ($isArray) { - if (!$this->adapter->getSupportForIndexArray()) { - throw new IndexException('Indexing an array attribute is not supported'); - } - if ($this->adapter->getMaxIndexLength() > 0) { $lengths[$i] = self::ARRAY_INDEX_LENGTH; } @@ -3108,7 +3102,8 @@ public function createIndex(string $collection, string $id, string $type, array $validator = new IndexValidator( $collection->getAttribute('attributes', []), $this->adapter->getMaxIndexLength(), - $this->adapter->getInternalIndexesKeys() + $this->adapter->getInternalIndexesKeys(), + $this->adapter->getSupportForIndexArray() ); if (!$validator->isValid($index)) { throw new IndexException($validator->getDescription()); diff --git a/src/Database/Validator/Index.php b/src/Database/Validator/Index.php index 5452471cb..9f28b85d3 100644 --- a/src/Database/Validator/Index.php +++ b/src/Database/Validator/Index.php @@ -22,16 +22,19 @@ class Index extends Validator */ protected array $reservedKeys; + protected bool $arrayIndexSupport; + /** * @param array $attributes * @param int $maxLength * @param array $reservedKeys * @throws DatabaseException */ - public function __construct(array $attributes, int $maxLength, array $reservedKeys = []) + public function __construct(array $attributes, int $maxLength, array $reservedKeys = [], $arrayIndexSupport = false) { $this->maxLength = $maxLength; $this->reservedKeys = $reservedKeys; + $this->arrayIndexSupport = $arrayIndexSupport; foreach ($attributes as $attribute) { $key = \strtolower($attribute->getAttribute('key', $attribute->getAttribute('$id'))); @@ -156,6 +159,11 @@ public function checkArrayIndex(Document $index): bool $this->message = 'Invalid index order "' . $direction . '" on array attribute "'. $attribute->getAttribute('key', '') .'"'; return false; } + + if ($this->arrayIndexSupport === false) { + $this->message = 'Indexing an array attribute is temporarily disabled'; + return false; + } } elseif ($attribute->getAttribute('type') !== Database::VAR_STRING && !empty($lengths[$attributePosition])) { $this->message = 'Cannot set a length on "'. $attribute->getAttribute('type') . '" attributes'; return false; From d17c90d0ceb0dcc550bbd0313921c150acb7607a Mon Sep 17 00:00:00 2001 From: fogelito Date: Sun, 20 Jul 2025 10:56:04 +0300 Subject: [PATCH 2/5] MariaDB disable getSupportForIndexArray --- src/Database/Adapter/MariaDB.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Database/Adapter/MariaDB.php b/src/Database/Adapter/MariaDB.php index 708926548..e7167eaae 100644 --- a/src/Database/Adapter/MariaDB.php +++ b/src/Database/Adapter/MariaDB.php @@ -2120,4 +2120,12 @@ public function getSupportForNumericCasting(): bool { return true; } + + public function getSupportForIndexArray(): bool + { + /** + * Added for Appwrite tests + */ + return false; + } } From 9e2895b92cb094436973d5f8f30d75014bf03ae6 Mon Sep 17 00:00:00 2001 From: fogelito Date: Sun, 20 Jul 2025 11:28:54 +0300 Subject: [PATCH 3/5] Add bool type --- src/Database/Validator/Index.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Database/Validator/Index.php b/src/Database/Validator/Index.php index 9f28b85d3..f236006f1 100644 --- a/src/Database/Validator/Index.php +++ b/src/Database/Validator/Index.php @@ -28,9 +28,10 @@ class Index extends Validator * @param array $attributes * @param int $maxLength * @param array $reservedKeys + * @param bool $arrayIndexSupport * @throws DatabaseException */ - public function __construct(array $attributes, int $maxLength, array $reservedKeys = [], $arrayIndexSupport = false) + public function __construct(array $attributes, int $maxLength, array $reservedKeys = [], bool $arrayIndexSupport = false) { $this->maxLength = $maxLength; $this->reservedKeys = $reservedKeys; From c07119d2f32b52b61cb5bd0daf50eb8d52ef7c36 Mon Sep 17 00:00:00 2001 From: fogelito Date: Sun, 20 Jul 2025 11:38:53 +0300 Subject: [PATCH 4/5] Message --- src/Database/Adapter/MariaDB.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Database/Adapter/MariaDB.php b/src/Database/Adapter/MariaDB.php index e7167eaae..19769749b 100644 --- a/src/Database/Adapter/MariaDB.php +++ b/src/Database/Adapter/MariaDB.php @@ -2124,7 +2124,7 @@ public function getSupportForNumericCasting(): bool public function getSupportForIndexArray(): bool { /** - * Added for Appwrite tests + * Disabled to be compatible with Mysql adapter */ return false; } From 8367f40c88abbf0e766edd825e973f79b5268033 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Mon, 21 Jul 2025 13:18:42 +1200 Subject: [PATCH 5/5] Update src/Database/Validator/Index.php --- src/Database/Validator/Index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Database/Validator/Index.php b/src/Database/Validator/Index.php index f236006f1..69029730a 100644 --- a/src/Database/Validator/Index.php +++ b/src/Database/Validator/Index.php @@ -162,7 +162,7 @@ public function checkArrayIndex(Document $index): bool } if ($this->arrayIndexSupport === false) { - $this->message = 'Indexing an array attribute is temporarily disabled'; + $this->message = 'Indexing an array attribute is not supported'; return false; } } elseif ($attribute->getAttribute('type') !== Database::VAR_STRING && !empty($lengths[$attributePosition])) {