Fix project deletes for shared tables
This commit is contained in:
parent
6b31f1323d
commit
d0e258854c
12
composer.lock
generated
12
composer.lock
generated
|
@ -1556,16 +1556,16 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "utopia-php/database",
|
"name": "utopia-php/database",
|
||||||
"version": "0.49.7",
|
"version": "0.49.8",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/utopia-php/database.git",
|
"url": "https://github.com/utopia-php/database.git",
|
||||||
"reference": "69b9cb52cc81a7f606ea7586f6c0af3394cc3601"
|
"reference": "4fb1f6d216f6f628dd5b013e1f539ae2191228b1"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/utopia-php/database/zipball/69b9cb52cc81a7f606ea7586f6c0af3394cc3601",
|
"url": "https://api.github.com/repos/utopia-php/database/zipball/4fb1f6d216f6f628dd5b013e1f539ae2191228b1",
|
||||||
"reference": "69b9cb52cc81a7f606ea7586f6c0af3394cc3601",
|
"reference": "4fb1f6d216f6f628dd5b013e1f539ae2191228b1",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
|
@ -1606,9 +1606,9 @@
|
||||||
],
|
],
|
||||||
"support": {
|
"support": {
|
||||||
"issues": "https://github.com/utopia-php/database/issues",
|
"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",
|
"name": "utopia-php/domains",
|
||||||
|
|
|
@ -12,6 +12,7 @@ use Utopia\Audit\Audit;
|
||||||
use Utopia\Cache\Adapter\Filesystem;
|
use Utopia\Cache\Adapter\Filesystem;
|
||||||
use Utopia\Cache\Cache;
|
use Utopia\Cache\Cache;
|
||||||
use Utopia\CLI\Console;
|
use Utopia\CLI\Console;
|
||||||
|
use Utopia\Config\Config;
|
||||||
use Utopia\Database\Database;
|
use Utopia\Database\Database;
|
||||||
use Utopia\Database\DateTime;
|
use Utopia\Database\DateTime;
|
||||||
use Utopia\Database\Document;
|
use Utopia\Database\Document;
|
||||||
|
@ -21,6 +22,7 @@ use Utopia\Database\Exception\Conflict;
|
||||||
use Utopia\Database\Exception\Restricted;
|
use Utopia\Database\Exception\Restricted;
|
||||||
use Utopia\Database\Exception\Structure;
|
use Utopia\Database\Exception\Structure;
|
||||||
use Utopia\Database\Query;
|
use Utopia\Database\Query;
|
||||||
|
use Utopia\DSN\DSN;
|
||||||
use Utopia\Logger\Log;
|
use Utopia\Logger\Log;
|
||||||
use Utopia\Platform\Action;
|
use Utopia\Platform\Action;
|
||||||
use Utopia\Queue\Message;
|
use Utopia\Queue\Message;
|
||||||
|
@ -476,18 +478,38 @@ class Deletes extends Action
|
||||||
$projectId = $document->getId();
|
$projectId = $document->getId();
|
||||||
$projectInternalId = $document->getInternalId();
|
$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);
|
$dbForProject = $getProjectDB($document);
|
||||||
|
$projectCollectionIds = \array_keys(Config::getParam('collections', [])['projects']);
|
||||||
|
$limit = \count($projectCollectionIds) + 25;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
$collections = $dbForProject->listCollections();
|
$collections = $dbForProject->listCollections($limit);
|
||||||
|
|
||||||
if (empty($collections)) {
|
if ($dsn->getHost() === DATABASE_SHARED_TABLES) {
|
||||||
break;
|
$collectionsIds = \array_map(fn ($collection) => $collection->getId(), $collections);
|
||||||
|
|
||||||
|
if ($collectionsIds == $projectCollectionIds) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (empty($collections)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($collections as $collection) {
|
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]),
|
Query::equal('projectInternalId', [$projectInternalId]),
|
||||||
], $dbForConsole);
|
], $dbForConsole);
|
||||||
|
|
||||||
// Delete VCS commments
|
// Delete VCS comments
|
||||||
$this->deleteByGroup('vcsComments', [
|
$this->deleteByGroup('vcsComments', [
|
||||||
Query::equal('projectInternalId', [$projectInternalId]),
|
Query::equal('projectInternalId', [$projectInternalId]),
|
||||||
], $dbForConsole);
|
], $dbForConsole);
|
||||||
|
|
||||||
// Delete metadata tables
|
// Delete metadata table
|
||||||
try {
|
if ($dsn->getHost() !== DATABASE_SHARED_TABLES) {
|
||||||
$dbForProject->deleteCollection('_metadata');
|
$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
|
// Delete all storage directories
|
||||||
|
|
Loading…
Reference in a new issue