Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
8 changes: 8 additions & 0 deletions src/Database/Adapter/MariaDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -1934,4 +1934,12 @@ public function getSupportForOptionalSpatialAttributeWithExistingRows(): bool
{
return true;
}

/**
* @return int
*/
public function getMaxVarcharLength(): int
{
return min(16381, $this->getMaxIndexLength());
}
}
8 changes: 8 additions & 0 deletions src/Database/Adapter/Postgres.php
Original file line number Diff line number Diff line change
Expand Up @@ -2321,4 +2321,12 @@ public function decodePolygon(string $wkb): array

return $rings; // array of rings, each ring is array of [x,y]
}

/**
* @return int
*/
public function getMaxVarcharLength(): int
{
return 16383;
}
}
5 changes: 1 addition & 4 deletions src/Database/Adapter/SQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -1852,10 +1852,7 @@ public function getHostname(): string
/**
* @return int
*/
public function getMaxVarcharLength(): int
{
return 16381; // Floor value for Postgres:16383 | MySQL:16381 | MariaDB:16382
}
abstract public function getMaxVarcharLength(): int;

/**
* Size of POINT spatial type
Expand Down
32 changes: 18 additions & 14 deletions tests/e2e/Adapter/Scopes/AttributeTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -979,23 +979,27 @@ public function testExceptionWidthLimit(): void
return;
}

$limit = floor(($database->getAdapter()->getDocumentSizeLimit() / 4) / $database->getAdapter()->getMaxVarcharLength());

$attributes = [];

$attributes[] = new Document([
'$id' => ID::custom('varchar_16000'),
'type' => Database::VAR_STRING,
'size' => 16000,
'required' => true,
'default' => null,
'signed' => true,
'array' => false,
'filters' => [],
]);
for ($i = 1; $i < $limit; $i++) {
$attributes[] = new Document([
'$id' => ID::custom('varchar_'.$i),
'type' => Database::VAR_STRING,
'size' => $database->getAdapter()->getMaxVarcharLength(),
'required' => true,
'default' => null,
'signed' => true,
'array' => false,
'filters' => [],
]);
}

$attributes[] = new Document([
'$id' => ID::custom('varchar_200'),
'$id' => ID::custom('breaking'),
'type' => Database::VAR_STRING,
'size' => 200,
'size' => $database->getAdapter()->getMaxVarcharLength(),
'required' => true,
'default' => null,
'signed' => true,
Expand All @@ -1022,7 +1026,7 @@ public function testExceptionWidthLimit(): void
$attribute = new Document([
'$id' => ID::custom('breaking'),
'type' => Database::VAR_STRING,
'size' => 200,
'size' => $database->getAdapter()->getMaxVarcharLength(),
'required' => true,
'default' => null,
'signed' => true,
Expand All @@ -1039,7 +1043,7 @@ public function testExceptionWidthLimit(): void
}

try {
$database->createAttribute($collection->getId(), 'breaking', Database::VAR_STRING, 200, true);
$database->createAttribute($collection->getId(), 'breaking', Database::VAR_STRING, $database->getAdapter()->getMaxVarcharLength(), true);
$this->fail('Failed to throw exception');
} catch (\Throwable $e) {
$this->assertInstanceOf(LimitException::class, $e);
Expand Down
36 changes: 5 additions & 31 deletions tests/e2e/Adapter/Scopes/CollectionTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -605,45 +605,19 @@ public function testRowSizeToLarge(): void
* 65535 / 4 = 16383 MB4
*/
$collection_1 = $database->createCollection('row_size_1');
$collection_2 = $database->createCollection('row_size_2');

$this->assertEquals(true, $database->createAttribute($collection_1->getId(), 'attr_1', Database::VAR_STRING, 16000, true));
$limit = floor(($database->getAdapter()->getDocumentSizeLimit() / 4) / $database->getAdapter()->getMaxVarcharLength());

try {
$database->createAttribute($collection_1->getId(), 'attr_2', Database::VAR_STRING, Database::LENGTH_KEY, true);
$this->fail('Failed to throw exception');
} catch (Exception $e) {
$this->assertInstanceOf(LimitException::class, $e);
for ($i = 1; $i < $limit; $i++) {
$this->assertEquals(true, $database->createAttribute($collection_1->getId(), 'attr_'.$i, Database::VAR_STRING, $database->getAdapter()->getMaxVarcharLength(), true));
}

/**
* Relation takes length of Database::LENGTH_KEY so exceeding getDocumentSizeLimit
*/

try {
$database->createRelationship(
collection: $collection_2->getId(),
relatedCollection: $collection_1->getId(),
type: Database::RELATION_ONE_TO_ONE,
twoWay: true,
);

$this->fail('Failed to throw exception');
} catch (Exception $e) {
$this->assertInstanceOf(LimitException::class, $e);
}

try {
$database->createRelationship(
collection: $collection_1->getId(),
relatedCollection: $collection_2->getId(),
type: Database::RELATION_ONE_TO_ONE,
twoWay: true,
);

$this->assertEquals(true, $database->createAttribute($collection_1->getId(), 'attr_100', Database::VAR_STRING, $database->getAdapter()->getMaxVarcharLength(), true));
$this->fail('Failed to throw exception');
} catch (Exception $e) {
$this->assertInstanceOf(LimitException::class, $e);
$this->assertEquals('Row width limit reached. Cannot create new attribute.', $e->getMessage());
}
}

Expand Down
Loading