Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Database/Validator/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public function checkIndexLength(Document $index): bool
switch ($attribute->getAttribute('type')) {
case Database::VAR_STRING:
$attributeSize = $attribute->getAttribute('size', 0);
$indexLength = $lengths[$attributePosition] ?? $attributeSize;
$indexLength = !empty($lengths[$attributePosition]) ? $lengths[$attributePosition] : $attributeSize;
break;
case Database::VAR_FLOAT:
$attributeSize = 2; // 8 bytes / 4 mb4
Expand Down
34 changes: 32 additions & 2 deletions tests/e2e/Adapter/Scopes/IndexTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ public function testIndexValidation(): void
$validator = new Index(
$attributes,
$database->getAdapter()->getMaxIndexLength(),
$database->getAdapter()->getInternalIndexesKeys()
$database->getAdapter()->getInternalIndexesKeys(),
$database->getAdapter()->getSupportForIndexArray()
);

$errorMessage = 'Index length 701 is larger than the size for title1: 700"';
Expand Down Expand Up @@ -239,7 +240,8 @@ public function testIndexValidation(): void
$validator = new Index(
$attributes,
$database->getAdapter()->getMaxIndexLength(),
$database->getAdapter()->getInternalIndexesKeys()
$database->getAdapter()->getInternalIndexesKeys(),
$database->getAdapter()->getSupportForIndexArray()
);
$errorMessage = 'Attribute "integer" cannot be part of a FULLTEXT index, must be of type string';
$this->assertFalse($validator->isValid($indexes[0]));
Expand Down Expand Up @@ -296,6 +298,34 @@ public function testIndexValidation(): void
}
}

public function testIndexLengthZero(): void
{
/** @var Database $database */
$database = static::getDatabase();

$database->createCollection(__FUNCTION__);

$database->createAttribute(__FUNCTION__, 'title1', Database::VAR_STRING, 1000, true);

try {
$database->createIndex(__FUNCTION__, 'index_title1', Database::INDEX_KEY, ['title1'], [0]);
$this->fail('Failed to throw exception');
} catch (Throwable $e) {
$this->assertEquals('Index length is longer than the maximum: '.$database->getAdapter()->getMaxIndexLength(), $e->getMessage());
}


$database->createAttribute(__FUNCTION__, 'title2', Database::VAR_STRING, 100, true);
$database->createIndex(__FUNCTION__, 'index_title2', Database::INDEX_KEY, ['title2'], [0]);

try {
$database->updateAttribute(__FUNCTION__, 'title2', Database::VAR_STRING, 1000, true);
$this->fail('Failed to throw exception');
} catch (Throwable $e) {
$this->assertEquals('Index length is longer than the maximum: '.$database->getAdapter()->getMaxIndexLength(), $e->getMessage());
}
}

public function testRenameIndex(): void
{
$database = static::getDatabase();
Expand Down