diff --git a/src/Database/Validator/Index.php b/src/Database/Validator/Index.php index 65a7c9de5..07c5b3688 100644 --- a/src/Database/Validator/Index.php +++ b/src/Database/Validator/Index.php @@ -104,7 +104,7 @@ public function checkIndexLength(Document $collection): bool { foreach ($collection->getAttribute('indexes', []) as $index) { if ($index->getAttribute('type') === Database::INDEX_FULLTEXT) { - return true; + continue; } $total = 0; diff --git a/tests/Database/Validator/IndexTest.php b/tests/Database/Validator/IndexTest.php index ea6a349f4..7d4d86ee6 100644 --- a/tests/Database/Validator/IndexTest.php +++ b/tests/Database/Validator/IndexTest.php @@ -106,6 +106,61 @@ public function testIndexLength(): void $this->assertEquals('Index length is longer than the maximum: 768', $validator->getDescription()); } + /** + * @throws Exception + */ + public function testMultipleIndexLength(): void + { + $validator = new Index(768); + + $collection = new Document([ + '$id' => ID::custom('test'), + 'name' => 'test', + 'attributes' => [ + new Document([ + '$id' => ID::custom('title'), + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => 256, + 'signed' => true, + 'required' => false, + 'default' => null, + 'array' => false, + 'filters' => [], + ]), + new Document([ + '$id' => ID::custom('description'), + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => 1024, + 'signed' => true, + 'required' => false, + 'default' => null, + 'array' => false, + 'filters' => [], + ]), + ], + 'indexes' => [ + new Document([ + '$id' => ID::custom('index1'), + 'type' => Database::INDEX_FULLTEXT, + 'attributes' => ['title'], + ]), + ], + ]); + + $this->assertTrue($validator->isValid($collection)); + + $collection->setAttribute('indexes', new Document([ + '$id' => ID::custom('index2'), + 'type' => Database::INDEX_KEY, + 'attributes' => ['title', 'description'], + ]), Document::SET_TYPE_APPEND); + + $this->assertFalse($validator->isValid($collection)); + $this->assertEquals('Index length is longer than the maximum: 768', $validator->getDescription()); + } + /** * @throws Exception */