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 72e138be44..040057f580 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Create.php @@ -112,7 +112,9 @@ class Create extends Action } catch (NotFoundException) { throw new Exception(Exception::DATABASE_NOT_FOUND); } - + /** + * @var Database $dbForDatabases + */ $dbForDatabases = $getDatabasesDB($database); try { $dbForDatabases->createCollection( diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Create.php index 6078e2d7d8..29324f2684 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Create.php @@ -4,6 +4,7 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases; use Appwrite\Event\Event; use Appwrite\Extend\Exception; +use Appwrite\Platform\Modules\Databases\Services\Registry\TablesDB; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; use Appwrite\SDK\Deprecated; @@ -76,11 +77,12 @@ class Create extends Action ->inject('project') ->inject('response') ->inject('dbForProject') + ->inject('getDatabasesDB') ->inject('queueForEvents') ->callback($this->action(...)); } - public function action(string $databaseId, string $name, bool $enabled, Document $project, UtopiaResponse $response, Database $dbForProject, Event $queueForEvents): void + public function action(string $databaseId, string $name, bool $enabled, Document $project, UtopiaResponse $response, Database $dbForProject, callable $getDatabasesDB, Event $queueForEvents): void { $databaseId = $databaseId == 'unique()' ? ID::unique() : $databaseId; @@ -118,6 +120,12 @@ class Create extends Action try { $dbForProject->createCollection('database_' . $database->getSequence(), $attributes, $indexes); + $dbFordatabases = $getDatabasesDB($database); + // legacy and tablesdb are created on the same project database + // need to check for multitype databases + if ($this->getDatabaseType() !== TABLESDB && $this->getDatabaseType() !== 'legacy') { + $dbFordatabases->create(); + } } catch (DuplicateException) { throw new Exception(Exception::DATABASE_ALREADY_EXISTS); } catch (IndexException) { diff --git a/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Create.php index 2802c21dce..08715d253a 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/DocumentsDB/Create.php @@ -52,6 +52,7 @@ class Create extends DatabaseCreate ->inject('project') ->inject('response') ->inject('dbForProject') + ->inject('getDatabasesDB') ->inject('queueForEvents') ->callback($this->action(...)); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Create.php index c2fc861811..eb78ec27e1 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Create.php @@ -53,6 +53,7 @@ class Create extends DatabaseCreate ->inject('project') ->inject('response') ->inject('dbForProject') + ->inject('getDatabasesDB') ->inject('queueForEvents') ->callback($this->action(...)); }