diff --git a/composer.lock b/composer.lock index 0af5c0cdf..76f51b75c 100644 --- a/composer.lock +++ b/composer.lock @@ -1556,16 +1556,16 @@ }, { "name": "utopia-php/database", - "version": "0.49.7", + "version": "0.49.8", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "69b9cb52cc81a7f606ea7586f6c0af3394cc3601" + "reference": "4fb1f6d216f6f628dd5b013e1f539ae2191228b1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/69b9cb52cc81a7f606ea7586f6c0af3394cc3601", - "reference": "69b9cb52cc81a7f606ea7586f6c0af3394cc3601", + "url": "https://api.github.com/repos/utopia-php/database/zipball/4fb1f6d216f6f628dd5b013e1f539ae2191228b1", + "reference": "4fb1f6d216f6f628dd5b013e1f539ae2191228b1", "shasum": "" }, "require": { @@ -1606,9 +1606,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/0.49.7" + "source": "https://github.com/utopia-php/database/tree/0.49.8" }, - "time": "2024-05-08T09:04:08+00:00" + "time": "2024-05-09T04:43:05+00:00" }, { "name": "utopia-php/domains", diff --git a/src/Appwrite/Platform/Workers/Deletes.php b/src/Appwrite/Platform/Workers/Deletes.php index 189ef6496..b08bfb027 100644 --- a/src/Appwrite/Platform/Workers/Deletes.php +++ b/src/Appwrite/Platform/Workers/Deletes.php @@ -12,6 +12,7 @@ use Utopia\Audit\Audit; use Utopia\Cache\Adapter\Filesystem; use Utopia\Cache\Cache; use Utopia\CLI\Console; +use Utopia\Config\Config; use Utopia\Database\Database; use Utopia\Database\DateTime; use Utopia\Database\Document; @@ -21,6 +22,7 @@ use Utopia\Database\Exception\Conflict; use Utopia\Database\Exception\Restricted; use Utopia\Database\Exception\Structure; use Utopia\Database\Query; +use Utopia\DSN\DSN; use Utopia\Logger\Log; use Utopia\Platform\Action; use Utopia\Queue\Message; @@ -476,18 +478,38 @@ class Deletes extends Action $projectId = $document->getId(); $projectInternalId = $document->getInternalId(); - // Delete project tables + try { + $dsn = new DSN($document->getAttribute('database', 'console')); + } catch (\InvalidArgumentException) { + // TODO: Temporary until all projects are using shared tables + $dsn = new DSN('mysql://' . $document->getAttribute('database', 'console')); + } + $dbForProject = $getProjectDB($document); + $projectCollectionIds = \array_keys(Config::getParam('collections', [])['projects']); + $limit = \count($projectCollectionIds) + 25; while (true) { - $collections = $dbForProject->listCollections(); + $collections = $dbForProject->listCollections($limit); - if (empty($collections)) { - break; + if ($dsn->getHost() === DATABASE_SHARED_TABLES) { + $collectionsIds = \array_map(fn ($collection) => $collection->getId(), $collections); + + if ($collectionsIds == $projectCollectionIds) { + break; + } + } else { + if (empty($collections)) { + break; + } } foreach ($collections as $collection) { - $dbForProject->deleteCollection($collection->getId()); + if ($dsn->getHost() !== DATABASE_SHARED_TABLES || !\in_array($collection->getId(), $projectCollectionIds)) { + $dbForProject->deleteCollection($collection->getId()); + } else { + $this->deleteByGroup($collection->getId(), [], database: $dbForProject); + } } } @@ -523,17 +545,14 @@ class Deletes extends Action Query::equal('projectInternalId', [$projectInternalId]), ], $dbForConsole); - // Delete VCS commments + // Delete VCS comments $this->deleteByGroup('vcsComments', [ Query::equal('projectInternalId', [$projectInternalId]), ], $dbForConsole); - // Delete metadata tables - try { + // Delete metadata table + if ($dsn->getHost() !== DATABASE_SHARED_TABLES) { $dbForProject->deleteCollection('_metadata'); - } catch (\Throwable) { - // Ignore: deleteCollection tries to delete a metadata entry after the collection is deleted, - // which will throw an exception here because the metadata collection is already deleted. } // Delete all storage directories