mirror of
https://github.com/appwrite/appwrite
synced 2026-05-22 08:28:42 +00:00
Merge pull request #9226 from appwrite/index-dependency-exception
Add index dependency exception
This commit is contained in:
commit
190b9cdaee
7 changed files with 56 additions and 33 deletions
|
|
@ -726,6 +726,11 @@ return [
|
|||
'description' => 'Index invalid.',
|
||||
'code' => 400,
|
||||
],
|
||||
Exception::INDEX_DEPENDENCY => [
|
||||
'name' => Exception::INDEX_DEPENDENCY,
|
||||
'description' => 'Attribute cannot be renamed or deleted. Please remove the associated index first.',
|
||||
'code' => 409,
|
||||
],
|
||||
|
||||
/** Project Errors */
|
||||
Exception::PROJECT_NOT_FOUND => [
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
// Only update status if removing available attribute
|
||||
if ($attribute->getAttribute('status') === 'available') {
|
||||
$attribute = $dbForProject->updateDocument('attributes', $attribute->getId(), $attribute->setAttribute('status', 'deleting'));
|
||||
|
|
|
|||
|
|
@ -808,6 +808,10 @@ App::error()
|
|||
break;
|
||||
case 'Utopia\Database\Exception\NotFound':
|
||||
$error = new AppwriteException(AppwriteException::COLLECTION_NOT_FOUND, $error->getMessage(), previous: $error);
|
||||
break;
|
||||
case 'Utopia\Database\Exception\Dependency':
|
||||
$error = new AppwriteException(AppwriteException::INDEX_DEPENDENCY, null, previous: $error);
|
||||
break;
|
||||
}
|
||||
|
||||
$code = $error->getCode();
|
||||
|
|
|
|||
|
|
@ -770,7 +770,7 @@ Structure::addFormat(APP_DATABASE_ATTRIBUTE_DATETIME, function () {
|
|||
}, Database::VAR_DATETIME);
|
||||
|
||||
Structure::addFormat(APP_DATABASE_ATTRIBUTE_ENUM, function ($attribute) {
|
||||
$elements = $attribute['formatOptions']['elements'];
|
||||
$elements = $attribute['formatOptions']['elements'] ?? [];
|
||||
return new WhiteList($elements, true);
|
||||
}, Database::VAR_STRING);
|
||||
|
||||
|
|
|
|||
|
|
@ -45,13 +45,13 @@
|
|||
"ext-sockets": "*",
|
||||
"appwrite/php-runtimes": "0.16.*",
|
||||
"appwrite/php-clamav": "2.0.*",
|
||||
"utopia-php/abuse": "0.46.*",
|
||||
"utopia-php/abuse": "0.47.*",
|
||||
"utopia-php/analytics": "0.10.*",
|
||||
"utopia-php/audit": "0.46.*",
|
||||
"utopia-php/audit": "0.47.*",
|
||||
"utopia-php/cache": "0.11.*",
|
||||
"utopia-php/cli": "0.15.*",
|
||||
"utopia-php/config": "0.2.*",
|
||||
"utopia-php/database": "0.53.32",
|
||||
"utopia-php/database": "0.56.4",
|
||||
"utopia-php/domains": "0.5.*",
|
||||
"utopia-php/dsn": "0.2.1",
|
||||
"utopia-php/framework": "0.33.*",
|
||||
|
|
|
|||
58
composer.lock
generated
58
composer.lock
generated
|
|
@ -4,7 +4,7 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "92b40e75d531c98b72508dd104eeab0d",
|
||||
"content-hash": "7ef4409cc1690563b87dffc0d52b06d5",
|
||||
"packages": [
|
||||
{
|
||||
"name": "adhocore/jwt",
|
||||
|
|
@ -3136,16 +3136,16 @@
|
|||
},
|
||||
{
|
||||
"name": "utopia-php/abuse",
|
||||
"version": "0.46.2",
|
||||
"version": "0.47.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/utopia-php/abuse.git",
|
||||
"reference": "59749df988430b28953fb5cabfad88b0ff5b539b"
|
||||
"reference": "2b52bb362234d4072b647ed57db1b3be030f57c2"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/utopia-php/abuse/zipball/59749df988430b28953fb5cabfad88b0ff5b539b",
|
||||
"reference": "59749df988430b28953fb5cabfad88b0ff5b539b",
|
||||
"url": "https://api.github.com/repos/utopia-php/abuse/zipball/2b52bb362234d4072b647ed57db1b3be030f57c2",
|
||||
"reference": "2b52bb362234d4072b647ed57db1b3be030f57c2",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
|
@ -3153,7 +3153,7 @@
|
|||
"ext-pdo": "*",
|
||||
"ext-redis": "*",
|
||||
"php": ">=8.0",
|
||||
"utopia-php/database": "0.53.32"
|
||||
"utopia-php/database": "0.56.*"
|
||||
},
|
||||
"require-dev": {
|
||||
"laravel/pint": "1.5.*",
|
||||
|
|
@ -3181,9 +3181,9 @@
|
|||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/utopia-php/abuse/issues",
|
||||
"source": "https://github.com/utopia-php/abuse/tree/0.46.2"
|
||||
"source": "https://github.com/utopia-php/abuse/tree/0.47.0"
|
||||
},
|
||||
"time": "2025-01-13T02:09:43+00:00"
|
||||
"time": "2025-01-15T02:41:02+00:00"
|
||||
},
|
||||
{
|
||||
"name": "utopia-php/analytics",
|
||||
|
|
@ -3233,21 +3233,21 @@
|
|||
},
|
||||
{
|
||||
"name": "utopia-php/audit",
|
||||
"version": "0.46.1",
|
||||
"version": "0.47.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/utopia-php/audit.git",
|
||||
"reference": "21255fa1ce66433140a43d380b2859c7f0a0bb37"
|
||||
"reference": "1ebd5784ba68645073426f2f04a67726a1bde4d7"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/utopia-php/audit/zipball/21255fa1ce66433140a43d380b2859c7f0a0bb37",
|
||||
"reference": "21255fa1ce66433140a43d380b2859c7f0a0bb37",
|
||||
"url": "https://api.github.com/repos/utopia-php/audit/zipball/1ebd5784ba68645073426f2f04a67726a1bde4d7",
|
||||
"reference": "1ebd5784ba68645073426f2f04a67726a1bde4d7",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=8.0",
|
||||
"utopia-php/database": "0.53.32"
|
||||
"utopia-php/database": "0.56.*"
|
||||
},
|
||||
"require-dev": {
|
||||
"laravel/pint": "1.5.*",
|
||||
|
|
@ -3274,9 +3274,9 @@
|
|||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/utopia-php/audit/issues",
|
||||
"source": "https://github.com/utopia-php/audit/tree/0.46.1"
|
||||
"source": "https://github.com/utopia-php/audit/tree/0.47.0"
|
||||
},
|
||||
"time": "2025-01-13T02:19:56+00:00"
|
||||
"time": "2025-01-15T02:40:53+00:00"
|
||||
},
|
||||
{
|
||||
"name": "utopia-php/cache",
|
||||
|
|
@ -3476,16 +3476,16 @@
|
|||
},
|
||||
{
|
||||
"name": "utopia-php/database",
|
||||
"version": "0.53.32",
|
||||
"version": "0.56.4",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/utopia-php/database.git",
|
||||
"reference": "981a1241139b42dccd531511130b79137740b205"
|
||||
"reference": "240478a60797124a885ceac40046fe47c22415b7"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/utopia-php/database/zipball/981a1241139b42dccd531511130b79137740b205",
|
||||
"reference": "981a1241139b42dccd531511130b79137740b205",
|
||||
"url": "https://api.github.com/repos/utopia-php/database/zipball/240478a60797124a885ceac40046fe47c22415b7",
|
||||
"reference": "240478a60797124a885ceac40046fe47c22415b7",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
|
@ -3526,9 +3526,9 @@
|
|||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/utopia-php/database/issues",
|
||||
"source": "https://github.com/utopia-php/database/tree/0.53.32"
|
||||
"source": "https://github.com/utopia-php/database/tree/0.56.4"
|
||||
},
|
||||
"time": "2025-01-10T08:53:47+00:00"
|
||||
"time": "2025-01-20T09:22:08+00:00"
|
||||
},
|
||||
{
|
||||
"name": "utopia-php/domains",
|
||||
|
|
@ -3929,16 +3929,16 @@
|
|||
},
|
||||
{
|
||||
"name": "utopia-php/migration",
|
||||
"version": "0.6.14",
|
||||
"version": "0.6.15",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/utopia-php/migration.git",
|
||||
"reference": "59a19f09ded0ccab4c8cca35b1242c01e2b9cfd2"
|
||||
"reference": "e849ec3e7ad38f5f5273ebb0132b112639cdf01c"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/utopia-php/migration/zipball/59a19f09ded0ccab4c8cca35b1242c01e2b9cfd2",
|
||||
"reference": "59a19f09ded0ccab4c8cca35b1242c01e2b9cfd2",
|
||||
"url": "https://api.github.com/repos/utopia-php/migration/zipball/e849ec3e7ad38f5f5273ebb0132b112639cdf01c",
|
||||
"reference": "e849ec3e7ad38f5f5273ebb0132b112639cdf01c",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
|
@ -3946,7 +3946,7 @@
|
|||
"ext-curl": "*",
|
||||
"ext-openssl": "*",
|
||||
"php": "8.3.*",
|
||||
"utopia-php/database": "0.53.*",
|
||||
"utopia-php/database": "0.56.*",
|
||||
"utopia-php/dsn": "0.2.*",
|
||||
"utopia-php/framework": "0.33.*",
|
||||
"utopia-php/storage": "0.18.*"
|
||||
|
|
@ -3979,9 +3979,9 @@
|
|||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/utopia-php/migration/issues",
|
||||
"source": "https://github.com/utopia-php/migration/tree/0.6.14"
|
||||
"source": "https://github.com/utopia-php/migration/tree/0.6.15"
|
||||
},
|
||||
"time": "2025-01-08T01:07:25+00:00"
|
||||
"time": "2025-01-15T04:55:08+00:00"
|
||||
},
|
||||
{
|
||||
"name": "utopia-php/mongo",
|
||||
|
|
@ -8556,7 +8556,7 @@
|
|||
],
|
||||
"aliases": [],
|
||||
"minimum-stability": "stable",
|
||||
"stability-flags": {},
|
||||
"stability-flags": [],
|
||||
"prefer-stable": false,
|
||||
"prefer-lowest": false,
|
||||
"platform": {
|
||||
|
|
|
|||
|
|
@ -210,6 +210,7 @@ class Exception extends \Exception
|
|||
public const INDEX_LIMIT_EXCEEDED = 'index_limit_exceeded';
|
||||
public const INDEX_ALREADY_EXISTS = 'index_already_exists';
|
||||
public const INDEX_INVALID = 'index_invalid';
|
||||
public const INDEX_DEPENDENCY = 'index_dependency';
|
||||
|
||||
/** Projects */
|
||||
public const PROJECT_NOT_FOUND = 'project_not_found';
|
||||
|
|
|
|||
Loading…
Reference in a new issue