Skip to content

Commit 8fdc871

Browse files
committed
Improve v1 hack quality
1 parent dfda0e1 commit 8fdc871

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

src/Database/Adapter/MariaDB.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,9 +331,13 @@ public function deleteCollection(string $id): bool
331331

332332
$sql = $this->trigger(Database::EVENT_COLLECTION_DELETE, $sql);
333333

334-
return $this->getPDO()
335-
->prepare($sql)
336-
->execute();
334+
try {
335+
return $this->getPDO()
336+
->prepare($sql)
337+
->execute();
338+
} catch (PDOException $e) {
339+
throw $this->processException($e);
340+
}
337341
}
338342

339343
/**

src/Database/Database.php

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Utopia\Database;
44

55
use Exception;
6-
use PDOException;
76
use Utopia\Cache\Cache;
87
use Utopia\CLI\Console;
98
use Utopia\Database\Exception as DatabaseException;
@@ -1435,20 +1434,16 @@ public function deleteCollection(string $id): bool
14351434
fn ($attribute) => $attribute->getAttribute('type') === Database::VAR_RELATIONSHIP
14361435
);
14371436

1437+
foreach ($relationships as $relationship) {
1438+
$this->deleteRelationship($collection->getId(), $relationship->getId());
1439+
}
14381440

14391441
try {
1440-
foreach ($relationships as $relationship) {
1441-
$this->deleteRelationship($collection->getId(), $relationship->getId());
1442-
}
1443-
14441442
$this->adapter->deleteCollection($id);
1445-
} catch (PDOException $e) {
1443+
} catch (NotFoundException $e) {
14461444
// HACK: Metadata should still be updated, can be removed when null tenant collections are supported.
1447-
// "42S02" is "Base table or view not found": https://learn.microsoft.com/en-us/sql/odbc/reference/appendixes/appendix-a-odbc-error-codes?view=sql-server-ver16
1448-
if ($e->getCode() === '42S02') {
1449-
if (!$this->adapter->getSharedTables() || !$this->isMigrating()) {
1450-
throw $e;
1451-
}
1445+
if (!$this->adapter->getSharedTables() || !$this->isMigrating()) {
1446+
throw $e;
14521447
}
14531448
}
14541449

0 commit comments

Comments
 (0)