diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Create.php index a0ee24db87..b2e783bccd 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Create.php @@ -103,6 +103,15 @@ class Create extends Action // Map aggregate permissions into the multiple permissions they represent. $permissions = Permission::aggregate($permissions) ?? []; + // Resolve the data-plane database BEFORE writing the metadata row. For a + // dedicated product database this throws while provisioning (no DSN yet); + // writing the row first would leave an orphaned collection with no backing + // collection, which lists fine but fails every document operation. + /** + * @var Database $dbForDatabases + */ + $dbForDatabases = $getDatabasesDB($database); + try { $collection = $dbForProject->createDocument('database_' . $database->getSequence(), new Document([ '$id' => $collectionId, @@ -122,11 +131,6 @@ class Create extends Action throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } - /** - * @var Database $dbForDatabases - */ - $dbForDatabases = $getDatabasesDB($database); - $collectionKey = 'database_' . $database->getSequence() . '_collection_' . $collection->getSequence(); $databaseKey = 'database_' . $database->getSequence(); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Create.php index 58433c7deb..3b346bb7c0 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Create.php @@ -94,6 +94,13 @@ class Create extends CollectionAction // Map aggregate permissions into the multiple permissions they represent. $permissions = Permission::aggregate($permissions) ?? []; + // Resolve the data-plane database BEFORE writing the metadata row. For a + // dedicated product database this throws while provisioning (no DSN yet); + // writing the row first would leave an orphaned collection with no backing + // collection, which lists fine but fails every document operation. + /** @var Database $dbForDatabases */ + $dbForDatabases = $getDatabasesDB($database); + try { $collection = $dbForProject->createDocument('database_' . $database->getSequence(), new Document([ '$id' => $collectionId, @@ -114,8 +121,6 @@ class Create extends CollectionAction } catch (NotFoundException) { throw new Exception(Exception::DATABASE_NOT_FOUND); } - /** @var Database $dbForDatabases */ - $dbForDatabases = $getDatabasesDB($database); $attributes = []; $indexes = [];