Skip to content

Commit 32ef15f

Browse files
authored
Merge pull request #11398 from appwrite/fix-cast
2 parents b4a32c8 + 7dc50b4 commit 32ef15f

9 files changed

Lines changed: 63 additions & 30 deletions

File tree

composer.lock

Lines changed: 21 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Appwrite/Platform/Modules/Console/Http/Variables/Get.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ public function action(Response $response, array $platform, Database $dbForProje
102102
'supportForAttributeResizing' => $adapter->getSupportForAttributeResizing(),
103103
'supportForSchemas' => $adapter->getSupportForSchemas(),
104104
'maxIndexLength' => $adapter->getMaxIndexLength(),
105+
'supportForIntegerIds' => $adapter->getIdAttributeType() === 'integer',
105106
]);
106107

107108
$response->dynamic($variables, Response::MODEL_CONSOLE_VARIABLES);

src/Appwrite/SDK/Specification/Format/OpenAPI3.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -839,10 +839,14 @@ public function parse(): array
839839
case 'string':
840840
case 'datetime':
841841
case 'payload':
842-
case 'id':
843842
$type = 'string';
844843
break;
845844

845+
case 'id':
846+
$type = 'integer';
847+
$format = $rule['format'] ?? 'int32';
848+
break;
849+
846850
case 'enum':
847851
$type = 'string';
848852
break;

src/Appwrite/SDK/Specification/Format/Swagger2.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,10 +819,14 @@ public function parse(): array
819819
switch ($rule['type']) {
820820
case 'string':
821821
case 'datetime':
822-
case 'id':
823822
$type = 'string';
824823
break;
825824

825+
case 'id':
826+
$type = 'integer';
827+
$format = $rule['format'] ?? 'int32';
828+
break;
829+
826830
case 'enum':
827831
$type = 'string';
828832
break;

src/Appwrite/Utopia/Response/Model/ConsoleVariables.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,15 @@ public function __construct()
196196
'example' => 768,
197197
]
198198
)
199+
->addRule(
200+
'supportForIntegerIds',
201+
[
202+
'type' => self::TYPE_BOOLEAN,
203+
'description' => 'Whether the database adapter uses integer sequence IDs.',
204+
'default' => true,
205+
'example' => true,
206+
]
207+
)
199208
;
200209
}
201210

src/Appwrite/Utopia/Response/Model/Document.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,8 @@ public function filter(DatabaseDocument $document): DatabaseDocument
8383
$document->removeAttribute('$collection');
8484
$document->removeAttribute('$tenant');
8585

86-
if (!$document->isEmpty()) {
87-
$sequence = $document->getAttribute('$sequence', '');
88-
$document->setAttribute('$sequence', $sequence);
86+
if (!$document->isEmpty() && \is_numeric($document->getAttribute('$sequence', 0))) {
87+
$document->setAttribute('$sequence', (int)$document->getAttribute('$sequence', 0));
8988
}
9089

9190
foreach ($document->getAttributes() as $attribute) {

src/Appwrite/Utopia/Response/Model/Row.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,10 @@ public function filter(DatabaseDocument $document): DatabaseDocument
8282
{
8383
$document->removeAttribute('$collection');
8484
$document->removeAttribute('$tenant');
85-
$sequence = $document->getAttribute('$sequence', '');
86-
$document->setAttribute('$sequence', $sequence);
85+
86+
if (!$document->isEmpty() && \is_numeric($document->getAttribute('$sequence', 0))) {
87+
$document->setAttribute('$sequence', (int)$document->getAttribute('$sequence', 0));
88+
}
8789

8890
foreach ($document->getAttributes() as $column) {
8991
if (\is_array($column)) {

tests/e2e/Scopes/Scope.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,14 @@ protected function getMaxIndexLength(): int
143143
return $this->getConsoleVariables()['maxIndexLength'] ?? 768;
144144
}
145145

146+
/**
147+
* Check if the database adapter uses integer sequence IDs
148+
*/
149+
protected function getSupportForIntegerIds(): bool
150+
{
151+
return $this->getConsoleVariables()['supportForIntegerIds'] ?? true;
152+
}
153+
146154
protected function getLastEmail(int $limit = 1, ?callable $probe = null): array
147155
{
148156
$result = [];

tests/e2e/Services/Databases/DatabasesBase.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2567,6 +2567,10 @@ public function testCreateDocument(): void
25672567
$this->assertEquals($document1['body']['birthDay'], '1975-06-12T12:12:55.000+00:00');
25682568
$this->assertTrue(array_key_exists('$sequence', $document1['body']));
25692569

2570+
$this->getSupportForIntegerIds()
2571+
? $this->assertIsInt($document1['body']['$sequence'])
2572+
: $this->assertIsString($document1['body']['$sequence']);
2573+
25702574
$this->assertEquals(201, $document2['headers']['status-code']);
25712575
$this->assertEquals($data['moviesId'], $document2['body'][$this->getContainerIdResponseKey()]);
25722576
$this->assertArrayNotHasKey('$collection', $document2['body']);
@@ -2637,7 +2641,10 @@ public function testUpsertDocument(): void
26372641
/**
26382642
* Resubmit same document, nothing to update
26392643
*/
2640-
$this->assertIsString($document['body']['$sequence']);
2644+
$this->getSupportForIntegerIds()
2645+
? $this->assertIsInt($document['body']['$sequence'])
2646+
: $this->assertIsString($document['body']['$sequence']);
2647+
26412648
$upsertData = [
26422649
'title' => 'Thor: Ragnarok',
26432650
'releaseYear' => 2000,

0 commit comments

Comments
 (0)