diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Create.php index 0dbe995457..d77db3da43 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Create.php @@ -234,11 +234,11 @@ class Create extends Action $formatOptions = ['elements' => $attributeDef['elements']]; } - if (isset($attributeDef['min']) && isset($attributeDef['max'])) { + if (isset($attributeDef['min']) || isset($attributeDef['max'])) { $format = $type === Database::VAR_INTEGER ? APP_DATABASE_ATTRIBUTE_INT_RANGE : APP_DATABASE_ATTRIBUTE_FLOAT_RANGE; $formatOptions = [ - 'min' => $attributeDef['min'], - 'max' => $attributeDef['max'], + 'min' => $attributeDef['min'] ?? ($type === Database::VAR_INTEGER ? \PHP_INT_MIN : -\PHP_FLOAT_MAX), + 'max' => $attributeDef['max'] ?? ($type === Database::VAR_INTEGER ? \PHP_INT_MAX : \PHP_FLOAT_MAX), ]; } diff --git a/src/Appwrite/Utopia/Database/Validator/Attributes.php b/src/Appwrite/Utopia/Database/Validator/Attributes.php index fea4086eaf..731e6749c4 100644 --- a/src/Appwrite/Utopia/Database/Validator/Attributes.php +++ b/src/Appwrite/Utopia/Database/Validator/Attributes.php @@ -182,13 +182,14 @@ class Attributes extends Validator } // Validate min/max range for integer/float - if (isset($attribute['min']) && isset($attribute['max'])) { + if (isset($attribute['min']) || isset($attribute['max'])) { if (!in_array($attribute['type'], [Database::VAR_INTEGER, Database::VAR_FLOAT])) { $this->message = "Attribute '" . $attribute['key'] . "': min/max can only be used with integer or float types"; return false; } - if ($attribute['min'] > $attribute['max']) { + // If both are set, validate ordering + if (isset($attribute['min']) && isset($attribute['max']) && $attribute['min'] > $attribute['max']) { $this->message = "Attribute '" . $attribute['key'] . "': minimum value must be less than or equal to maximum value"; return false; }