From 554a66681334911c8f16b30f69488f9b9ffb16b9 Mon Sep 17 00:00:00 2001 From: fogelito Date: Wed, 17 Apr 2024 15:42:06 +0300 Subject: [PATCH 1/7] Delete relating --- composer.lock | 111 +++++++++++--------- src/Appwrite/Platform/Workers/Databases.php | 28 +++-- 2 files changed, 76 insertions(+), 63 deletions(-) diff --git a/composer.lock b/composer.lock index 506d6d9a67..15fbde266b 100644 --- a/composer.lock +++ b/composer.lock @@ -156,21 +156,21 @@ }, { "name": "appwrite/php-runtimes", - "version": "0.13.3", + "version": "0.13.5", "source": { "type": "git", "url": "https://github.com/appwrite/runtimes.git", - "reference": "5d93fc578a9a543bcdc9b2c0562d80a51d56c73d" + "reference": "ba24c3a163f1a1da6cd355db92def508d05e59f7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/appwrite/runtimes/zipball/5d93fc578a9a543bcdc9b2c0562d80a51d56c73d", - "reference": "5d93fc578a9a543bcdc9b2c0562d80a51d56c73d", + "url": "https://api.github.com/repos/appwrite/runtimes/zipball/ba24c3a163f1a1da6cd355db92def508d05e59f7", + "reference": "ba24c3a163f1a1da6cd355db92def508d05e59f7", "shasum": "" }, "require": { "php": ">=8.0", - "utopia-php/system": "0.7.*" + "utopia-php/system": "0.8.*" }, "require-dev": { "phpunit/phpunit": "^9.3", @@ -204,9 +204,9 @@ ], "support": { "issues": "https://github.com/appwrite/runtimes/issues", - "source": "https://github.com/appwrite/runtimes/tree/0.13.3" + "source": "https://github.com/appwrite/runtimes/tree/0.13.5" }, - "time": "2024-03-01T14:47:47+00:00" + "time": "2024-04-01T10:35:02+00:00" }, { "name": "beberlei/assert", @@ -2337,16 +2337,16 @@ }, { "name": "utopia-php/storage", - "version": "0.18.3", + "version": "0.18.4", "source": { "type": "git", "url": "https://github.com/utopia-php/storage.git", - "reference": "faa0279519ac14f3501e8b138e0865ad9d12bff6" + "reference": "94ab8758fabcefee5c5fa723616e45719833f922" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/storage/zipball/faa0279519ac14f3501e8b138e0865ad9d12bff6", - "reference": "faa0279519ac14f3501e8b138e0865ad9d12bff6", + "url": "https://api.github.com/repos/utopia-php/storage/zipball/94ab8758fabcefee5c5fa723616e45719833f922", + "reference": "94ab8758fabcefee5c5fa723616e45719833f922", "shasum": "" }, "require": { @@ -2386,9 +2386,9 @@ ], "support": { "issues": "https://github.com/utopia-php/storage/issues", - "source": "https://github.com/utopia-php/storage/tree/0.18.3" + "source": "https://github.com/utopia-php/storage/tree/0.18.4" }, - "time": "2023-12-31T11:45:12+00:00" + "time": "2024-04-02T08:24:09+00:00" }, { "name": "utopia-php/swoole", @@ -2443,16 +2443,16 @@ }, { "name": "utopia-php/system", - "version": "0.7.2", + "version": "0.8.0", "source": { "type": "git", "url": "https://github.com/utopia-php/system.git", - "reference": "4593d4d334b0c15879c4744a826e0362924c5d66" + "reference": "a2cbfb3c69b9ecb8b6f06c5774f3cf279ea7665e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/system/zipball/4593d4d334b0c15879c4744a826e0362924c5d66", - "reference": "4593d4d334b0c15879c4744a826e0362924c5d66", + "url": "https://api.github.com/repos/utopia-php/system/zipball/a2cbfb3c69b9ecb8b6f06c5774f3cf279ea7665e", + "reference": "a2cbfb3c69b9ecb8b6f06c5774f3cf279ea7665e", "shasum": "" }, "require": { @@ -2493,9 +2493,9 @@ ], "support": { "issues": "https://github.com/utopia-php/system/issues", - "source": "https://github.com/utopia-php/system/tree/0.7.2" + "source": "https://github.com/utopia-php/system/tree/0.8.0" }, - "time": "2023-10-20T01:39:17+00:00" + "time": "2024-04-01T10:22:28+00:00" }, { "name": "utopia-php/vcs", @@ -2731,16 +2731,16 @@ "packages-dev": [ { "name": "appwrite/sdk-generator", - "version": "0.37.8", + "version": "0.37.10", "source": { "type": "git", "url": "https://github.com/appwrite/sdk-generator.git", - "reference": "29844ac860237018a5d6bce17f8b591c996081ef" + "reference": "d875e74c2d64e11c0f787531cea0b3b3703f476a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/29844ac860237018a5d6bce17f8b591c996081ef", - "reference": "29844ac860237018a5d6bce17f8b591c996081ef", + "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/d875e74c2d64e11c0f787531cea0b3b3703f476a", + "reference": "d875e74c2d64e11c0f787531cea0b3b3703f476a", "shasum": "" }, "require": { @@ -2776,9 +2776,9 @@ "description": "Appwrite PHP library for generating API SDKs for multiple programming languages and platforms", "support": { "issues": "https://github.com/appwrite/sdk-generator/issues", - "source": "https://github.com/appwrite/sdk-generator/tree/0.37.8" + "source": "https://github.com/appwrite/sdk-generator/tree/0.37.10" }, - "time": "2024-03-12T14:13:43+00:00" + "time": "2024-04-17T07:55:05+00:00" }, { "name": "doctrine/deprecations", @@ -2899,16 +2899,16 @@ }, { "name": "laravel/pint", - "version": "v1.14.0", + "version": "v1.15.1", "source": { "type": "git", "url": "https://github.com/laravel/pint.git", - "reference": "6b127276e3f263f7bb17d5077e9e0269e61b2a0e" + "reference": "5f288b5e79938cc72f5c298d384e639de87507c6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/pint/zipball/6b127276e3f263f7bb17d5077e9e0269e61b2a0e", - "reference": "6b127276e3f263f7bb17d5077e9e0269e61b2a0e", + "url": "https://api.github.com/repos/laravel/pint/zipball/5f288b5e79938cc72f5c298d384e639de87507c6", + "reference": "5f288b5e79938cc72f5c298d384e639de87507c6", "shasum": "" }, "require": { @@ -2919,13 +2919,13 @@ "php": "^8.1.0" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^3.49.0", - "illuminate/view": "^10.43.0", - "larastan/larastan": "^2.8.1", + "friendsofphp/php-cs-fixer": "^3.52.1", + "illuminate/view": "^10.48.4", + "larastan/larastan": "^2.9.2", "laravel-zero/framework": "^10.3.0", - "mockery/mockery": "^1.6.7", + "mockery/mockery": "^1.6.11", "nunomaduro/termwind": "^1.15.1", - "pestphp/pest": "^2.33.6" + "pestphp/pest": "^2.34.5" }, "bin": [ "builds/pint" @@ -2961,7 +2961,7 @@ "issues": "https://github.com/laravel/pint/issues", "source": "https://github.com/laravel/pint" }, - "time": "2024-02-20T17:38:05+00:00" + "time": "2024-04-02T14:28:47+00:00" }, { "name": "matthiasmullie/minify", @@ -3377,28 +3377,35 @@ }, { "name": "phpdocumentor/reflection-docblock", - "version": "5.3.0", + "version": "5.4.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "622548b623e81ca6d78b721c5e029f4ce664f170" + "reference": "298d2febfe79d03fe714eb871d5538da55205b1a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/622548b623e81ca6d78b721c5e029f4ce664f170", - "reference": "622548b623e81ca6d78b721c5e029f4ce664f170", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/298d2febfe79d03fe714eb871d5538da55205b1a", + "reference": "298d2febfe79d03fe714eb871d5538da55205b1a", "shasum": "" }, "require": { + "doctrine/deprecations": "^1.1", "ext-filter": "*", - "php": "^7.2 || ^8.0", + "php": "^7.4 || ^8.0", "phpdocumentor/reflection-common": "^2.2", - "phpdocumentor/type-resolver": "^1.3", + "phpdocumentor/type-resolver": "^1.7", + "phpstan/phpdoc-parser": "^1.7", "webmozart/assert": "^1.9.1" }, "require-dev": { - "mockery/mockery": "~1.3.2", - "psalm/phar": "^4.8" + "mockery/mockery": "~1.3.5", + "phpstan/extension-installer": "^1.1", + "phpstan/phpstan": "^1.8", + "phpstan/phpstan-mockery": "^1.1", + "phpstan/phpstan-webmozart-assert": "^1.2", + "phpunit/phpunit": "^9.5", + "vimeo/psalm": "^5.13" }, "type": "library", "extra": { @@ -3422,15 +3429,15 @@ }, { "name": "Jaap van Otterdijk", - "email": "account@ijaap.nl" + "email": "opensource@ijaap.nl" } ], "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", "support": { "issues": "https://github.com/phpDocumentor/ReflectionDocBlock/issues", - "source": "https://github.com/phpDocumentor/ReflectionDocBlock/tree/5.3.0" + "source": "https://github.com/phpDocumentor/ReflectionDocBlock/tree/5.4.0" }, - "time": "2021-10-19T17:43:47+00:00" + "time": "2024-04-09T21:13:58+00:00" }, { "name": "phpdocumentor/type-resolver", @@ -3561,16 +3568,16 @@ }, { "name": "phpstan/phpdoc-parser", - "version": "1.27.0", + "version": "1.28.0", "source": { "type": "git", "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "86e4d5a4b036f8f0be1464522f4c6b584c452757" + "reference": "cd06d6b1a1b3c75b0b83f97577869fd85a3cd4fb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/86e4d5a4b036f8f0be1464522f4c6b584c452757", - "reference": "86e4d5a4b036f8f0be1464522f4c6b584c452757", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/cd06d6b1a1b3c75b0b83f97577869fd85a3cd4fb", + "reference": "cd06d6b1a1b3c75b0b83f97577869fd85a3cd4fb", "shasum": "" }, "require": { @@ -3602,9 +3609,9 @@ "description": "PHPDoc parser with support for nullable, intersection and generic types", "support": { "issues": "https://github.com/phpstan/phpdoc-parser/issues", - "source": "https://github.com/phpstan/phpdoc-parser/tree/1.27.0" + "source": "https://github.com/phpstan/phpdoc-parser/tree/1.28.0" }, - "time": "2024-03-21T13:14:53+00:00" + "time": "2024-04-03T18:51:33+00:00" }, { "name": "phpunit/php-code-coverage", diff --git a/src/Appwrite/Platform/Workers/Databases.php b/src/Appwrite/Platform/Workers/Databases.php index a5ac3b47d1..6a7e38e3e1 100644 --- a/src/Appwrite/Platform/Workers/Databases.php +++ b/src/Appwrite/Platform/Workers/Databases.php @@ -515,19 +515,25 @@ class Databases extends Action $databaseId = $database->getId(); $databaseInternalId = $database->getInternalId(); - $relationships = \array_filter( - $collection->getAttribute('attributes'), - fn ($attribute) => $attribute['type'] === Database::VAR_RELATIONSHIP - ); + /** + * Related collections relating to current collection + */ + $attributes = $dbForProject->find('attributes', [ + Query::equal('databaseInternalId', [$databaseInternalId]), + Query::equal('type', [Database::VAR_RELATIONSHIP]), + Query::notEqual('collectionInternalId', $collectionInternalId), + Query::contains('options', ['"relatedCollection":"'. $collectionId .'"']), // Comment in Version < 1.5 + Query::limit(PHP_INT_MAX) + ]); - foreach ($relationships as $relationship) { - if (!$relationship['twoWay']) { - continue; + foreach ($attributes as $attribute) { + $options = $attribute->getAttribute('options', []); + if($options['relatedCollection'] === $collectionId){ // Remove if using contains query above + $dbForProject->deleteDocument('attributes', $attribute->getId()); + Console::success('Deleted document "' . $attribute->getId() . '" related collection successfully'); + $dbForProject->purgeCachedDocument('database_' . $databaseInternalId, $attribute->getAttribute('collectionId')); + $dbForProject->purgeCachedCollection('database_' . $databaseInternalId . '_collection_' . $attribute->getAttribute('collectionInternalId')); } - $relatedCollection = $dbForProject->getDocument('database_' . $databaseInternalId, $relationship['relatedCollection']); - $dbForProject->deleteDocument('attributes', $databaseInternalId . '_' . $relatedCollection->getInternalId() . '_' . $relationship['twoWayKey']); - $dbForProject->purgeCachedDocument('database_' . $databaseInternalId, $relatedCollection->getId()); - $dbForProject->purgeCachedCollection('database_' . $databaseInternalId . '_collection_' . $relatedCollection->getInternalId()); } $dbForProject->deleteCollection('database_' . $databaseInternalId . '_collection_' . $collection->getInternalId()); From 28a72efe22e146957eb58174ee2d98464b0c6806 Mon Sep 17 00:00:00 2001 From: fogelito Date: Wed, 17 Apr 2024 15:43:31 +0300 Subject: [PATCH 2/7] formatting --- src/Appwrite/Platform/Workers/Databases.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Workers/Databases.php b/src/Appwrite/Platform/Workers/Databases.php index 6a7e38e3e1..6cb1bf3c28 100644 --- a/src/Appwrite/Platform/Workers/Databases.php +++ b/src/Appwrite/Platform/Workers/Databases.php @@ -528,7 +528,7 @@ class Databases extends Action foreach ($attributes as $attribute) { $options = $attribute->getAttribute('options', []); - if($options['relatedCollection'] === $collectionId){ // Remove if using contains query above + if($options['relatedCollection'] === $collectionId) { // Remove if using contains query above $dbForProject->deleteDocument('attributes', $attribute->getId()); Console::success('Deleted document "' . $attribute->getId() . '" related collection successfully'); $dbForProject->purgeCachedDocument('database_' . $databaseInternalId, $attribute->getAttribute('collectionId')); From 2babf7f59df081ef24f3e57158dfe685445cc69e Mon Sep 17 00:00:00 2001 From: fogelito Date: Thu, 18 Apr 2024 10:08:19 +0300 Subject: [PATCH 3/7] 1.5.x version --- composer.lock | 12 ++++++------ src/Appwrite/Platform/Workers/Databases.php | 13 +++++-------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/composer.lock b/composer.lock index 15fbde266b..37149d8e23 100644 --- a/composer.lock +++ b/composer.lock @@ -2731,16 +2731,16 @@ "packages-dev": [ { "name": "appwrite/sdk-generator", - "version": "0.37.10", + "version": "0.37.12", "source": { "type": "git", "url": "https://github.com/appwrite/sdk-generator.git", - "reference": "d875e74c2d64e11c0f787531cea0b3b3703f476a" + "reference": "882881934e8014b2135590e7ea5f402ab4513c38" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/d875e74c2d64e11c0f787531cea0b3b3703f476a", - "reference": "d875e74c2d64e11c0f787531cea0b3b3703f476a", + "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/882881934e8014b2135590e7ea5f402ab4513c38", + "reference": "882881934e8014b2135590e7ea5f402ab4513c38", "shasum": "" }, "require": { @@ -2776,9 +2776,9 @@ "description": "Appwrite PHP library for generating API SDKs for multiple programming languages and platforms", "support": { "issues": "https://github.com/appwrite/sdk-generator/issues", - "source": "https://github.com/appwrite/sdk-generator/tree/0.37.10" + "source": "https://github.com/appwrite/sdk-generator/tree/0.37.12" }, - "time": "2024-04-17T07:55:05+00:00" + "time": "2024-04-17T19:14:43+00:00" }, { "name": "doctrine/deprecations", diff --git a/src/Appwrite/Platform/Workers/Databases.php b/src/Appwrite/Platform/Workers/Databases.php index 6cb1bf3c28..0d1ae14890 100644 --- a/src/Appwrite/Platform/Workers/Databases.php +++ b/src/Appwrite/Platform/Workers/Databases.php @@ -522,18 +522,15 @@ class Databases extends Action Query::equal('databaseInternalId', [$databaseInternalId]), Query::equal('type', [Database::VAR_RELATIONSHIP]), Query::notEqual('collectionInternalId', $collectionInternalId), - Query::contains('options', ['"relatedCollection":"'. $collectionId .'"']), // Comment in Version < 1.5 + Query::contains('options', ['"relatedCollection":"'. $collectionId .'"']), Query::limit(PHP_INT_MAX) ]); foreach ($attributes as $attribute) { - $options = $attribute->getAttribute('options', []); - if($options['relatedCollection'] === $collectionId) { // Remove if using contains query above - $dbForProject->deleteDocument('attributes', $attribute->getId()); - Console::success('Deleted document "' . $attribute->getId() . '" related collection successfully'); - $dbForProject->purgeCachedDocument('database_' . $databaseInternalId, $attribute->getAttribute('collectionId')); - $dbForProject->purgeCachedCollection('database_' . $databaseInternalId . '_collection_' . $attribute->getAttribute('collectionInternalId')); - } + $dbForProject->deleteDocument('attributes', $attribute->getId()); + Console::success('Deleted document "' . $attribute->getId() . '" related collection successfully'); + $dbForProject->purgeCachedDocument('database_' . $databaseInternalId, $attribute->getAttribute('collectionId')); + $dbForProject->purgeCachedCollection('database_' . $databaseInternalId . '_collection_' . $attribute->getAttribute('collectionInternalId')); } $dbForProject->deleteCollection('database_' . $databaseInternalId . '_collection_' . $collection->getInternalId()); From 0f1872cb5ab3d6aa7b7707d24edf96b204ec542c Mon Sep 17 00:00:00 2001 From: fogelito Date: Thu, 18 Apr 2024 10:46:40 +0300 Subject: [PATCH 4/7] revert composer.lock --- composer.lock | 111 +++++++++++++++++++++++--------------------------- 1 file changed, 52 insertions(+), 59 deletions(-) diff --git a/composer.lock b/composer.lock index 37149d8e23..506d6d9a67 100644 --- a/composer.lock +++ b/composer.lock @@ -156,21 +156,21 @@ }, { "name": "appwrite/php-runtimes", - "version": "0.13.5", + "version": "0.13.3", "source": { "type": "git", "url": "https://github.com/appwrite/runtimes.git", - "reference": "ba24c3a163f1a1da6cd355db92def508d05e59f7" + "reference": "5d93fc578a9a543bcdc9b2c0562d80a51d56c73d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/appwrite/runtimes/zipball/ba24c3a163f1a1da6cd355db92def508d05e59f7", - "reference": "ba24c3a163f1a1da6cd355db92def508d05e59f7", + "url": "https://api.github.com/repos/appwrite/runtimes/zipball/5d93fc578a9a543bcdc9b2c0562d80a51d56c73d", + "reference": "5d93fc578a9a543bcdc9b2c0562d80a51d56c73d", "shasum": "" }, "require": { "php": ">=8.0", - "utopia-php/system": "0.8.*" + "utopia-php/system": "0.7.*" }, "require-dev": { "phpunit/phpunit": "^9.3", @@ -204,9 +204,9 @@ ], "support": { "issues": "https://github.com/appwrite/runtimes/issues", - "source": "https://github.com/appwrite/runtimes/tree/0.13.5" + "source": "https://github.com/appwrite/runtimes/tree/0.13.3" }, - "time": "2024-04-01T10:35:02+00:00" + "time": "2024-03-01T14:47:47+00:00" }, { "name": "beberlei/assert", @@ -2337,16 +2337,16 @@ }, { "name": "utopia-php/storage", - "version": "0.18.4", + "version": "0.18.3", "source": { "type": "git", "url": "https://github.com/utopia-php/storage.git", - "reference": "94ab8758fabcefee5c5fa723616e45719833f922" + "reference": "faa0279519ac14f3501e8b138e0865ad9d12bff6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/storage/zipball/94ab8758fabcefee5c5fa723616e45719833f922", - "reference": "94ab8758fabcefee5c5fa723616e45719833f922", + "url": "https://api.github.com/repos/utopia-php/storage/zipball/faa0279519ac14f3501e8b138e0865ad9d12bff6", + "reference": "faa0279519ac14f3501e8b138e0865ad9d12bff6", "shasum": "" }, "require": { @@ -2386,9 +2386,9 @@ ], "support": { "issues": "https://github.com/utopia-php/storage/issues", - "source": "https://github.com/utopia-php/storage/tree/0.18.4" + "source": "https://github.com/utopia-php/storage/tree/0.18.3" }, - "time": "2024-04-02T08:24:09+00:00" + "time": "2023-12-31T11:45:12+00:00" }, { "name": "utopia-php/swoole", @@ -2443,16 +2443,16 @@ }, { "name": "utopia-php/system", - "version": "0.8.0", + "version": "0.7.2", "source": { "type": "git", "url": "https://github.com/utopia-php/system.git", - "reference": "a2cbfb3c69b9ecb8b6f06c5774f3cf279ea7665e" + "reference": "4593d4d334b0c15879c4744a826e0362924c5d66" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/system/zipball/a2cbfb3c69b9ecb8b6f06c5774f3cf279ea7665e", - "reference": "a2cbfb3c69b9ecb8b6f06c5774f3cf279ea7665e", + "url": "https://api.github.com/repos/utopia-php/system/zipball/4593d4d334b0c15879c4744a826e0362924c5d66", + "reference": "4593d4d334b0c15879c4744a826e0362924c5d66", "shasum": "" }, "require": { @@ -2493,9 +2493,9 @@ ], "support": { "issues": "https://github.com/utopia-php/system/issues", - "source": "https://github.com/utopia-php/system/tree/0.8.0" + "source": "https://github.com/utopia-php/system/tree/0.7.2" }, - "time": "2024-04-01T10:22:28+00:00" + "time": "2023-10-20T01:39:17+00:00" }, { "name": "utopia-php/vcs", @@ -2731,16 +2731,16 @@ "packages-dev": [ { "name": "appwrite/sdk-generator", - "version": "0.37.12", + "version": "0.37.8", "source": { "type": "git", "url": "https://github.com/appwrite/sdk-generator.git", - "reference": "882881934e8014b2135590e7ea5f402ab4513c38" + "reference": "29844ac860237018a5d6bce17f8b591c996081ef" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/882881934e8014b2135590e7ea5f402ab4513c38", - "reference": "882881934e8014b2135590e7ea5f402ab4513c38", + "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/29844ac860237018a5d6bce17f8b591c996081ef", + "reference": "29844ac860237018a5d6bce17f8b591c996081ef", "shasum": "" }, "require": { @@ -2776,9 +2776,9 @@ "description": "Appwrite PHP library for generating API SDKs for multiple programming languages and platforms", "support": { "issues": "https://github.com/appwrite/sdk-generator/issues", - "source": "https://github.com/appwrite/sdk-generator/tree/0.37.12" + "source": "https://github.com/appwrite/sdk-generator/tree/0.37.8" }, - "time": "2024-04-17T19:14:43+00:00" + "time": "2024-03-12T14:13:43+00:00" }, { "name": "doctrine/deprecations", @@ -2899,16 +2899,16 @@ }, { "name": "laravel/pint", - "version": "v1.15.1", + "version": "v1.14.0", "source": { "type": "git", "url": "https://github.com/laravel/pint.git", - "reference": "5f288b5e79938cc72f5c298d384e639de87507c6" + "reference": "6b127276e3f263f7bb17d5077e9e0269e61b2a0e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/pint/zipball/5f288b5e79938cc72f5c298d384e639de87507c6", - "reference": "5f288b5e79938cc72f5c298d384e639de87507c6", + "url": "https://api.github.com/repos/laravel/pint/zipball/6b127276e3f263f7bb17d5077e9e0269e61b2a0e", + "reference": "6b127276e3f263f7bb17d5077e9e0269e61b2a0e", "shasum": "" }, "require": { @@ -2919,13 +2919,13 @@ "php": "^8.1.0" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^3.52.1", - "illuminate/view": "^10.48.4", - "larastan/larastan": "^2.9.2", + "friendsofphp/php-cs-fixer": "^3.49.0", + "illuminate/view": "^10.43.0", + "larastan/larastan": "^2.8.1", "laravel-zero/framework": "^10.3.0", - "mockery/mockery": "^1.6.11", + "mockery/mockery": "^1.6.7", "nunomaduro/termwind": "^1.15.1", - "pestphp/pest": "^2.34.5" + "pestphp/pest": "^2.33.6" }, "bin": [ "builds/pint" @@ -2961,7 +2961,7 @@ "issues": "https://github.com/laravel/pint/issues", "source": "https://github.com/laravel/pint" }, - "time": "2024-04-02T14:28:47+00:00" + "time": "2024-02-20T17:38:05+00:00" }, { "name": "matthiasmullie/minify", @@ -3377,35 +3377,28 @@ }, { "name": "phpdocumentor/reflection-docblock", - "version": "5.4.0", + "version": "5.3.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "298d2febfe79d03fe714eb871d5538da55205b1a" + "reference": "622548b623e81ca6d78b721c5e029f4ce664f170" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/298d2febfe79d03fe714eb871d5538da55205b1a", - "reference": "298d2febfe79d03fe714eb871d5538da55205b1a", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/622548b623e81ca6d78b721c5e029f4ce664f170", + "reference": "622548b623e81ca6d78b721c5e029f4ce664f170", "shasum": "" }, "require": { - "doctrine/deprecations": "^1.1", "ext-filter": "*", - "php": "^7.4 || ^8.0", + "php": "^7.2 || ^8.0", "phpdocumentor/reflection-common": "^2.2", - "phpdocumentor/type-resolver": "^1.7", - "phpstan/phpdoc-parser": "^1.7", + "phpdocumentor/type-resolver": "^1.3", "webmozart/assert": "^1.9.1" }, "require-dev": { - "mockery/mockery": "~1.3.5", - "phpstan/extension-installer": "^1.1", - "phpstan/phpstan": "^1.8", - "phpstan/phpstan-mockery": "^1.1", - "phpstan/phpstan-webmozart-assert": "^1.2", - "phpunit/phpunit": "^9.5", - "vimeo/psalm": "^5.13" + "mockery/mockery": "~1.3.2", + "psalm/phar": "^4.8" }, "type": "library", "extra": { @@ -3429,15 +3422,15 @@ }, { "name": "Jaap van Otterdijk", - "email": "opensource@ijaap.nl" + "email": "account@ijaap.nl" } ], "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", "support": { "issues": "https://github.com/phpDocumentor/ReflectionDocBlock/issues", - "source": "https://github.com/phpDocumentor/ReflectionDocBlock/tree/5.4.0" + "source": "https://github.com/phpDocumentor/ReflectionDocBlock/tree/5.3.0" }, - "time": "2024-04-09T21:13:58+00:00" + "time": "2021-10-19T17:43:47+00:00" }, { "name": "phpdocumentor/type-resolver", @@ -3568,16 +3561,16 @@ }, { "name": "phpstan/phpdoc-parser", - "version": "1.28.0", + "version": "1.27.0", "source": { "type": "git", "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "cd06d6b1a1b3c75b0b83f97577869fd85a3cd4fb" + "reference": "86e4d5a4b036f8f0be1464522f4c6b584c452757" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/cd06d6b1a1b3c75b0b83f97577869fd85a3cd4fb", - "reference": "cd06d6b1a1b3c75b0b83f97577869fd85a3cd4fb", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/86e4d5a4b036f8f0be1464522f4c6b584c452757", + "reference": "86e4d5a4b036f8f0be1464522f4c6b584c452757", "shasum": "" }, "require": { @@ -3609,9 +3602,9 @@ "description": "PHPDoc parser with support for nullable, intersection and generic types", "support": { "issues": "https://github.com/phpstan/phpdoc-parser/issues", - "source": "https://github.com/phpstan/phpdoc-parser/tree/1.28.0" + "source": "https://github.com/phpstan/phpdoc-parser/tree/1.27.0" }, - "time": "2024-04-03T18:51:33+00:00" + "time": "2024-03-21T13:14:53+00:00" }, { "name": "phpunit/php-code-coverage", From 2391ba07dfb725584dc25c113f4737a029a1a149 Mon Sep 17 00:00:00 2001 From: fogelito Date: Fri, 19 Apr 2024 18:04:54 +0300 Subject: [PATCH 5/7] deleteByGroup --- src/Appwrite/Platform/Workers/Databases.php | 31 +++++++++++---------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/Appwrite/Platform/Workers/Databases.php b/src/Appwrite/Platform/Workers/Databases.php index 0d1ae14890..b305279e7a 100644 --- a/src/Appwrite/Platform/Workers/Databases.php +++ b/src/Appwrite/Platform/Workers/Databases.php @@ -503,6 +503,7 @@ class Databases extends Action * @throws DatabaseException * @throws Restricted * @throws Structure + * @throws Exception */ protected function deleteCollection(Document $database, Document $collection, Document $project, Database $dbForProject): void { @@ -518,20 +519,22 @@ class Databases extends Action /** * Related collections relating to current collection */ - $attributes = $dbForProject->find('attributes', [ - Query::equal('databaseInternalId', [$databaseInternalId]), - Query::equal('type', [Database::VAR_RELATIONSHIP]), - Query::notEqual('collectionInternalId', $collectionInternalId), - Query::contains('options', ['"relatedCollection":"'. $collectionId .'"']), - Query::limit(PHP_INT_MAX) - ]); - - foreach ($attributes as $attribute) { - $dbForProject->deleteDocument('attributes', $attribute->getId()); - Console::success('Deleted document "' . $attribute->getId() . '" related collection successfully'); - $dbForProject->purgeCachedDocument('database_' . $databaseInternalId, $attribute->getAttribute('collectionId')); - $dbForProject->purgeCachedCollection('database_' . $databaseInternalId . '_collection_' . $attribute->getAttribute('collectionInternalId')); - } + $this->deleteByGroup( + 'attributes', + [ + Query::equal('databaseInternalId', [$databaseInternalId]), + Query::equal('type', [Database::VAR_RELATIONSHIP]), + Query::notEqual('collectionInternalId', $collectionInternalId), + Query::contains('options', ['"relatedCollection":"'. $collectionId .'"']), + ], + $dbForProject, + function ($attribute) use ($dbForProject, $databaseInternalId) { + $dbForProject->deleteDocument('attributes', $attribute->getId()); + Console::success('Deleted document "' . $attribute->getId() . '" related collection successfully'); + $dbForProject->purgeCachedDocument('database_' . $databaseInternalId, $attribute->getAttribute('collectionId')); + $dbForProject->purgeCachedCollection('database_' . $databaseInternalId . '_collection_' . $attribute->getAttribute('collectionInternalId')); + } + ); $dbForProject->deleteCollection('database_' . $databaseInternalId . '_collection_' . $collection->getInternalId()); From d5335c4398fc9c32842f07d2e955f9fa86f632b6 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Tue, 23 Apr 2024 15:19:30 +1200 Subject: [PATCH 6/7] Remove redundant delete --- src/Appwrite/Platform/Workers/Databases.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Appwrite/Platform/Workers/Databases.php b/src/Appwrite/Platform/Workers/Databases.php index b305279e7a..6510461eee 100644 --- a/src/Appwrite/Platform/Workers/Databases.php +++ b/src/Appwrite/Platform/Workers/Databases.php @@ -529,8 +529,6 @@ class Databases extends Action ], $dbForProject, function ($attribute) use ($dbForProject, $databaseInternalId) { - $dbForProject->deleteDocument('attributes', $attribute->getId()); - Console::success('Deleted document "' . $attribute->getId() . '" related collection successfully'); $dbForProject->purgeCachedDocument('database_' . $databaseInternalId, $attribute->getAttribute('collectionId')); $dbForProject->purgeCachedCollection('database_' . $databaseInternalId . '_collection_' . $attribute->getAttribute('collectionInternalId')); } From 476074cc5b464cfad6fe6234257f97f0616d3ff9 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Tue, 23 Apr 2024 15:20:25 +1200 Subject: [PATCH 7/7] Add test --- .../e2e/Services/Databases/DatabasesBase.php | 274 +++++++++--------- .../Databases/DatabasesCustomServerTest.php | 114 +++++--- 2 files changed, 204 insertions(+), 184 deletions(-) diff --git a/tests/e2e/Services/Databases/DatabasesBase.php b/tests/e2e/Services/Databases/DatabasesBase.php index 5c1f49399e..a7d36a43c9 100644 --- a/tests/e2e/Services/Databases/DatabasesBase.php +++ b/tests/e2e/Services/Databases/DatabasesBase.php @@ -16,142 +16,6 @@ use Utopia\Validator\JSON; trait DatabasesBase { - /** - * @throws \Utopia\Database\Exception - * @throws \Utopia\Database\Exception\Query - */ - public function testOrQueries(): void - { - // Create database - $database = $this->client->call(Client::METHOD_POST, '/databases', [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-key' => $this->getProject()['apiKey'] - ], [ - 'databaseId' => ID::unique(), - 'name' => 'Or queries' - ]); - - $this->assertNotEmpty($database['body']['$id']); - $this->assertEquals(201, $database['headers']['status-code']); - $this->assertEquals('Or queries', $database['body']['name']); - - $databaseId = $database['body']['$id']; - - // Create Collection - $presidents = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-key' => $this->getProject()['apiKey'] - ]), [ - 'collectionId' => ID::unique(), - 'name' => 'USA Presidents', - 'documentSecurity' => true, - 'permissions' => [ - Permission::create(Role::user($this->getUser()['$id'])), - ], - ]); - - $this->assertEquals(201, $presidents['headers']['status-code']); - $this->assertEquals($presidents['body']['name'], 'USA Presidents'); - - // Create Attributes - $firstName = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $presidents['body']['$id'] . '/attributes/string', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-key' => $this->getProject()['apiKey'] - ]), [ - 'key' => 'first_name', - 'size' => 256, - 'required' => true, - ]); - $this->assertEquals(202, $firstName['headers']['status-code']); - - $lastName = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $presidents['body']['$id'] . '/attributes/string', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-key' => $this->getProject()['apiKey'] - ]), [ - 'key' => 'last_name', - 'size' => 256, - 'required' => true, - ]); - - $this->assertEquals(202, $lastName['headers']['status-code']); - - // Wait for worker - sleep(2); - - $document1 = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $presidents['body']['$id'] . '/documents', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ - 'documentId' => ID::unique(), - 'data' => [ - 'first_name' => 'Donald', - 'last_name' => 'Trump', - ], - 'permissions' => [ - Permission::read(Role::user($this->getUser()['$id'])), - ] - ]); - $this->assertEquals(201, $document1['headers']['status-code']); - - $document2 = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $presidents['body']['$id'] . '/documents', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ - 'documentId' => ID::unique(), - 'data' => [ - 'first_name' => 'George', - 'last_name' => 'Bush', - ], - 'permissions' => [ - Permission::read(Role::user($this->getUser()['$id'])), - ] - ]); - $this->assertEquals(201, $document2['headers']['status-code']); - - $document3 = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $presidents['body']['$id'] . '/documents', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ - 'documentId' => ID::unique(), - 'data' => [ - 'first_name' => 'Joe', - 'last_name' => 'Biden', - ], - 'permissions' => [ - Permission::read(Role::user($this->getUser()['$id'])), - ] - ]); - - $this->assertEquals(201, $document3['headers']['status-code']); - - $documents = $this->client->call( - Client::METHOD_GET, - '/databases/' . $databaseId . '/collections/' . $presidents['body']['$id'] . '/documents', - array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), - [ - 'queries' => [ - Query::select(['first_name', 'last_name'])->toString(), - Query::or([ - Query::equal('first_name', ['Donald']), - Query::equal('last_name', ['Bush']) - ])->toString(), - Query::limit(999)->toString(), - Query::offset(0)->toString() - ], - ] - ); - - $this->assertEquals(200, $documents['headers']['status-code']); - $this->assertCount(2, $documents['body']['documents']); - } - public function testCreateDatabase(): array { /** @@ -4539,7 +4403,7 @@ trait DatabasesBase /** * @depends testOneToManyRelationship */ - public function testSelectsQueries(array $data): void + public function testSelectQueries(array $data): void { $response = $this->client->call(Client::METHOD_GET, '/databases/' . $data['databaseId'] . '/collections/' . $data['personCollection'] . '/documents', array_merge([ 'content-type' => 'application/json', @@ -4584,6 +4448,142 @@ trait DatabasesBase $this->assertArrayNotHasKey('libraries', $response['body']); } + /** + * @throws \Utopia\Database\Exception + * @throws \Utopia\Database\Exception\Query + */ + public function testOrQueries(): void + { + // Create database + $database = $this->client->call(Client::METHOD_POST, '/databases', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ], [ + 'databaseId' => ID::unique(), + 'name' => 'Or queries' + ]); + + $this->assertNotEmpty($database['body']['$id']); + $this->assertEquals(201, $database['headers']['status-code']); + $this->assertEquals('Or queries', $database['body']['name']); + + $databaseId = $database['body']['$id']; + + // Create Collection + $presidents = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'collectionId' => ID::unique(), + 'name' => 'USA Presidents', + 'documentSecurity' => true, + 'permissions' => [ + Permission::create(Role::user($this->getUser()['$id'])), + ], + ]); + + $this->assertEquals(201, $presidents['headers']['status-code']); + $this->assertEquals($presidents['body']['name'], 'USA Presidents'); + + // Create Attributes + $firstName = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $presidents['body']['$id'] . '/attributes/string', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'first_name', + 'size' => 256, + 'required' => true, + ]); + $this->assertEquals(202, $firstName['headers']['status-code']); + + $lastName = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $presidents['body']['$id'] . '/attributes/string', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'last_name', + 'size' => 256, + 'required' => true, + ]); + + $this->assertEquals(202, $lastName['headers']['status-code']); + + // Wait for worker + sleep(2); + + $document1 = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $presidents['body']['$id'] . '/documents', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'documentId' => ID::unique(), + 'data' => [ + 'first_name' => 'Donald', + 'last_name' => 'Trump', + ], + 'permissions' => [ + Permission::read(Role::user($this->getUser()['$id'])), + ] + ]); + $this->assertEquals(201, $document1['headers']['status-code']); + + $document2 = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $presidents['body']['$id'] . '/documents', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'documentId' => ID::unique(), + 'data' => [ + 'first_name' => 'George', + 'last_name' => 'Bush', + ], + 'permissions' => [ + Permission::read(Role::user($this->getUser()['$id'])), + ] + ]); + $this->assertEquals(201, $document2['headers']['status-code']); + + $document3 = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $presidents['body']['$id'] . '/documents', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'documentId' => ID::unique(), + 'data' => [ + 'first_name' => 'Joe', + 'last_name' => 'Biden', + ], + 'permissions' => [ + Permission::read(Role::user($this->getUser()['$id'])), + ] + ]); + + $this->assertEquals(201, $document3['headers']['status-code']); + + $documents = $this->client->call( + Client::METHOD_GET, + '/databases/' . $databaseId . '/collections/' . $presidents['body']['$id'] . '/documents', + array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), + [ + 'queries' => [ + Query::select(['first_name', 'last_name'])->toString(), + Query::or([ + Query::equal('first_name', ['Donald']), + Query::equal('last_name', ['Bush']) + ])->toString(), + Query::limit(999)->toString(), + Query::offset(0)->toString() + ], + ] + ); + + $this->assertEquals(200, $documents['headers']['status-code']); + $this->assertCount(2, $documents['body']['documents']); + } + /** * @depends testCreateDatabase * @param array $data diff --git a/tests/e2e/Services/Databases/DatabasesCustomServerTest.php b/tests/e2e/Services/Databases/DatabasesCustomServerTest.php index 7ba6dbd189..70bbedcb38 100644 --- a/tests/e2e/Services/Databases/DatabasesCustomServerTest.php +++ b/tests/e2e/Services/Databases/DatabasesCustomServerTest.php @@ -7,7 +7,9 @@ use Tests\E2E\Client; use Tests\E2E\Scopes\ProjectCustom; use Tests\E2E\Scopes\Scope; use Tests\E2E\Scopes\SideServer; +use Utopia\Database\Database; use Utopia\Database\Document; +use Utopia\Database\Exception; use Utopia\Database\Helpers\ID; use Utopia\Database\Helpers\Permission; use Utopia\Database\Helpers\Role; @@ -1227,59 +1229,77 @@ class DatabasesCustomServerTest extends Scope $this->assertEquals(404, $response['headers']['status-code']); } - // Adds several minutes to test to replicate coverage in Utopia\Database unit tests - // and messes with subsequent tests as DatabaseV1 queue gets overwhelmed - // TODO@kodumbeats either fix or remove testAttributeCountLimit - // Options to fix: - // - Enable attribute creation in batches - // - Use additional database workers - // - Wait for worker to complete before moving onto next test - // - Remove since this is unit tested in Utopia\Database - // - // public function testAttributeCountLimit() - // { - // $collection = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections', array_merge([ - // 'content-type' => 'application/json', - // 'x-appwrite-project' => $this->getProject()['$id'], - // 'x-appwrite-key' => $this->getProject()['apiKey'] - // ]), [ - // 'collectionId' => ID::unique(), - // 'name' => 'attributeCountLimit', - // 'read' => ['any'], - // 'write' => ['any'], - // 'documentSecurity' => true, - // ]); + /** + * @throws Exception + */ + public function testDeleteCollectionDeletesRelatedAttributes(): void + { + $database = $this->client->call(Client::METHOD_POST, '/databases', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'databaseId' => ID::unique(), + 'name' => 'TestDeleteCollectionDeletesRelatedAttributes', + ]); - // $collectionId = $collection['body']['$id']; + $databaseId = $database['body']['$id']; - // // load the collection up to the limit - // for ($i=0; $i < 1012; $i++) { - // $attribute = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/integer', array_merge([ - // 'content-type' => 'application/json', - // 'x-appwrite-project' => $this->getProject()['$id'], - // 'x-appwrite-key' => $this->getProject()['apiKey'] - // ]), [ - // 'key' => "attribute{$i}", - // 'required' => false, - // ]); + $collection1 = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'collectionId' => ID::unique(), + 'name' => 'Collection1', + 'documentSecurity' => false, + 'permissions' => [], + ]); - // $this->assertEquals(201, $attribute['headers']['status-code']); - // } + $collection2 = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'collectionId' => ID::unique(), + 'name' => 'Collection2', + 'documentSecurity' => false, + 'permissions' => [], + ]); - // sleep(30); + $collection1 = $collection1['body']['$id']; + $collection2 = $collection2['body']['$id']; - // $tooMany = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes/integer', array_merge([ - // 'content-type' => 'application/json', - // 'x-appwrite-project' => $this->getProject()['$id'], - // 'x-appwrite-key' => $this->getProject()['apiKey'] - // ]), [ - // 'key' => "tooMany", - // 'required' => false, - // ]); + $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collection1 . '/attributes/relationship', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ]), [ + 'relatedCollectionId' => $collection2, + 'type' => Database::RELATION_MANY_TO_ONE, + 'twoWay' => false, + 'key' => 'collection2' + ]); - // $this->assertEquals(400, $tooMany['headers']['status-code']); - // $this->assertEquals('Attribute limit exceeded', $tooMany['body']['message']); - // } + sleep(2); + + $this->client->call(Client::METHOD_DELETE, '/databases/' . $databaseId . '/collections/' . $collection2, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ], $this->getHeaders())); + + sleep(2); + + $attributes = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $collection1 . '/attributes', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ], $this->getHeaders())); + + \var_dump($attributes['body']); + + $this->assertEquals(0, $attributes['body']['total']); + } public function testAttributeRowWidthLimit() {