Skip to content

Commit b6c7176

Browse files
committed
fix: prevent metadata table from being dropped during orphan reconciliation
When createCollection is called for the _metadata table and the table already exists, the orphan reconciliation code would drop and recreate it, destroying all collection metadata. This breaks upgrades where Database::create() is called on an existing database. The fix adds _metadata to the safe list alongside shared-tables checks, ensuring the metadata table is never treated as an orphan.
1 parent f121418 commit b6c7176

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

src/Database/Database.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1796,8 +1796,10 @@ public function createCollection(string $id, array $attributes = [], array $inde
17961796
$this->adapter->createCollection($id, $attributes, $indexes);
17971797
$createdPhysicalTable = true;
17981798
} catch (DuplicateException $e) {
1799-
if ($this->adapter->getSharedTables()
1800-
&& ($id === self::METADATA || $this->adapter->exists($this->adapter->getDatabase(), $id))) {
1799+
if ($id === self::METADATA
1800+
|| ($this->adapter->getSharedTables()
1801+
&& $this->adapter->exists($this->adapter->getDatabase(), $id))) {
1802+
// The metadata table must never be dropped during reconciliation.
18011803
// In shared-tables mode the physical table is reused across
18021804
// tenants. A DuplicateException simply means the table already
18031805
// exists for another tenant — not an orphan.

0 commit comments

Comments
 (0)