Skip to content

Commit 080de0e

Browse files
Remove BIGINT size limit validation from Database and Validator classes
- Eliminated size limit checks for VAR_BIGINT in the Database and Attribute classes to allow larger values. - Updated Mongo and SQL adapters to return a constant for BIGINT limits, ensuring consistent handling across implementations. - Refactored tests to reflect the removal of size constraints and validate successful attribute creation without exceptions.
1 parent 14828d9 commit 080de0e

6 files changed

Lines changed: 16 additions & 28 deletions

File tree

src/Database/Adapter/Mongo.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3013,8 +3013,7 @@ public function getLimitForInt(): int
30133013
*/
30143014
public function getLimitForBigInt(): int
30153015
{
3016-
// Mongo does not handle integers directly, so using MariaDB limit for now
3017-
return 4294967295;
3016+
return Database::MAX_BIG_INT;
30183017
}
30193018

30203019
/**

src/Database/Adapter/SQL.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -903,11 +903,7 @@ public function getLimitForInt(): int
903903
*/
904904
public function getLimitForBigInt(): int
905905
{
906-
// 2^64 - 1
907-
// 18446744073709551615 is the maximum value for a 64-bit unsigned integer
908-
// 9223372036854775807 is the maximum value for a 64-bit signed integer
909-
// in php we can't represent 64-bit integer, so greater than 4294967295 will be treated as bigint
910-
return 4294967295;
906+
return Database::MAX_BIG_INT;
911907
}
912908

913909
/**

src/Database/Database.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2914,10 +2914,6 @@ public function updateAttribute(string $collection, string $id, ?string $type =
29142914
}
29152915
break;
29162916
case self::VAR_BIGINT:
2917-
$limit = ($signed) ? $this->adapter->getLimitForBigInt() / 2 : $this->adapter->getLimitForBigInt();
2918-
if ($size > $limit) {
2919-
throw new DatabaseException('Max size allowed for bigint is: ' . number_format($limit));
2920-
}
29212917
break;
29222918
case self::VAR_FLOAT:
29232919
case self::VAR_BOOLEAN:

src/Database/Validator/Attribute.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -345,11 +345,6 @@ public function checkType(Document $attribute): bool
345345
break;
346346

347347
case Database::VAR_BIGINT:
348-
$limit = ($signed) ? $this->maxBigIntLength / 2 : $this->maxBigIntLength;
349-
if ($size > $limit) {
350-
$this->message = 'Max size allowed for bigint is: ' . number_format($limit);
351-
throw new DatabaseException($this->message);
352-
}
353348
break;
354349

355350
case Database::VAR_FLOAT:

tests/e2e/Adapter/Scopes/AttributeTests.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2221,7 +2221,8 @@ public function testCreateAttributesIntegerSizeLimit(): void
22212221
}
22222222
}
22232223

2224-
public function testCreateAttributesBigIntSizeLimit(): void
2224+
2225+
public function testCreateAttributesBigIntIgnoresSizeLimit(): void
22252226
{
22262227
/** @var Database $database */
22272228
$database = $this->getDatabase();
@@ -2234,20 +2235,23 @@ public function testCreateAttributesBigIntSizeLimit(): void
22342235
$database->createCollection(__FUNCTION__);
22352236

22362237
$limit = $database->getAdapter()->getLimitForBigInt() / 2;
2238+
$size = (int)$limit + 1;
22372239

22382240
$attributes = [[
22392241
'$id' => 'foo',
22402242
'type' => Database::VAR_BIGINT,
2241-
'size' => (int)$limit + 1,
2243+
'size' => $size,
22422244
'required' => false
22432245
]];
22442246

2245-
try {
2246-
$database->createAttributes(__FUNCTION__, $attributes);
2247-
$this->fail('Expected DatabaseException not thrown');
2248-
} catch (\Throwable $e) {
2249-
$this->assertInstanceOf(DatabaseException::class, $e);
2250-
}
2247+
$result = $database->createAttributes(__FUNCTION__, $attributes);
2248+
$this->assertTrue($result);
2249+
2250+
$collection = $database->getCollection(__FUNCTION__);
2251+
$attrs = $collection->getAttribute('attributes');
2252+
$this->assertCount(1, $attrs);
2253+
$this->assertEquals('foo', $attrs[0]['$id']);
2254+
$this->assertEquals($size, $attrs[0]['size']);
22512255
}
22522256

22532257
public function testCreateAttributesSuccessMultiple(): void

tests/unit/Validator/AttributeTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,7 +1139,7 @@ public function testUnsignedIntegerSizeTooLarge(): void
11391139
$validator->isValid($attribute);
11401140
}
11411141

1142-
public function testBigIntSizeTooLarge(): void
1142+
public function testBigIntSizeNotLimited(): void
11431143
{
11441144
$validator = new Attribute(
11451145
attributes: [],
@@ -1161,9 +1161,7 @@ public function testBigIntSizeTooLarge(): void
11611161
'filters' => [],
11621162
]);
11631163

1164-
$this->expectException(DatabaseException::class);
1165-
$this->expectExceptionMessage('Max size allowed for bigint is: 100');
1166-
$validator->isValid($attribute);
1164+
$this->assertTrue($validator->isValid($attribute));
11671165
}
11681166

11691167
public function testUnsignedBigIntSizeLimit(): void

0 commit comments

Comments
 (0)