Merge pull request #1567 from appwrite/feat-delete-collection-attributes-indexes
feat(refactor-db): delete internal attributes and indexes on deleteCollection
This commit is contained in:
commit
45066d99db
|
@ -6,9 +6,10 @@ arch:
|
|||
|
||||
os: linux
|
||||
|
||||
# Small change
|
||||
vm:
|
||||
size: large
|
||||
|
||||
size: large
|
||||
|
||||
language: shell
|
||||
|
||||
notifications:
|
||||
|
|
|
@ -620,12 +620,15 @@ App::delete('/v1/database/collections/:collectionId')
|
|||
throw new Exception('Collection not found', 404);
|
||||
}
|
||||
|
||||
$dbForExternal->deleteCollection($collectionId); // TDOD move to DB worker
|
||||
|
||||
if (!$dbForInternal->deleteDocument('collections', $collectionId)) {
|
||||
throw new Exception('Failed to remove collection from DB', 500);
|
||||
}
|
||||
|
||||
$deletes
|
||||
->setParam('type', DELETE_TYPE_DOCUMENT)
|
||||
->setParam('document', $collection)
|
||||
;
|
||||
|
||||
$usage->setParam('database.collections.delete', 1);
|
||||
|
||||
$events
|
||||
|
|
|
@ -44,6 +44,9 @@ class DeletesV1 extends Worker
|
|||
|
||||
switch ($document->getCollection()) {
|
||||
// TODO@kodumbeats define these as constants somewhere
|
||||
case 'collections':
|
||||
$this->deleteCollection($document, $projectId);
|
||||
break;
|
||||
case 'projects':
|
||||
$this->deleteProject($document);
|
||||
break;
|
||||
|
@ -92,6 +95,28 @@ class DeletesV1 extends Worker
|
|||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Document $document teams document
|
||||
* @param string $projectId
|
||||
*/
|
||||
protected function deleteCollection(Document $document, string $projectId): void
|
||||
{
|
||||
$collectionId = $document->getId();
|
||||
|
||||
$dbForInternal = $this->getInternalDB($projectId);
|
||||
$dbForExternal = $this->getExternalDB($projectId);
|
||||
|
||||
$this->deleteByGroup('attributes', [
|
||||
new Query('collectionId', Query::TYPE_EQUAL, [$collectionId])
|
||||
], $dbForInternal);
|
||||
|
||||
$this->deleteByGroup('indexes', [
|
||||
new Query('collectionId', Query::TYPE_EQUAL, [$collectionId])
|
||||
], $dbForInternal);
|
||||
|
||||
$dbForExternal->deleteCollection($collectionId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $timestamp1d
|
||||
* @param int $timestamp30m
|
||||
|
|
|
@ -403,5 +403,13 @@ class DatabaseCustomServerTest extends Scope
|
|||
|
||||
$this->assertEquals(400, $tooMany['headers']['status-code']);
|
||||
$this->assertEquals('Index limit exceeded', $tooMany['body']['message']);
|
||||
|
||||
$collection = $this->client->call(Client::METHOD_DELETE, '/database/collections/' . $collectionId, array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey']
|
||||
]));
|
||||
|
||||
$this->assertEquals(204, $collection['headers']['status-code']);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue