Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
7 changes: 7 additions & 0 deletions src/Database/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,13 @@ abstract public function getLimitForString(): int;
*/
abstract public function getLimitForInt(): int;

/**
* Get max BIGINT limit
*
* @return int
*/
abstract public function getLimitForBigInt(): int;

/**
* Get maximum attributes limit.
*
Expand Down
6 changes: 5 additions & 1 deletion src/Database/Adapter/MariaDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -1734,6 +1734,10 @@ protected function getSQLType(string $type, int $size, bool $signed = true, bool

return 'INT' . $signed;

case Database::VAR_BIGINT:
$signed = ($signed) ? '' : ' UNSIGNED';
return 'BIGINT' . $signed;

case Database::VAR_FLOAT:
$signed = ($signed) ? '' : ' UNSIGNED';
return 'DOUBLE' . $signed;
Expand All @@ -1748,7 +1752,7 @@ protected function getSQLType(string $type, int $size, bool $signed = true, bool
return 'DATETIME(3)';

default:
throw new DatabaseException('Unknown type: ' . $type . '. Must be one of ' . Database::VAR_STRING . ', ' . Database::VAR_VARCHAR . ', ' . Database::VAR_TEXT . ', ' . Database::VAR_MEDIUMTEXT . ', ' . Database::VAR_LONGTEXT . ', ' . Database::VAR_INTEGER . ', ' . Database::VAR_FLOAT . ', ' . Database::VAR_BOOLEAN . ', ' . Database::VAR_DATETIME . ', ' . Database::VAR_RELATIONSHIP . ', ' . Database::VAR_POINT . ', ' . Database::VAR_LINESTRING . ', ' . Database::VAR_POLYGON);
throw new DatabaseException('Unknown type: ' . $type . '. Must be one of ' . Database::VAR_STRING . ', ' . Database::VAR_VARCHAR . ', ' . Database::VAR_TEXT . ', ' . Database::VAR_MEDIUMTEXT . ', ' . Database::VAR_LONGTEXT . ', ' . Database::VAR_INTEGER . ', ' . Database::VAR_BIGINT . ', ' . Database::VAR_FLOAT . ', ' . Database::VAR_BOOLEAN . ', ' . Database::VAR_DATETIME . ', ' . Database::VAR_RELATIONSHIP . ', ' . Database::VAR_POINT . ', ' . Database::VAR_LINESTRING . ', ' . Database::VAR_POLYGON);
}
}

Expand Down
12 changes: 12 additions & 0 deletions src/Database/Adapter/Mongo.php
Original file line number Diff line number Diff line change
Expand Up @@ -1310,6 +1310,7 @@ public function castingAfter(Document $collection, Document $document): Document
foreach ($value as &$node) {
switch ($type) {
case Database::VAR_INTEGER:
case Database::VAR_BIGINT:
$node = (int)$node;
break;
case Database::VAR_DATETIME:
Expand Down Expand Up @@ -2211,6 +2212,7 @@ private function getMongoTypeCode(string $appwriteType): string
Database::VAR_MEDIUMTEXT => 'string',
Database::VAR_LONGTEXT => 'string',
Database::VAR_INTEGER => 'int',
Database::VAR_BIGINT => 'long',
Database::VAR_FLOAT => 'double',
Database::VAR_BOOLEAN => 'bool',
Database::VAR_DATETIME => 'date',
Expand Down Expand Up @@ -3004,6 +3006,16 @@ public function getLimitForInt(): int
return 4294967295;
}

/**
* Get max BIGINT limit
*
* @return int
*/
public function getLimitForBigInt(): int
{
return Database::MAX_BIG_INT;
}

/**
* Get maximum column limit.
* Returns 0 to indicate no limit
Expand Down
5 changes: 5 additions & 0 deletions src/Database/Adapter/Pool.php
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,11 @@ public function getLimitForInt(): int
return $this->delegate(__FUNCTION__, \func_get_args());
}

public function getLimitForBigInt(): int
{
return $this->delegate(__FUNCTION__, \func_get_args());
}

public function getLimitForAttributes(): int
{
return $this->delegate(__FUNCTION__, \func_get_args());
Expand Down
5 changes: 4 additions & 1 deletion src/Database/Adapter/Postgres.php
Original file line number Diff line number Diff line change
Expand Up @@ -1972,6 +1972,9 @@ protected function getSQLType(string $type, int $size, bool $signed = true, bool

return 'INTEGER';

case Database::VAR_BIGINT:
return 'BIGINT';

case Database::VAR_FLOAT:
return 'DOUBLE PRECISION';

Expand Down Expand Up @@ -2000,7 +2003,7 @@ protected function getSQLType(string $type, int $size, bool $signed = true, bool
return "VECTOR({$size})";

default:
throw new DatabaseException('Unknown Type: ' . $type . '. Must be one of ' . Database::VAR_STRING . ', ' . Database::VAR_VARCHAR . ', ' . Database::VAR_TEXT . ', ' . Database::VAR_MEDIUMTEXT . ', ' . Database::VAR_LONGTEXT . ', ' . Database::VAR_INTEGER . ', ' . Database::VAR_FLOAT . ', ' . Database::VAR_BOOLEAN . ', ' . Database::VAR_DATETIME . ', ' . Database::VAR_RELATIONSHIP . ', ' . Database::VAR_OBJECT . ', ' . Database::VAR_POINT . ', ' . Database::VAR_LINESTRING . ', ' . Database::VAR_POLYGON);
throw new DatabaseException('Unknown Type: ' . $type . '. Must be one of ' . Database::VAR_STRING . ', ' . Database::VAR_VARCHAR . ', ' . Database::VAR_TEXT . ', ' . Database::VAR_MEDIUMTEXT . ', ' . Database::VAR_LONGTEXT . ', ' . Database::VAR_INTEGER . ', ' . Database::VAR_BIGINT . ', ' . Database::VAR_FLOAT . ', ' . Database::VAR_BOOLEAN . ', ' . Database::VAR_DATETIME . ', ' . Database::VAR_RELATIONSHIP . ', ' . Database::VAR_OBJECT . ', ' . Database::VAR_POINT . ', ' . Database::VAR_LINESTRING . ', ' . Database::VAR_POLYGON);
}
}

Expand Down
14 changes: 14 additions & 0 deletions src/Database/Adapter/SQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,16 @@ public function getLimitForInt(): int
return 4294967295;
}

/**
* Get max BIGINT limit
*
* @return int
*/
public function getLimitForBigInt(): int
{
return Database::MAX_BIG_INT;
}

/**
* Get maximum column limit.
* https://mariadb.com/kb/en/innodb-limitations/#limitations-on-schema
Expand Down Expand Up @@ -1164,6 +1174,10 @@ public function getAttributeWidth(Document $collection): int
}
break;

case Database::VAR_BIGINT:
$total += 8; // BIGINT 8 bytes
break;

case Database::VAR_FLOAT:
$total += 8; // DOUBLE 8 bytes
break;
Expand Down
16 changes: 16 additions & 0 deletions src/Database/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class Database
// Simple Types
public const VAR_STRING = 'string';
public const VAR_INTEGER = 'integer';
public const VAR_BIGINT = 'bigint';
public const VAR_FLOAT = 'double';
public const VAR_BOOLEAN = 'boolean';
public const VAR_DATETIME = 'datetime';
Expand Down Expand Up @@ -2512,6 +2513,7 @@ private function validateAttribute(
maxStringLength: $this->adapter->getLimitForString(),
maxVarcharLength: $this->adapter->getMaxVarcharLength(),
maxIntLength: $this->adapter->getLimitForInt(),
maxBigIntLength: $this->adapter->getLimitForBigInt(),
supportForSchemaAttributes: $this->adapter->getSupportForSchemaAttributes(),
supportForVectors: $this->adapter->getSupportForVectors(),
supportForSpatialAttributes: $this->adapter->getSupportForSpatialAttributes(),
Expand Down Expand Up @@ -2588,6 +2590,11 @@ protected function validateDefaultTypes(string $type, mixed $default): void
throw new DatabaseException('Default value ' . $default . ' does not match given type ' . $type);
}
break;
case Database::VAR_BIGINT:
if ($defaultType !== 'integer') {
throw new DatabaseException('Default value ' . $default . ' does not match given type ' . $type);
}
break;
case self::VAR_DATETIME:
if ($defaultType !== self::VAR_STRING) {
throw new DatabaseException('Default value ' . $default . ' does not match given type ' . $type);
Expand All @@ -2607,6 +2614,7 @@ protected function validateDefaultTypes(string $type, mixed $default): void
self::VAR_MEDIUMTEXT,
self::VAR_LONGTEXT,
self::VAR_INTEGER,
self::VAR_BIGINT,
self::VAR_FLOAT,
self::VAR_BOOLEAN,
self::VAR_DATETIME,
Expand Down Expand Up @@ -2909,6 +2917,8 @@ public function updateAttribute(string $collection, string $id, ?string $type =
throw new DatabaseException('Max size allowed for int is: ' . number_format($limit));
}
break;
case self::VAR_BIGINT:
break;
case self::VAR_FLOAT:
case self::VAR_BOOLEAN:
case self::VAR_DATETIME:
Expand Down Expand Up @@ -2975,6 +2985,7 @@ public function updateAttribute(string $collection, string $id, ?string $type =
self::VAR_MEDIUMTEXT,
self::VAR_LONGTEXT,
self::VAR_INTEGER,
self::VAR_BIGINT,
self::VAR_FLOAT,
self::VAR_BOOLEAN,
self::VAR_DATETIME,
Expand Down Expand Up @@ -7423,6 +7434,7 @@ public function increaseDocumentAttribute(

$whiteList = [
self::VAR_INTEGER,
self::VAR_BIGINT,
self::VAR_FLOAT
];

Expand Down Expand Up @@ -7521,6 +7533,7 @@ public function decreaseDocumentAttribute(

$whiteList = [
self::VAR_INTEGER,
self::VAR_BIGINT,
self::VAR_FLOAT
];

Expand Down Expand Up @@ -8932,6 +8945,9 @@ public function casting(Document $collection, Document $document): Document
case self::VAR_INTEGER:
$node = (int)$node;
break;
case self::VAR_BIGINT:
$node = (int)$node;
break;
case self::VAR_FLOAT:
$node = (float)$node;
break;
Expand Down
19 changes: 19 additions & 0 deletions src/Database/Validator/Attribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Attribute extends Validator
* @param int $maxStringLength
* @param int $maxVarcharLength
* @param int $maxIntLength
* @param int $maxBigIntLength
* @param bool $supportForSchemaAttributes
* @param bool $supportForVectors
* @param bool $supportForSpatialAttributes
Expand All @@ -49,6 +50,7 @@ public function __construct(
protected int $maxStringLength = 0,
protected int $maxVarcharLength = 0,
protected int $maxIntLength = 0,
protected int $maxBigIntLength = 0,
protected bool $supportForSchemaAttributes = false,
protected bool $supportForVectors = false,
protected bool $supportForSpatialAttributes = false,
Expand All @@ -59,6 +61,11 @@ public function __construct(
protected bool $isMigrating = false,
protected bool $sharedTables = false,
) {
// Keep backwards compatibility for existing validator construction sites.
if ($this->maxBigIntLength === 0) {
$this->maxBigIntLength = $this->maxIntLength;
}

foreach ($attributes as $attribute) {
$key = \strtolower($attribute->getAttribute('key', $attribute->getAttribute('$id')));
$this->attributes[$key] = $attribute;
Expand Down Expand Up @@ -337,6 +344,9 @@ public function checkType(Document $attribute): bool
}
break;

case Database::VAR_BIGINT:
break;

case Database::VAR_FLOAT:
case Database::VAR_BOOLEAN:
case Database::VAR_DATETIME:
Expand Down Expand Up @@ -420,6 +430,8 @@ public function checkType(Document $attribute): bool
Database::VAR_MEDIUMTEXT,
Database::VAR_LONGTEXT,
Database::VAR_INTEGER,
Database::VAR_BIGINT,
Database::VAR_BIGINT,
Database::VAR_FLOAT,
Database::VAR_BOOLEAN,
Database::VAR_DATETIME,
Expand Down Expand Up @@ -522,6 +534,12 @@ protected function validateDefaultTypes(string $type, mixed $default): void
throw new DatabaseException($this->message);
}
break;
case Database::VAR_BIGINT:
if ($defaultType !== 'integer') {
$this->message = 'Default value ' . $default . ' does not match given type ' . $type;
throw new DatabaseException($this->message);
}
break;
case Database::VAR_DATETIME:
if ($defaultType !== Database::VAR_STRING) {
$this->message = 'Default value ' . $default . ' does not match given type ' . $type;
Expand All @@ -543,6 +561,7 @@ protected function validateDefaultTypes(string $type, mixed $default): void
Database::VAR_MEDIUMTEXT,
Database::VAR_LONGTEXT,
Database::VAR_INTEGER,
Database::VAR_BIGINT,
Database::VAR_FLOAT,
Database::VAR_BOOLEAN,
Database::VAR_DATETIME,
Expand Down
3 changes: 2 additions & 1 deletion src/Database/Validator/Query/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,10 @@ protected function isValidAttributeAndValues(string $attribute, array $values, s
break;

case Database::VAR_INTEGER:
case Database::VAR_BIGINT:
$size = $attributeSchema['size'] ?? 4;
$signed = $attributeSchema['signed'] ?? true;
$bits = $size >= 8 ? 64 : 32;
$bits = ($attributeType === Database::VAR_BIGINT || $size >= 8) ? 64 : 32;
// For 64-bit unsigned, use signed since PHP doesn't support true 64-bit unsigned
$unsigned = !$signed && $bits < 64;
$validator = new Integer(false, $bits, $unsigned);
Expand Down
6 changes: 4 additions & 2 deletions src/Database/Validator/Structure.php
Original file line number Diff line number Diff line change
Expand Up @@ -352,13 +352,15 @@ protected function checkForInvalidAttributeValues(array $structure, array $keys)
break;

case Database::VAR_INTEGER:
case Database::VAR_BIGINT:
// Determine bit size based on attribute size in bytes
$bits = $size >= 8 ? 64 : 32;
// BIGINT is always 64-bit in SQL adapters; VAR_INTEGER uses size to decide.
$bits = ($type === Database::VAR_BIGINT || $size >= 8) ? 64 : 32;
// For 64-bit unsigned, use signed since PHP doesn't support true 64-bit unsigned
// The Range validator will restrict to positive values only
$unsigned = !$signed && $bits < 64;
$validators[] = new Integer(false, $bits, $unsigned);
$max = $size >= 8 ? Database::MAX_BIG_INT : Database::MAX_INT;
$max = $bits === 64 ? Database::MAX_BIG_INT : Database::MAX_INT;
$min = $signed ? -$max : 0;
$validators[] = new Range($min, $max, Database::VAR_INTEGER);
break;
Expand Down
33 changes: 33 additions & 0 deletions tests/e2e/Adapter/Scopes/AttributeTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -2221,6 +2221,39 @@ public function testCreateAttributesIntegerSizeLimit(): void
}
}


public function testCreateAttributesBigInt(): void
{
/** @var Database $database */
$database = $this->getDatabase();

if (!$database->getAdapter()->getSupportForBatchCreateAttributes()) {
$this->expectNotToPerformAssertions();
return;
}

$database->createCollection(__FUNCTION__);

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

$attributes = [[
'$id' => 'foo',
'type' => Database::VAR_BIGINT,
'size' => $size,
'required' => false
]];

$result = $database->createAttributes(__FUNCTION__, $attributes);
$this->assertTrue($result);

$collection = $database->getCollection(__FUNCTION__);
$attrs = $collection->getAttribute('attributes');
$this->assertCount(1, $attrs);
$this->assertEquals('foo', $attrs[0]['$id']);
$this->assertEquals($size, $attrs[0]['size']);
}

public function testCreateAttributesSuccessMultiple(): void
{
/** @var Database $database */
Expand Down
Loading
Loading