@@ -1970,32 +1970,26 @@ private function normalizeCollectionAttributeSizes(Document $collection): Docume
19701970 }
19711971
19721972 $ type = $ attribute ->getAttribute ('type ' );
1973- $ size = $ attribute ->getAttribute ('size ' , 0 );
19741973
19751974 if ($ type === self ::VAR_BIGINT ) {
1976- // Keep bigint size as string to avoid precision loss.
1977- $ attribute ->setAttribute ('size ' , (string )$ size );
1978- continue ;
1975+ $ formatOptions = $ attribute ->getAttribute ('formatOptions ' , []);
1976+ if (\is_array ($ formatOptions )) {
1977+ if (\array_key_exists ('min ' , $ formatOptions ) && $ formatOptions ['min ' ] !== null ) {
1978+ $ formatOptions ['min ' ] = (string )$ formatOptions ['min ' ];
1979+ }
1980+ if (\array_key_exists ('max ' , $ formatOptions ) && $ formatOptions ['max ' ] !== null ) {
1981+ $ formatOptions ['max ' ] = (string )$ formatOptions ['max ' ];
1982+ }
1983+ $ attribute ->setAttribute ('formatOptions ' , $ formatOptions );
1984+ }
19791985 }
1980-
1981- // Keep legacy behavior for non-bigint metadata.
1982- $ attribute ->setAttribute ('size ' , (int )$ size );
19831986 }
19841987
19851988 $ collection ->setAttribute ('attributes ' , $ attributes );
19861989
19871990 return $ collection ;
19881991 }
19891992
1990- private function getSize (string $ type , int |string |null $ size ): int |string
1991- {
1992- if ($ type === self ::VAR_BIGINT ) {
1993- return (string )($ size ?? 0 );
1994- }
1995-
1996- return (int )($ size ?? 0 );
1997- }
1998-
19991993 /**
20001994 * Get Collection Size
20011995 *
@@ -2155,9 +2149,8 @@ public function deleteCollection(string $id): bool
21552149 * @throws StructureException
21562150 * @throws Exception
21572151 */
2158- public function createAttribute (string $ collection , string $ id , string $ type , int | string $ size , bool $ required , mixed $ default = null , bool $ signed = true , bool $ array = false , ?string $ format = null , array $ formatOptions = [], array $ filters = []): bool
2152+ public function createAttribute (string $ collection , string $ id , string $ type , int $ size , bool $ required , mixed $ default = null , bool $ signed = true , bool $ array = false , ?string $ format = null , array $ formatOptions = [], array $ filters = []): bool
21592153 {
2160- $ size = $ this ->getSize ($ type , $ size );
21612154 $ collection = $ this ->silent (fn () => $ this ->getCollection ($ collection ));
21622155
21632156 if ($ collection ->isEmpty ()) {
@@ -2241,7 +2234,7 @@ public function createAttribute(string $collection, string $id, string $type, in
22412234 '$id ' => ID ::custom ($ id ),
22422235 'key ' => $ id ,
22432236 'type ' => $ type ,
2244- 'size ' => $ this -> getSize ( $ type , $ size) ,
2237+ 'size ' => $ size ,
22452238 'required ' => $ required ,
22462239 'default ' => $ default ,
22472240 'signed ' => $ signed ,
@@ -2365,7 +2358,6 @@ public function createAttributes(string $collection, array $attributes): bool
23652358 $ existsInSchema = false ;
23662359
23672360 try {
2368- $ attribute ['size ' ] = $ this ->getSize ($ attribute ['type ' ], $ attribute ['size ' ]);
23692361 $ attributeDocument = $ this ->validateAttribute (
23702362 $ collection ,
23712363 $ attribute ['$id ' ],
@@ -2422,7 +2414,7 @@ public function createAttributes(string $collection, array $attributes): bool
24222414 '$id ' => ID ::custom ($ attribute ['$id ' ]),
24232415 'key ' => $ attribute ['$id ' ],
24242416 'type ' => $ attribute ['type ' ],
2425- 'size ' => $ this -> getSize ( $ attribute ['type ' ], $ attribute [ ' size ' ]) ,
2417+ 'size ' => $ attribute ['size ' ],
24262418 'required ' => $ attribute ['required ' ],
24272419 'default ' => $ attribute ['default ' ],
24282420 'signed ' => $ attribute ['signed ' ],
@@ -2525,7 +2517,7 @@ private function validateAttribute(
25252517 Document $ collection ,
25262518 string $ id ,
25272519 string $ type ,
2528- int | string $ size ,
2520+ int $ size ,
25292521 bool $ required ,
25302522 mixed $ default ,
25312523 bool $ signed ,
@@ -2539,7 +2531,7 @@ private function validateAttribute(
25392531 '$id ' => ID ::custom ($ id ),
25402532 'key ' => $ id ,
25412533 'type ' => $ type ,
2542- 'size ' => $ this -> getSize ( $ type , $ size) ,
2534+ 'size ' => $ size ,
25432535 'required ' => $ required ,
25442536 'default ' => $ default ,
25452537 'signed ' => $ signed ,
@@ -2881,7 +2873,7 @@ public function updateAttributeDefault(string $collection, string $id, mixed $de
28812873 * @return Document
28822874 * @throws Exception
28832875 */
2884- public function updateAttribute (string $ collection , string $ id , ?string $ type = null , int | string | null $ size = null , ?bool $ required = null , mixed $ default = null , ?bool $ signed = null , ?bool $ array = null , ?string $ format = null , ?array $ formatOptions = null , ?array $ filters = null , ?string $ newKey = null ): Document
2876+ public function updateAttribute (string $ collection , string $ id , ?string $ type = null , ? int $ size = null , ?bool $ required = null , mixed $ default = null , ?bool $ signed = null , ?bool $ array = null , ?string $ format = null , ?array $ formatOptions = null , ?array $ filters = null , ?string $ newKey = null ): Document
28852877 {
28862878 $ collectionDoc = $ this ->silent (fn () => $ this ->getCollection ($ collection ));
28872879
@@ -2917,7 +2909,6 @@ public function updateAttribute(string $collection, string $id, ?string $type =
29172909 || !\is_null ($ newKey );
29182910 $ type ??= $ attribute ->getAttribute ('type ' );
29192911 $ size ??= $ attribute ->getAttribute ('size ' );
2920- $ size = $ this ->getSize ($ type , $ size );
29212912 $ signed ??= $ attribute ->getAttribute ('signed ' );
29222913 $ required ??= $ attribute ->getAttribute ('required ' );
29232914 $ default ??= $ attribute ->getAttribute ('default ' );
@@ -2969,11 +2960,12 @@ public function updateAttribute(string $collection, string $id, ?string $type =
29692960 }
29702961 break ;
29712962 case self ::VAR_BIGINT :
2972- $ sizeString = ( string )$ size ;
2973- $ limit = ($ this ->adapter ->getSupportForUnsignedBigInt () && ! $ signed )
2963+ $ sizeString = BigIntHelper:: normalizeUnsignedString (( string )$ size) ;
2964+ $ limit = (! $ signed && $ this ->adapter ->getSupportForUnsignedBigInt ())
29742965 ? BigIntHelper::UNSIGNED_MAX
2975- : (string )$ this ->adapter ->getLimitForBigInt ();
2976- if (!BigIntHelper::fitsBigIntRange ($ sizeString , false , $ this ->adapter ->getSupportForUnsignedBigInt () && !$ signed )) {
2966+ : BigIntHelper::SIGNED_MAX ;
2967+
2968+ if (BigIntHelper::compareUnsignedStrings ($ sizeString , $ limit ) > 0 ) {
29772969 throw new DatabaseException ('Max size allowed for bigint is: ' . BigIntHelper::formatIntegerString ($ limit ));
29782970 }
29792971 break ;
@@ -3082,7 +3074,7 @@ public function updateAttribute(string $collection, string $id, ?string $type =
30823074 ->setAttribute ('$id ' , $ newKey ?? $ id )
30833075 ->setattribute ('key ' , $ newKey ?? $ id )
30843076 ->setAttribute ('type ' , $ type )
3085- ->setAttribute ('size ' , $ this -> getSize ( $ type , $ size) )
3077+ ->setAttribute ('size ' , $ size )
30863078 ->setAttribute ('signed ' , $ signed )
30873079 ->setAttribute ('array ' , $ array )
30883080 ->setAttribute ('format ' , $ format )
0 commit comments