1
0
Fork 0
mirror of synced 2024-07-01 12:40:34 +12:00

Merge pull request #3383 from appwrite/feat-internal-ids-collections

Feat internal ids Database Api
This commit is contained in:
Torsten Dittmann 2022-06-19 11:30:42 +02:00 committed by GitHub
commit cf3de6d7ef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 4 deletions

View file

@ -119,6 +119,17 @@ $collections = [
'$id' => 'attributes',
'name' => 'Attributes',
'attributes' => [
[
'$id' => 'collectionInternalId',
'type' => Database::VAR_STRING,
'format' => '',
'size' => Database::LENGTH_KEY,
'signed' => true,
'required' => false,
'default' => null,
'array' => false,
'filters' => [],
],
[
'$id' => 'collectionId',
'type' => Database::VAR_STRING,
@ -248,6 +259,13 @@ $collections = [
],
],
'indexes' => [
[
'$id' => '_key_collection_internal_id',
'type' => Database::INDEX_KEY,
'attributes' => ['collectionInternalId'],
'lengths' => [Database::LENGTH_KEY],
'orders' => [Database::ORDER_ASC],
],
[
'$id' => '_key_collection',
'type' => Database::INDEX_KEY,
@ -263,6 +281,17 @@ $collections = [
'$id' => 'indexes',
'name' => 'Indexes',
'attributes' => [
[
'$id' => 'collectionInternalId',
'type' => Database::VAR_STRING,
'format' => '',
'size' => Database::LENGTH_KEY,
'signed' => true,
'required' => false,
'default' => null,
'array' => false,
'filters' => [],
],
[
'$id' => 'collectionId',
'type' => Database::VAR_STRING,
@ -349,6 +378,13 @@ $collections = [
'lengths' => [Database::LENGTH_KEY],
'orders' => [Database::ORDER_ASC],
],
[
'$id' => '_key_collection_internal_id',
'type' => Database::INDEX_KEY,
'attributes' => ['collectionInternalId'],
'lengths' => [Database::LENGTH_KEY],
'orders' => [Database::ORDER_ASC],
],
],
],

View file

@ -47,6 +47,7 @@ use MaxMind\Db\Reader;
*
*
* @return Document Newly created attribute document
* @throws Exception
*/
function createAttribute(string $collectionId, Document $attribute, Response $response, Database $dbForProject, EventDatabase $database, EventAudit $audits, Event $events, Stats $usage): Document
{
@ -86,6 +87,7 @@ function createAttribute(string $collectionId, Document $attribute, Response $re
$attribute = new Document([
'$id' => $collectionId . '_' . $key,
'key' => $key,
'collectionInternalId' => $collection->getInternalId(),
'collectionId' => $collectionId,
'type' => $type,
'status' => 'processing', // processing, available, failed, deleting, stuck
@ -1263,8 +1265,8 @@ App::post('/v1/database/collections/:collectionId/indexes')
}
$count = $dbForProject->count('indexes', [
new Query('collectionId', Query::TYPE_EQUAL, [$collectionId])
], 61);
new Query('collectionInternalId', Query::TYPE_EQUAL, [$collection->getInternalId()])
]);
$limit = 64 - MariaDB::getNumberOfDefaultIndexes();
@ -1304,6 +1306,7 @@ App::post('/v1/database/collections/:collectionId/indexes')
'$id' => $collectionId . '_' . $key,
'key' => $key,
'status' => 'processing', // processing, available, failed, deleting, stuck
'collectionInternalId' => $collection->getInternalId(),
'collectionId' => $collectionId,
'type' => $type,
'attributes' => $attributes,

View file

@ -256,7 +256,7 @@ Database::addFilter(
function (mixed $value, Document $document, Database $database) {
return $database
->find('attributes', [
new Query('collectionId', Query::TYPE_EQUAL, [$document->getId()])
new Query('collectionInternalId', Query::TYPE_EQUAL, [$document->getInternalId()])
], $database->getAttributeLimit());
}
);
@ -269,7 +269,7 @@ Database::addFilter(
function (mixed $value, Document $document, Database $database) {
return $database
->find('indexes', [
new Query('collectionId', Query::TYPE_EQUAL, [$document->getId()])
new Query('collectionInternalId', Query::TYPE_EQUAL, [$document->getInternalId()])
], 64);
}
);