Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

exposed internal id as a part of auto increment id #9713

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Next Next commit
* exposed internal id as a part of auto increment id
* updated test cases regarding internal id
  • Loading branch information
ArnabChatterjee20k committed May 1, 2025
commit 7750ada4d8c541557d89d1fbf5b6412a222f8124
7 changes: 6 additions & 1 deletion 7 src/Appwrite/Utopia/Response/Model/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ public function __construct()
'default' => '',
'example' => '5e5ea5c16897e',
])
->addRule('$internalId', [
'type' => self::TYPE_INTEGER,
'description' => 'Auto increment integer.',
'default' => '',
'example' => '1',
])
->addRule('$collectionId', [
'type' => self::TYPE_STRING,
'description' => 'Collection ID.',
Expand Down Expand Up @@ -71,7 +77,6 @@ public function __construct()

public function filter(DatabaseDocument $document): DatabaseDocument
{
$document->removeAttribute('$internalId');
$document->removeAttribute('$collection');
$document->removeAttribute('$tenant');

Expand Down
49 changes: 43 additions & 6 deletions 49 tests/e2e/Services/Databases/DatabasesBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -1553,6 +1553,7 @@ public function testCreateDocument(array $data): array
$this->assertEquals($document1['body']['actors'][0], 'Chris Evans');
$this->assertEquals($document1['body']['actors'][1], 'Samuel Jackson');
$this->assertEquals($document1['body']['birthDay'], '1975-06-12T12:12:55.000+00:00');
$this->assertTrue(array_key_exists('$internalId', $document1['body']));

$this->assertEquals(201, $document2['headers']['status-code']);
$this->assertEquals($data['moviesId'], $document2['body']['$collectionId']);
Expand All @@ -1570,6 +1571,7 @@ public function testCreateDocument(array $data): array
$this->assertEquals($document2['body']['birthDay'], null);
$this->assertEquals($document2['body']['integers'][0], 50);
$this->assertEquals($document2['body']['integers'][1], 60);
$this->assertTrue(array_key_exists('$internalId', $document2['body']));

$this->assertEquals(201, $document3['headers']['status-code']);
$this->assertEquals($data['moviesId'], $document3['body']['$collectionId']);
Expand All @@ -1584,6 +1586,7 @@ public function testCreateDocument(array $data): array
$this->assertEquals($document3['body']['actors'][0], 'Tom Holland');
$this->assertEquals($document3['body']['actors'][1], 'Zendaya Maree Stoermer');
$this->assertEquals($document3['body']['birthDay'], '1975-06-12T18:12:55.000+00:00'); // UTC for NY
$this->assertTrue(array_key_exists('$internalId', $document3['body']));

$this->assertEquals(400, $document4['headers']['status-code']);

Expand Down Expand Up @@ -1615,9 +1618,9 @@ public function testListDocuments(array $data): array
$this->assertEquals(1944, $documents['body']['documents'][0]['releaseYear']);
$this->assertEquals(2017, $documents['body']['documents'][1]['releaseYear']);
$this->assertEquals(2019, $documents['body']['documents'][2]['releaseYear']);
$this->assertFalse(array_key_exists('$internalId', $documents['body']['documents'][0]));
$this->assertFalse(array_key_exists('$internalId', $documents['body']['documents'][1]));
$this->assertFalse(array_key_exists('$internalId', $documents['body']['documents'][2]));
$this->assertTrue(array_key_exists('$internalId', $documents['body']['documents'][0]));
$this->assertTrue(array_key_exists('$internalId', $documents['body']['documents'][1]));
$this->assertTrue(array_key_exists('$internalId', $documents['body']['documents'][2]));
$this->assertCount(3, $documents['body']['documents']);

foreach ($documents['body']['documents'] as $document) {
Expand Down Expand Up @@ -1710,7 +1713,7 @@ public function testGetDocument(array $data): void
$this->assertEquals($response['body']['releaseYear'], $document['releaseYear']);
$this->assertEquals($response['body']['$permissions'], $document['$permissions']);
$this->assertEquals($response['body']['birthDay'], $document['birthDay']);
$this->assertFalse(array_key_exists('$internalId', $response['body']));
$this->assertTrue(array_key_exists('$internalId', $response['body']));
$this->assertFalse(array_key_exists('$tenant', $response['body']));
}
}
Expand All @@ -1723,6 +1726,7 @@ public function testGetDocumentWithQueries(array $data): void
$databaseId = $data['databaseId'];
$document = $data['documents'][0];

// not selecting internal id
$response = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $document['$collectionId'] . '/documents/' . $document['$id'], array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
Expand All @@ -1736,6 +1740,39 @@ public function testGetDocumentWithQueries(array $data): void
$this->assertEquals($document['title'], $response['body']['title']);
$this->assertEquals($document['releaseYear'], $response['body']['releaseYear']);
$this->assertArrayNotHasKey('birthDay', $response['body']);
$this->assertFalse(array_key_exists('$internalId', $response['body']));

// selecting internal id as well
$response = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $document['$collectionId'] . '/documents/' . $document['$id'], array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'queries' => [
Query::select(['title', 'releaseYear', '$id','$internalId'])->toString(),
],
]);

$this->assertEquals(200, $response['headers']['status-code']);
$this->assertEquals($document['title'], $response['body']['title']);
$this->assertEquals($document['releaseYear'], $response['body']['releaseYear']);
$this->assertArrayNotHasKey('birthDay', $response['body']);
$this->assertTrue(array_key_exists('$internalId', $response['body']));
$internalId = $response['body']['$internalId'];

// Query by internalId
$response = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $document['$collectionId'] . '/documents/' . $document['$id'], array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'queries' => [
Query::equal('$internalId', [$internalId])
],
]);

$this->assertEquals(200, $response['headers']['status-code']);
$this->assertEquals($document['title'], $response['body']['title']);
$this->assertEquals($document['releaseYear'], $response['body']['releaseYear']);
$this->assertTrue(array_key_exists('$internalId', $response['body']));
}

/**
Expand Down Expand Up @@ -4005,8 +4042,8 @@ public function testOneToOneRelationship(array $data): array

$this->assertArrayNotHasKey('$collection', $person1['body']);
$this->assertArrayNotHasKey('$collection', $person1['body']['library']);
$this->assertArrayNotHasKey('$internalId', $person1['body']);
$this->assertArrayNotHasKey('$internalId', $person1['body']['library']);
$this->assertArrayHasKey('$internalId', $person1['body']);
$this->assertArrayHasKey('$internalId', $person1['body']['library']);

$documents = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $person['body']['$id'] . '/documents', array_merge([
'content-type' => 'application/json',
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.