@@ -41,6 +41,8 @@ class Database
4141 public const VAR_FLOAT = 'double ' ;
4242 public const VAR_BOOLEAN = 'boolean ' ;
4343 public const VAR_DATETIME = 'datetime ' ;
44+ public const VAR_ID = 'id ' ;
45+ public const VAR_OBJECT_ID = 'objectId ' ;
4446
4547 public const INT_MAX = 2147483647 ;
4648 public const BIG_INT_MAX = PHP_INT_MAX ;
@@ -167,8 +169,8 @@ class Database
167169 ],
168170 [
169171 '$id ' => '$sequence ' ,
170- 'type ' => self ::VAR_STRING ,
171- 'size ' => Database:: LENGTH_KEY ,
172+ 'type ' => self ::VAR_ID ,
173+ 'size ' => 0 ,
172174 'required ' => true ,
173175 'signed ' => true ,
174176 'array ' => false ,
@@ -186,6 +188,7 @@ class Database
186188 [
187189 '$id ' => '$tenant ' ,
188190 'type ' => self ::VAR_INTEGER ,
191+ //'type' => self::VAR_ID, // Inconsistency with other VAR_ID since this is an INT
189192 'size ' => 0 ,
190193 'required ' => false ,
191194 'default ' => null ,
@@ -1789,6 +1792,9 @@ private function validateAttribute(
17891792 $ this ->checkAttribute ($ collection , $ attribute );
17901793
17911794 switch ($ type ) {
1795+ case self ::VAR_ID :
1796+
1797+ break ;
17921798 case self ::VAR_STRING :
17931799 if ($ size > $ this ->adapter ->getLimitForString ()) {
17941800 throw new DatabaseException ('Max size allowed for string is: ' . number_format ($ this ->adapter ->getLimitForString ()));
@@ -3637,6 +3643,7 @@ public function createDocument(string $collection, Document $document): Document
36373643
36383644 $ structure = new Structure (
36393645 $ collection ,
3646+ $ this ->adapter ->getIdAttributeType (),
36403647 $ this ->adapter ->getMinDateTime (),
36413648 $ this ->adapter ->getMaxDateTime (),
36423649 );
@@ -3730,6 +3737,7 @@ public function createDocuments(
37303737
37313738 $ validator = new Structure (
37323739 $ collection ,
3740+ $ this ->adapter ->getIdAttributeType (),
37333741 $ this ->adapter ->getMinDateTime (),
37343742 $ this ->adapter ->getMaxDateTime (),
37353743 );
@@ -4274,6 +4282,7 @@ public function updateDocument(string $collection, string $id, Document $documen
42744282
42754283 $ structureValidator = new Structure (
42764284 $ collection ,
4285+ $ this ->adapter ->getIdAttributeType (),
42774286 $ this ->adapter ->getMinDateTime (),
42784287 $ this ->adapter ->getMaxDateTime (),
42794288 );
@@ -4358,6 +4367,7 @@ public function updateDocuments(
43584367 $ validator = new DocumentsValidator (
43594368 $ attributes ,
43604369 $ indexes ,
4370+ $ this ->adapter ->getIdAttributeType (),
43614371 $ this ->maxQueryValues ,
43624372 $ this ->adapter ->getMinDateTime (),
43634373 $ this ->adapter ->getMaxDateTime (),
@@ -4393,6 +4403,7 @@ public function updateDocuments(
43934403 // Check new document structure
43944404 $ validator = new PartialStructure (
43954405 $ collection ,
4406+ $ this ->adapter ->getIdAttributeType (),
43964407 $ this ->adapter ->getMinDateTime (),
43974408 $ this ->adapter ->getMaxDateTime (),
43984409 );
@@ -5043,6 +5054,7 @@ public function createOrUpdateDocumentsWithIncrease(
50435054
50445055 $ validator = new Structure (
50455056 $ collection ,
5057+ $ this ->adapter ->getIdAttributeType (),
50465058 $ this ->adapter ->getMinDateTime (),
50475059 $ this ->adapter ->getMaxDateTime (),
50485060 );
@@ -5823,6 +5835,7 @@ public function deleteDocuments(
58235835 $ validator = new DocumentsValidator (
58245836 $ attributes ,
58255837 $ indexes ,
5838+ $ this ->adapter ->getIdAttributeType (),
58265839 $ this ->maxQueryValues ,
58275840 $ this ->adapter ->getMinDateTime (),
58285841 $ this ->adapter ->getMaxDateTime ()
@@ -6018,6 +6031,7 @@ public function find(string $collection, array $queries = [], string $forPermiss
60186031 $ validator = new DocumentsValidator (
60196032 $ attributes ,
60206033 $ indexes ,
6034+ $ this ->adapter ->getIdAttributeType (),
60216035 $ this ->maxQueryValues ,
60226036 $ this ->adapter ->getMinDateTime (),
60236037 $ this ->adapter ->getMaxDateTime (),
@@ -6228,6 +6242,7 @@ public function count(string $collection, array $queries = [], ?int $max = null)
62286242 $ validator = new DocumentsValidator (
62296243 $ attributes ,
62306244 $ indexes ,
6245+ $ this ->adapter ->getIdAttributeType (),
62316246 $ this ->maxQueryValues ,
62326247 $ this ->adapter ->getMinDateTime (),
62336248 $ this ->adapter ->getMaxDateTime (),
@@ -6278,6 +6293,7 @@ public function sum(string $collection, string $attribute, array $queries = [],
62786293 $ validator = new DocumentsValidator (
62796294 $ attributes ,
62806295 $ indexes ,
6296+ $ this ->adapter ->getIdAttributeType (),
62816297 $ this ->maxQueryValues ,
62826298 $ this ->adapter ->getMinDateTime (),
62836299 $ this ->adapter ->getMaxDateTime (),
@@ -6500,6 +6516,12 @@ public function casting(Document $collection, Document $document): Document
65006516
65016517 foreach ($ value as $ index => $ node ) {
65026518 switch ($ type ) {
6519+ case self ::VAR_ID :
6520+ // Disabled until Appwrite migrates to use real int ID's for MySQL
6521+ //$type = $this->adapter->getIdAttributeType();
6522+ //\settype($node, $type);
6523+ $ node = (string )$ node ;
6524+ break ;
65036525 case self ::VAR_BOOLEAN :
65046526 $ node = (bool )$ node ;
65056527 break ;
0 commit comments