mirror of
https://github.com/appwrite/appwrite.git
synced 2026-11-18 20:36:03 +00:00
Merge pull request #13454 from appwrite/fix/atomic-bucket-create
fix(storage): remove the bucket document when its files collection cannot be created
This commit is contained in:
1 file changed
+10
-1
@@ -153,7 +153,16 @@ class Create extends Action
|
||||
|
||||
$bucket = $dbForProject->getDocument('buckets', $bucketId);
|
||||
|
||||
$dbForProject->createCollection('bucket_' . $bucket->getSequence(), $attributes, $indexes, permissions: $permissions, documentSecurity: $fileSecurity);
|
||||
// The files collection is DDL and cannot share a transaction with the
|
||||
// document insert above, and its name needs the document's sequence,
|
||||
// so the document is committed first. A bucket without its collection
|
||||
// can never hold a file: remove it rather than leave an orphan.
|
||||
try {
|
||||
$dbForProject->createCollection('bucket_' . $bucket->getSequence(), $attributes, $indexes, permissions: $permissions, documentSecurity: $fileSecurity);
|
||||
} catch (\Throwable $th) {
|
||||
$dbForProject->deleteDocument('buckets', $bucketId);
|
||||
throw $th;
|
||||
}
|
||||
} catch (DuplicateException) {
|
||||
throw new Exception(Exception::STORAGE_BUCKET_ALREADY_EXISTS);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user