From 6635ebf27fda77ddab3771f49ae274ebaffd18a5 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Mon, 20 Feb 2023 19:29:25 +1300 Subject: [PATCH 1/3] Remove indexed attribute query requirement --- app/controllers/api/databases.php | 2 +- .../Utopia/Database/Validator/IndexedQueries.php | 2 +- .../Database/Validator/Queries/Documents.php | 14 +++++++------- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index 88242482a1..bda5169338 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -2004,7 +2004,7 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/documents') } // Validate queries - $queriesValidator = new Documents($collection->getAttribute('attributes'), $collection->getAttribute('indexes')); + $queriesValidator = new Documents($collection->getAttribute('attributes')); $validQueries = $queriesValidator->isValid($queries); if (!$validQueries) { throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, $queriesValidator->getDescription()); diff --git a/src/Appwrite/Utopia/Database/Validator/IndexedQueries.php b/src/Appwrite/Utopia/Database/Validator/IndexedQueries.php index 1cc0429018..e36ba45928 100644 --- a/src/Appwrite/Utopia/Database/Validator/IndexedQueries.php +++ b/src/Appwrite/Utopia/Database/Validator/IndexedQueries.php @@ -27,7 +27,7 @@ class IndexedQueries extends Queries * @param Document[] $attributes * @param Document[] $indexes * @param Base ...$validators - * @param bool $strict + * @throws \Exception */ public function __construct($attributes = [], $indexes = [], Base ...$validators) { diff --git a/src/Appwrite/Utopia/Database/Validator/Queries/Documents.php b/src/Appwrite/Utopia/Database/Validator/Queries/Documents.php index fe1e85d699..27a09ea99b 100644 --- a/src/Appwrite/Utopia/Database/Validator/Queries/Documents.php +++ b/src/Appwrite/Utopia/Database/Validator/Queries/Documents.php @@ -2,24 +2,24 @@ namespace Appwrite\Utopia\Database\Validator\Queries; -use Appwrite\Utopia\Database\Validator\IndexedQueries; -use Appwrite\Utopia\Database\Validator\Query\Limit; -use Appwrite\Utopia\Database\Validator\Query\Offset; +use Appwrite\Utopia\Database\Validator\Queries; use Appwrite\Utopia\Database\Validator\Query\Cursor; use Appwrite\Utopia\Database\Validator\Query\Filter; +use Appwrite\Utopia\Database\Validator\Query\Limit; +use Appwrite\Utopia\Database\Validator\Query\Offset; use Appwrite\Utopia\Database\Validator\Query\Order; use Utopia\Database\Database; use Utopia\Database\Document; -class Documents extends IndexedQueries +class Documents extends Queries { /** * Expression constructor * * @param Document[] $attributes - * @param Document[] $indexes + * @throws \Exception */ - public function __construct(array $attributes, array $indexes) + public function __construct(array $attributes) { $attributes[] = new Document([ 'key' => '$id', @@ -45,6 +45,6 @@ class Documents extends IndexedQueries new Order($attributes), ]; - parent::__construct($attributes, $indexes, ...$validators); + parent::__construct(...$validators); } } From b8c11a5643f0c97babccf1545515555e199de3f0 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Tue, 21 Feb 2023 13:38:19 +1300 Subject: [PATCH 2/3] Fix test --- tests/e2e/Services/Databases/DatabasesBase.php | 9 --------- 1 file changed, 9 deletions(-) diff --git a/tests/e2e/Services/Databases/DatabasesBase.php b/tests/e2e/Services/Databases/DatabasesBase.php index 13a95c9f09..355ee2b24c 100644 --- a/tests/e2e/Services/Databases/DatabasesBase.php +++ b/tests/e2e/Services/Databases/DatabasesBase.php @@ -1443,15 +1443,6 @@ trait DatabasesBase /** * Test for Failure */ - $documents = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $data['moviesId'] . '/documents', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ - 'queries' => ['equal("actors", "Tom Holland")'], - ]); - $this->assertEquals(400, $documents['headers']['status-code']); - $this->assertEquals('Index not found: actors', $documents['body']['message']); - $conditions = []; for ($i = 0; $i < 101; $i++) { From a28eaa80cfeeae4acba2a183438e1d4623748173 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Tue, 28 Feb 2023 16:52:11 +1300 Subject: [PATCH 3/3] Add test asserting indexes not required --- tests/e2e/Services/Databases/DatabasesBase.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/e2e/Services/Databases/DatabasesBase.php b/tests/e2e/Services/Databases/DatabasesBase.php index 355ee2b24c..3b4c8822e0 100644 --- a/tests/e2e/Services/Databases/DatabasesBase.php +++ b/tests/e2e/Services/Databases/DatabasesBase.php @@ -1440,6 +1440,14 @@ trait DatabasesBase $this->assertCount(0, $documents['body']['documents']); + $documents = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $data['moviesId'] . '/documents', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'queries' => ['equal("actors", "Tom Holland")'], + ]); + $this->assertEquals(200, $documents['headers']['status-code']); + /** * Test for Failure */