mirror of
https://github.com/appwrite/appwrite.git
synced 2026-11-18 20:36:03 +00:00
Merge pull request #12593 from appwrite/fix/collection-create-orphan-on-unready-db
Resolve data-plane database before writing collection metadata
This commit is contained in:
2 files changed
+16
-7
No files matched your search
@@ -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();
|
||||
|
||||
|
||||
@@ -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 = [];
|
||||
|
||||
Reference in new issue
Block a user