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

fix(api): allow failed attributes to be deleted

This commit is contained in:
kodumbeats 2021-10-27 09:44:10 -04:00
parent adf5c1b288
commit 974788db83

View file

@ -106,12 +106,18 @@ class DatabaseV1 extends Worker
$dbForExternal = $this->getExternalDB($projectId);
$collectionId = $collection->getId();
$key = $attribute->getAttribute('key', '');
$status = $attribute->getAttribute('status', '');
// possible states at this point:
// - available: should not land in queue; controller flips these to 'deleting'
// - processing: hasn't finished creating
// - deleting: was available, in deletion queue for first time
// - failed: attribute was never created
// - stuck: attribute was available but cannot be removed
try {
if(!$dbForExternal->deleteAttribute($collectionId, $key) && $attribute->getAttribute('status') !== 'failed') {
if($status !== 'failed' && !$dbForExternal->deleteAttribute($collectionId, $key)) {
throw new Exception('Failed to delete Attribute');
}
$dbForInternal->deleteDocument('attributes', $attribute->getId());
} catch (\Throwable $th) {
Console::error($th->getMessage());
@ -214,12 +220,12 @@ class DatabaseV1 extends Worker
$collectionId = $collection->getId();
$key = $index->getAttribute('key');
$status = $index->getAttribute('status', '');
try {
if(!$dbForExternal->deleteIndex($collectionId, $key) && $index->getAttribute('status') !== 'failed') {
if($status !== 'failed' && !$dbForExternal->deleteIndex($collectionId, $key)) {
throw new Exception('Failed to delete index');
}
$dbForInternal->deleteDocument('indexes', $index->getId());
} catch (\Throwable $th) {
Console::error($th->getMessage());