Merge pull request #3383 from appwrite/feat-internal-ids-collections
Feat internal ids Database Api
This commit is contained in:
commit
cf3de6d7ef
3 changed files with 43 additions and 4 deletions
|
@ -119,6 +119,17 @@ $collections = [
|
||||||
'$id' => 'attributes',
|
'$id' => 'attributes',
|
||||||
'name' => 'Attributes',
|
'name' => 'Attributes',
|
||||||
'attributes' => [
|
'attributes' => [
|
||||||
|
[
|
||||||
|
'$id' => 'collectionInternalId',
|
||||||
|
'type' => Database::VAR_STRING,
|
||||||
|
'format' => '',
|
||||||
|
'size' => Database::LENGTH_KEY,
|
||||||
|
'signed' => true,
|
||||||
|
'required' => false,
|
||||||
|
'default' => null,
|
||||||
|
'array' => false,
|
||||||
|
'filters' => [],
|
||||||
|
],
|
||||||
[
|
[
|
||||||
'$id' => 'collectionId',
|
'$id' => 'collectionId',
|
||||||
'type' => Database::VAR_STRING,
|
'type' => Database::VAR_STRING,
|
||||||
|
@ -248,6 +259,13 @@ $collections = [
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'indexes' => [
|
'indexes' => [
|
||||||
|
[
|
||||||
|
'$id' => '_key_collection_internal_id',
|
||||||
|
'type' => Database::INDEX_KEY,
|
||||||
|
'attributes' => ['collectionInternalId'],
|
||||||
|
'lengths' => [Database::LENGTH_KEY],
|
||||||
|
'orders' => [Database::ORDER_ASC],
|
||||||
|
],
|
||||||
[
|
[
|
||||||
'$id' => '_key_collection',
|
'$id' => '_key_collection',
|
||||||
'type' => Database::INDEX_KEY,
|
'type' => Database::INDEX_KEY,
|
||||||
|
@ -263,6 +281,17 @@ $collections = [
|
||||||
'$id' => 'indexes',
|
'$id' => 'indexes',
|
||||||
'name' => 'Indexes',
|
'name' => 'Indexes',
|
||||||
'attributes' => [
|
'attributes' => [
|
||||||
|
[
|
||||||
|
'$id' => 'collectionInternalId',
|
||||||
|
'type' => Database::VAR_STRING,
|
||||||
|
'format' => '',
|
||||||
|
'size' => Database::LENGTH_KEY,
|
||||||
|
'signed' => true,
|
||||||
|
'required' => false,
|
||||||
|
'default' => null,
|
||||||
|
'array' => false,
|
||||||
|
'filters' => [],
|
||||||
|
],
|
||||||
[
|
[
|
||||||
'$id' => 'collectionId',
|
'$id' => 'collectionId',
|
||||||
'type' => Database::VAR_STRING,
|
'type' => Database::VAR_STRING,
|
||||||
|
@ -349,6 +378,13 @@ $collections = [
|
||||||
'lengths' => [Database::LENGTH_KEY],
|
'lengths' => [Database::LENGTH_KEY],
|
||||||
'orders' => [Database::ORDER_ASC],
|
'orders' => [Database::ORDER_ASC],
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'$id' => '_key_collection_internal_id',
|
||||||
|
'type' => Database::INDEX_KEY,
|
||||||
|
'attributes' => ['collectionInternalId'],
|
||||||
|
'lengths' => [Database::LENGTH_KEY],
|
||||||
|
'orders' => [Database::ORDER_ASC],
|
||||||
|
],
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
|
||||||
|
|
|
@ -47,6 +47,7 @@ use MaxMind\Db\Reader;
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @return Document Newly created attribute document
|
* @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
|
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([
|
$attribute = new Document([
|
||||||
'$id' => $collectionId . '_' . $key,
|
'$id' => $collectionId . '_' . $key,
|
||||||
'key' => $key,
|
'key' => $key,
|
||||||
|
'collectionInternalId' => $collection->getInternalId(),
|
||||||
'collectionId' => $collectionId,
|
'collectionId' => $collectionId,
|
||||||
'type' => $type,
|
'type' => $type,
|
||||||
'status' => 'processing', // processing, available, failed, deleting, stuck
|
'status' => 'processing', // processing, available, failed, deleting, stuck
|
||||||
|
@ -1263,8 +1265,8 @@ App::post('/v1/database/collections/:collectionId/indexes')
|
||||||
}
|
}
|
||||||
|
|
||||||
$count = $dbForProject->count('indexes', [
|
$count = $dbForProject->count('indexes', [
|
||||||
new Query('collectionId', Query::TYPE_EQUAL, [$collectionId])
|
new Query('collectionInternalId', Query::TYPE_EQUAL, [$collection->getInternalId()])
|
||||||
], 61);
|
]);
|
||||||
|
|
||||||
$limit = 64 - MariaDB::getNumberOfDefaultIndexes();
|
$limit = 64 - MariaDB::getNumberOfDefaultIndexes();
|
||||||
|
|
||||||
|
@ -1304,6 +1306,7 @@ App::post('/v1/database/collections/:collectionId/indexes')
|
||||||
'$id' => $collectionId . '_' . $key,
|
'$id' => $collectionId . '_' . $key,
|
||||||
'key' => $key,
|
'key' => $key,
|
||||||
'status' => 'processing', // processing, available, failed, deleting, stuck
|
'status' => 'processing', // processing, available, failed, deleting, stuck
|
||||||
|
'collectionInternalId' => $collection->getInternalId(),
|
||||||
'collectionId' => $collectionId,
|
'collectionId' => $collectionId,
|
||||||
'type' => $type,
|
'type' => $type,
|
||||||
'attributes' => $attributes,
|
'attributes' => $attributes,
|
||||||
|
|
|
@ -256,7 +256,7 @@ Database::addFilter(
|
||||||
function (mixed $value, Document $document, Database $database) {
|
function (mixed $value, Document $document, Database $database) {
|
||||||
return $database
|
return $database
|
||||||
->find('attributes', [
|
->find('attributes', [
|
||||||
new Query('collectionId', Query::TYPE_EQUAL, [$document->getId()])
|
new Query('collectionInternalId', Query::TYPE_EQUAL, [$document->getInternalId()])
|
||||||
], $database->getAttributeLimit());
|
], $database->getAttributeLimit());
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -269,7 +269,7 @@ Database::addFilter(
|
||||||
function (mixed $value, Document $document, Database $database) {
|
function (mixed $value, Document $document, Database $database) {
|
||||||
return $database
|
return $database
|
||||||
->find('indexes', [
|
->find('indexes', [
|
||||||
new Query('collectionId', Query::TYPE_EQUAL, [$document->getId()])
|
new Query('collectionInternalId', Query::TYPE_EQUAL, [$document->getInternalId()])
|
||||||
], 64);
|
], 64);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue