From 21600001ba5b3486f365a22db2aab3c22d0baf34 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Wed, 14 May 2025 10:26:06 +0530 Subject: [PATCH 1/4] updated string sizing code and test cases --- src/Database/Adapter/MariaDB.php | 11 +---------- tests/e2e/Adapter/Scopes/CollectionTests.php | 6 +++--- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/src/Database/Adapter/MariaDB.php b/src/Database/Adapter/MariaDB.php index e9c639536..18139a4e4 100644 --- a/src/Database/Adapter/MariaDB.php +++ b/src/Database/Adapter/MariaDB.php @@ -2060,18 +2060,9 @@ protected function getSQLType(string $type, int $size, bool $signed = true, bool switch ($type) { case Database::VAR_STRING: // $size = $size * 4; // Convert utf8mb4 size to bytes - if ($size > 16777215) { + if ($size > 767) { return 'LONGTEXT'; } - - if ($size > 65535) { - return 'MEDIUMTEXT'; - } - - if ($size > $this->getMaxVarcharLength()) { - return 'TEXT'; - } - return "VARCHAR({$size})"; case Database::VAR_INTEGER: // We don't support zerofill: https://stackoverflow.com/a/5634147/2299554 diff --git a/tests/e2e/Adapter/Scopes/CollectionTests.php b/tests/e2e/Adapter/Scopes/CollectionTests.php index 3650ab837..a68f14dd7 100644 --- a/tests/e2e/Adapter/Scopes/CollectionTests.php +++ b/tests/e2e/Adapter/Scopes/CollectionTests.php @@ -519,9 +519,9 @@ public function testSchemaAttributes(): void $attribute = $attributes['story']; $this->assertEquals('story', $attribute['$id']); - $this->assertEquals('text', $attribute['dataType']); - $this->assertEquals('text', $attribute['columnType']); - $this->assertEquals('65535', $attribute['characterMaximumLength']); + $this->assertEquals('longtext', $attribute['dataType']); + $this->assertEquals('longtext', $attribute['columnType']); + $this->assertEquals('4294967295', $attribute['characterMaximumLength']); $attribute = $attributes['string_list']; $this->assertEquals('string_list', $attribute['$id']); From 41ad46097ed44e57e8e844ec4e35f0dcdb12128b Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Thu, 26 Jun 2025 19:28:40 +0530 Subject: [PATCH 2/4] updated to new max size for getting max attribute width correctly working to the new size limts --- src/Database/Adapter/SQL.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Database/Adapter/SQL.php b/src/Database/Adapter/SQL.php index f88fec46f..963b3fc0b 100644 --- a/src/Database/Adapter/SQL.php +++ b/src/Database/Adapter/SQL.php @@ -1566,7 +1566,9 @@ public function getHostname(): string */ public function getMaxVarcharLength(): int { - return 16381; // Floor value for Postgres:16383 | MySQL:16381 | MariaDB:16382 + // Floor value for Postgres:16383 | MySQL:16381 | MariaDB:16382 + // new max value is 767 which will be longtext + return 767; } /** From b5c3b35b9a3bd7a6b7c5115450c568ebef1e809a Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Tue, 15 Jul 2025 17:59:03 +0530 Subject: [PATCH 3/4] replaced hard coded char limit for the sql column with the max index length --- src/Database/Adapter/MariaDB.php | 2 +- src/Database/Adapter/SQL.php | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Database/Adapter/MariaDB.php b/src/Database/Adapter/MariaDB.php index 80d9b4281..9d89302be 100644 --- a/src/Database/Adapter/MariaDB.php +++ b/src/Database/Adapter/MariaDB.php @@ -1922,7 +1922,7 @@ protected function getSQLType(string $type, int $size, bool $signed = true, bool switch ($type) { case Database::VAR_STRING: // $size = $size * 4; // Convert utf8mb4 size to bytes - if ($size > 767) { + if ($size > $this->getMaxIndexLength()) { return 'LONGTEXT'; } return "VARCHAR({$size})"; diff --git a/src/Database/Adapter/SQL.php b/src/Database/Adapter/SQL.php index 697c82955..c3ce9b31c 100644 --- a/src/Database/Adapter/SQL.php +++ b/src/Database/Adapter/SQL.php @@ -1575,8 +1575,7 @@ public function getHostname(): string public function getMaxVarcharLength(): int { // Floor value for Postgres:16383 | MySQL:16381 | MariaDB:16382 - // new max value is 767 which will be longtext - return 767; + return $this->getMaxIndexLength(); } /** From 8f19797368516625355e44fe6f1951902bd06d75 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Tue, 15 Jul 2025 21:46:21 +0530 Subject: [PATCH 4/4] updated tests to match the new limit --- tests/e2e/Adapter/Scopes/AttributeTests.php | 35 ++++++++------------ tests/e2e/Adapter/Scopes/CollectionTests.php | 5 ++- 2 files changed, 17 insertions(+), 23 deletions(-) diff --git a/tests/e2e/Adapter/Scopes/AttributeTests.php b/tests/e2e/Adapter/Scopes/AttributeTests.php index fa401db2a..7500d38ff 100644 --- a/tests/e2e/Adapter/Scopes/AttributeTests.php +++ b/tests/e2e/Adapter/Scopes/AttributeTests.php @@ -950,28 +950,19 @@ public function testExceptionWidthLimit(): void } $attributes = []; - - $attributes[] = new Document([ - '$id' => ID::custom('varchar_16000'), - 'type' => Database::VAR_STRING, - 'size' => 16000, - 'required' => true, - 'default' => null, - 'signed' => true, - 'array' => false, - 'filters' => [], - ]); - - $attributes[] = new Document([ - '$id' => ID::custom('varchar_200'), - 'type' => Database::VAR_STRING, - 'size' => 200, - 'required' => true, - 'default' => null, - 'signed' => true, - 'array' => false, - 'filters' => [], - ]); + $limit = (int)($database->getAdapter()->getDocumentSizeLimit() / (200 * 4)); + for ($i = 0; $i < $limit; $i++) { + $attributes[] = new Document([ + '$id' => ID::unique(), + 'type' => Database::VAR_STRING, + 'size' => 200, + 'required' => true, + 'default' => null, + 'signed' => true, + 'array' => false, + 'filters' => [], + ]); + } try { $database->createCollection("attributes_row_size", $attributes); diff --git a/tests/e2e/Adapter/Scopes/CollectionTests.php b/tests/e2e/Adapter/Scopes/CollectionTests.php index e705eae55..119078e9c 100644 --- a/tests/e2e/Adapter/Scopes/CollectionTests.php +++ b/tests/e2e/Adapter/Scopes/CollectionTests.php @@ -586,8 +586,11 @@ public function testRowSizeToLarge(): void $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 = (int)($database->getAdapter()->getDocumentSizeLimit() / (200 * 4)) - 1; + for ($i = 0; $i < $limit; $i++) { + $this->assertEquals(true, $database->createAttribute($collection_1->getId(), 'attr_1_'.$i, Database::VAR_STRING, 200, true)); + } try { $database->createAttribute($collection_1->getId(), 'attr_2', Database::VAR_STRING, Database::LENGTH_KEY, true); $this->fail('Failed to throw exception');