diff --git a/app/controllers/api/database.php b/app/controllers/api/database.php index 054a586059..ee076ef2fa 100644 --- a/app/controllers/api/database.php +++ b/app/controllers/api/database.php @@ -81,7 +81,7 @@ function createAttribute($collectionId, $attribute, $response, $dbForInternal, $ 'key' => $attributeId, 'collectionId' => $collectionId, 'type' => $type, - 'status' => 'processing', // processing, available, failed, deleting + 'status' => 'processing', // processing, available, failed, deleting, stuck 'size' => $size, 'required' => $required, 'signed' => $signed, @@ -1136,7 +1136,11 @@ App::delete('/v1/database/collections/:collectionId/attributes/:attributeId') throw new Exception('Attribute not found', 404); } - $attribute = $dbForInternal->updateDocument('attributes', $attribute->getId(), $attribute->setAttribute('status', 'deleting')); + // Only update status if removing available attribute + if ($attribute->getAttribute('status' === 'available')) { + $attribute = $dbForInternal->updateDocument('attributes', $attribute->getId(), $attribute->setAttribute('status', 'deleting')); + } + $dbForInternal->purgeDocument('collections', $collectionId); $database @@ -1233,7 +1237,7 @@ App::post('/v1/database/collections/:collectionId/indexes') $index = $dbForInternal->createDocument('indexes', new Document([ '$id' => $collectionId.'_'.$indexId, 'key' => $indexId, - 'status' => 'processing', // processing, available, failed, deleting + 'status' => 'processing', // processing, available, failed, deleting, stuck 'collectionId' => $collectionId, 'type' => $type, 'attributes' => $attributes, @@ -1388,7 +1392,11 @@ App::delete('/v1/database/collections/:collectionId/indexes/:indexId') throw new Exception('Index not found', 404); } - $index = $dbForInternal->updateDocument('indexes', $index->getId(), $index->setAttribute('status', 'deleting')); + // Only update status if removing available index + if ($index->getAttribute('status') === 'available') { + $index = $dbForInternal->updateDocument('indexes', $index->getId(), $index->setAttribute('status', 'deleting')); + } + $dbForInternal->purgeDocument('collections', $collectionId); $database diff --git a/app/workers/database.php b/app/workers/database.php index 2366b37998..8fb781dc2f 100644 --- a/app/workers/database.php +++ b/app/workers/database.php @@ -110,14 +110,14 @@ class DatabaseV1 extends Worker $key = $attribute->getAttribute('key', ''); try { - if(!$dbForExternal->deleteAttribute($collectionId, $key)) { + if(!$dbForExternal->deleteAttribute($collectionId, $key) && $attribute->getAttribute('status') !== 'failed') { throw new Exception('Failed to delete Attribute'); } $dbForInternal->deleteDocument('attributes', $attribute->getId()); } catch (\Throwable $th) { Console::error($th->getMessage()); - $dbForInternal->updateDocument('attributes', $attribute->getId(), $attribute->setAttribute('status', 'failed')); + $dbForInternal->updateDocument('attributes', $attribute->getId(), $attribute->setAttribute('status', 'stuck')); } $dbForInternal->purgeDocument('collections', $collectionId); @@ -167,14 +167,14 @@ class DatabaseV1 extends Worker $key = $index->getAttribute('key'); try { - if(!$dbForExternal->deleteIndex($collectionId, $key)) { + if(!$dbForExternal->deleteIndex($collectionId, $key) && $index->getAttribute('status') !== 'failed') { throw new Exception('Failed to delete Attribute'); } $dbForInternal->deleteDocument('indexes', $index->getId()); } catch (\Throwable $th) { Console::error($th->getMessage()); - $dbForInternal->updateDocument('indexes', $index->getId(), $index->setAttribute('status', 'failed')); + $dbForInternal->updateDocument('indexes', $index->getId(), $index->setAttribute('status', 'stuck')); } $dbForInternal->purgeDocument('collections', $collectionId); diff --git a/src/Appwrite/Utopia/Response/Model/Attribute.php b/src/Appwrite/Utopia/Response/Model/Attribute.php index 281a37a733..7d064ecb1b 100644 --- a/src/Appwrite/Utopia/Response/Model/Attribute.php +++ b/src/Appwrite/Utopia/Response/Model/Attribute.php @@ -24,7 +24,7 @@ class Attribute extends Model ]) ->addRule('status', [ 'type' => self::TYPE_STRING, - 'description' => 'Attribute status. Possible values: `available`, `processing`, `deleting`, or `failed`', + 'description' => 'Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed`', 'default' => '', 'example' => 'available', ]) diff --git a/src/Appwrite/Utopia/Response/Model/Index.php b/src/Appwrite/Utopia/Response/Model/Index.php index 4314971e39..d2d00fb196 100644 --- a/src/Appwrite/Utopia/Response/Model/Index.php +++ b/src/Appwrite/Utopia/Response/Model/Index.php @@ -24,7 +24,7 @@ class Index extends Model ]) ->addRule('status', [ 'type' => self::TYPE_STRING, - 'description' => 'Index status. Possible values: `available`, `processing`, `deleting`, or `failed`', + 'description' => 'Index status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed`', 'default' => '', 'example' => 'available', ])