Create metadata document from outside if duplicate on shared tables V1

This commit is contained in:
Jake Barnby 2024-10-21 22:43:47 +13:00
parent 5fcb990b1c
commit d979c0c914
No known key found for this signature in database
GPG key ID: C437A8CC85B96E9C
2 changed files with 16 additions and 2 deletions

View file

@ -234,7 +234,21 @@ App::post('/v1/projects')
$attributes = \array_map(fn ($attribute) => new Document($attribute), $collection['attributes']);
$indexes = \array_map(fn (array $index) => new Document($index), $collection['indexes']);
$dbForProject->createCollection($key, $attributes, $indexes);
try {
$dbForProject->createCollection($key, $attributes, $indexes);
} catch (Duplicate) {
if (!$globalCollections) {
$dbForProject->createDocument(Database::METADATA, new Document([
'$id' => ID::custom($key),
'$permissions' => [Permission::create(Role::any())],
'name' => $key,
'attributes' => $attributes,
'indexes' => $indexes,
'documentSecurity' => true
]));
}
}
}
}

2
composer.lock generated
View file

@ -7038,5 +7038,5 @@
"platform-overrides": {
"php": "8.3"
},
"plugin-api-version": "2.3.0"
"plugin-api-version": "2.6.0"
}