fix: resolve data-plane database before writing collection metadata

For a dedicated product database (documentsdb/vectorsdb on Cloud), the
data-plane resolver throws while the database is still provisioning (the
DSN is not published yet). Both collection create paths wrote the
control-plane metadata row before resolving the data plane, so every
create attempted against a provisioning database returned 409 but still
persisted a collection row with no backing collection. The orphan lists
fine in the API and console, but every document operation against it
fails with 'Invalid document structure: Missing collection attribute
$collection'.

Resolve the data-plane database first so a provisioning (or otherwise
unreachable) backend rejects the request before any metadata is written.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Jake BarnbyandClaude Fable 5 committed 2026-06-12 23:22:02 +12:00
1 parent cf9cd86a6a
commit 5f23b0e804
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 = [];