1
0
Fork 0
mirror of synced 2024-06-02 19:04:49 +12:00

Use database worker to remove attributes and indexes

This commit is contained in:
kodumbeats 2021-06-18 14:27:14 -04:00
parent 47d74a64be
commit b1a6302311
2 changed files with 58 additions and 21 deletions

View file

@ -250,6 +250,7 @@ App::post('/v1/database/collections/:collectionId/attributes')
->action(function ($collectionId, $id, $type, $size, $required, $signed, $array, $filters, $response, $dbForExternal, $database, $audits) {
/** @var Appwrite\Utopia\Response $response */
/** @var Utopia\Database\Database $dbForExternal*/
/** @var Appwrite\Event\Event $database */
/** @var Appwrite\Event\Event $audits */
$collection = $dbForExternal->getCollection($collectionId);
@ -382,12 +383,13 @@ App::delete('/v1/database/collections/:collectionId/attributes/:attributeId')
->param('attributeId', '', new Text(256), 'Attribute ID.')
->inject('response')
->inject('dbForExternal')
->inject('database')
->inject('events')
->inject('audits')
->inject('deletes')
->action(function ($collectionId, $attributeId, $response, $dbForExternal, $events, $audits, $deletes) {
->action(function ($collectionId, $attributeId, $response, $dbForExternal, $database, $events, $audits) {
/** @var Appwrite\Utopia\Response $response */
/** @var Utopia\Database\Database $dbForExternal */
/** @var Appwrite\Event\Event $database */
/** @var Appwrite\Event\Event $events */
/** @var Appwrite\Event\Event $audits */
@ -410,13 +412,10 @@ App::delete('/v1/database/collections/:collectionId/attributes/:attributeId')
'collectionId' => $collectionId,
])]);
// TODO@kodumbeats use the deletes worker to handle this
$success = $dbForExternal->deleteAttribute($collectionId, $attributeId);
// $deletes
// ->setParam('type', DELETE_TYPE_DOCUMENT)
// ->setParam('document', $attribute)
// ;
$database
->setParam('type', DELETE_TYPE_ATTRIBUTE)
->setParam('document', $attribute)
;
$events
->setParam('payload', $response->output2($attribute, Response::MODEL_ATTRIBUTE))
@ -587,12 +586,13 @@ App::delete('/v1/database/collections/:collectionId/indexes/:indexId')
->param('indexId', '', new UID(), 'Index unique ID.')
->inject('response')
->inject('dbForExternal')
->inject('database')
->inject('events')
->inject('audits')
->inject('deletes')
->action(function ($collectionId, $indexId, $response, $dbForExternal, $events, $audits, $deletes) {
->action(function ($collectionId, $indexId, $response, $dbForExternal, $database, $events, $audits) {
/** @var Appwrite\Utopia\Response $response */
/** @var Utopia\Database\Database $dbForExternal */
/** @var Appwrite\Event\Event $database */
/** @var Appwrite\Event\Event $events */
/** @var Appwrite\Event\Event $audits */
@ -615,13 +615,10 @@ App::delete('/v1/database/collections/:collectionId/indexes/:indexId')
'collectionId' => $collectionId,
])]);
// TODO@kodumbeats use the deletes worker to handle this
$success = $dbForExternal->deleteIndex($collectionId, $indexId);
// $deletes
// ->setParam('type', DELETE_TYPE_DOCUMENT)
// ->setParam('document', $attribute)
// ;
$database
->setParam('type', DELETE_TYPE_INDEX)
->setParam('document', $index)
;
$events
->setParam('payload', $response->output2($index, Response::MODEL_INDEX))

View file

@ -38,11 +38,21 @@ class DatabaseV1 extends Worker
$attribute = new Document($attribute);
$this->createAttribute($attribute, $projectId);
break;
case DELETE_TYPE_ATTRIBUTE:
$attribute = $this->args['document'] ?? '';
$attribute = new Document($attribute);
$this->deleteAttribute($attribute, $projectId);
break;
case CREATE_TYPE_INDEX:
$index = $this->args['document'] ?? '';
$index = new Document($index);
$this->createIndex($index, $projectId);
break;
case DELETE_TYPE_INDEX:
$index = $this->args['document'] ?? '';
$index = new Document($index);
$this->deleteIndex($index, $projectId);
break;
// case DELETE_TYPE_DOCUMENT:
// $document = $this->args['document'] ?? '';
@ -97,8 +107,9 @@ class DatabaseV1 extends Worker
/**
* @param Document $attribute
* @param string $projectId
*/
protected function createAttribute($attribute, $projectId)
protected function createAttribute($attribute, $projectId): void
{
$dbForExternal = $this->getExternalDB($projectId);
@ -118,9 +129,24 @@ class DatabaseV1 extends Worker
}
/**
* @param Document $index
* @param Document $attribute
* @param string $projectId
*/
protected function createIndex($index, $projectId)
protected function deleteAttribute($attribute, $projectId): void
{
$dbForExternal = $this->getExternalDB($projectId);
$collectionId = $attribute->getCollection();
$id = $attribute->getAttribute('$id');
$success = $dbForExternal->deleteAttribute($collectionId, $id);
}
/**
* @param Document $index
* @param string $projectId
*/
protected function createIndex($index, $projectId): void
{
$dbForExternal = $this->getExternalDB($projectId);
@ -137,6 +163,20 @@ class DatabaseV1 extends Worker
}
}
/**
* @param Document $index
* @param string $projectId
*/
protected function deleteIndex($index, $projectId): void
{
$dbForExternal = $this->getExternalDB($projectId);
$collectionId = $index->getCollection();
$id = $index->getAttribute('$id');
$success = $dbForExternal->deleteIndex($collectionId, $id);
}
/**
* @param string $projectId
*