INDEX_DEPENDENCY

This commit is contained in:
fogelito
2025-01-16 17:20:30 +02:00
parent 2ca690ccbd
commit 0afbfe2f84
3 changed files with 54 additions and 32 deletions
+13
View File
@@ -36,6 +36,7 @@ use Utopia\Database\Query;
use Utopia\Database\Validator\Authorization;
use Utopia\Database\Validator\Datetime as DatetimeValidator;
use Utopia\Database\Validator\Index as IndexValidator;
use Utopia\Database\Validator\IndexDependency as IndexDependencyValidator;
use Utopia\Database\Validator\Key;
use Utopia\Database\Validator\Permissions;
use Utopia\Database\Validator\Queries;
@@ -2421,6 +2422,18 @@ App::delete('/v1/databases/:databaseId/collections/:collectionId/attributes/:key
throw new Exception(Exception::ATTRIBUTE_NOT_FOUND);
}
/**
* Check index dependency
*/
$validator = new IndexDependencyValidator(
$collection->getAttribute('indexes'),
$dbForProject->getAdapter()->getSupportForCastIndexArray(),
);
if (! $validator->isValid($attribute)) {
throw new Exception(Exception::INDEX_DEPENDENCY, $validator->getDescription());
}
// Only update status if removing available attribute
if ($attribute->getAttribute('status') === 'available') {
$attribute = $dbForProject->updateDocument('attributes', $attribute->getId(), $attribute->setAttribute('status', 'deleting'));