From 974788db83334b8a62a3d2d88381bab98443fc8b Mon Sep 17 00:00:00 2001 From: kodumbeats Date: Wed, 27 Oct 2021 09:44:10 -0400 Subject: [PATCH] fix(api): allow failed attributes to be deleted --- app/workers/database.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/app/workers/database.php b/app/workers/database.php index c47a7bba82..3b9f36afbd 100644 --- a/app/workers/database.php +++ b/app/workers/database.php @@ -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());