diff --git a/app/config/collections.php b/app/config/collections.php index dcf944094b..7e30fa95f6 100644 --- a/app/config/collections.php +++ b/app/config/collections.php @@ -507,7 +507,7 @@ $collections = [ '$id' => 'database', 'type' => Database::VAR_STRING, 'format' => '', - 'size' => 16384, + 'size' => 256, 'signed' => true, 'required' => true, 'default' => null, diff --git a/app/config/variables.php b/app/config/variables.php index a8f3f887e5..335c46f358 100644 --- a/app/config/variables.php +++ b/app/config/variables.php @@ -290,8 +290,8 @@ return [ ], [ 'name' => '_APP_PROJECT_DB', - 'description' => 'A list of comma separated key value pairs for Project DBs where key is the database name and value is the DSN connection string.', - 'introduction' => '', + 'description' => 'A list of comma separated key value pairs for Project DBs where key is the database name and value is the DSN connection string. Example: db_fra1_01=mysql://user:password@112.145.123.1:3306/appwrite, db_fra1_02=mysql://user:password@112.145.123.5:3306/appwrite', + 'introduction' => '0.16.0', 'default' => 'db_fra1_02=mysql://user:password@mariadb:3306/appwrite', 'required' => true, 'question' => '', @@ -299,8 +299,8 @@ return [ ], [ 'name' => '_APP_CONSOLE_DB', - 'introduction' => '', - 'description' => 'A key value pair representing the console DB where key is the database name and value is the DSN connection string.', + 'introduction' => '0.16.0', + 'description' => 'A key value pair representing the console DB where key is the database name and value is the DSN connection string. Example: db_fra1_01=mysql://user:password@112.145.123.1:3306/appwrite', 'default' => 'db_fra1_01=mysql://user:password@mariadb:3306/appwrite', 'required' => true, 'question' => '', diff --git a/app/http.php b/app/http.php index a6d69c506f..945a0a9bf5 100644 --- a/app/http.php +++ b/app/http.php @@ -63,34 +63,34 @@ $http->on('start', function (Server $http) use ($payloadSize, $register) { App::setResource('cache', fn() => $redis); $dbPool = $register->get('dbPool'); - [$database, $returnDatabase] = $dbPool->getDBFromPool('console', $redis); - App::setResource('dbForConsole', fn() => $database); + [$dbForConsole, $returnDatabase] = $dbPool->getDBFromPool('console', $redis); + App::setResource('dbForConsole', fn() => $dbForConsole); Console::success('[Setup] - Server database init started...'); $collections = Config::getParam('collections', []); /** @var array $collections */ - if (!$database->exists(App::getEnv('_APP_DB_SCHEMA', 'appwrite'))) { + if (!$dbForConsole->exists(App::getEnv('_APP_DB_SCHEMA', 'appwrite'))) { $redis->flushAll(); Console::success('[Setup] - Creating database: appwrite...'); - $database->create(App::getEnv('_APP_DB_SCHEMA', 'appwrite')); + $dbForConsole->create(App::getEnv('_APP_DB_SCHEMA', 'appwrite')); } try { Console::success('[Setup] - Creating metadata table: appwrite...'); - $database->createMetadata(); + $dbForConsole->createMetadata(); } catch (\Throwable $th) { Console::success('[Setup] - Skip: metadata table already exists'); } - if ($database->getCollection(Audit::COLLECTION)->isEmpty()) { - $audit = new Audit($database); + if ($dbForConsole->getCollection(Audit::COLLECTION)->isEmpty()) { + $audit = new Audit($dbForConsole); $audit->setup(); } - if ($database->getCollection(TimeLimit::COLLECTION)->isEmpty()) { - $adapter = new TimeLimit("", 0, 1, $database); + if ($dbForConsole->getCollection(TimeLimit::COLLECTION)->isEmpty()) { + $adapter = new TimeLimit("", 0, 1, $dbForConsole); $adapter->setup(); } @@ -98,9 +98,17 @@ $http->on('start', function (Server $http) use ($payloadSize, $register) { if (($collection['$collection'] ?? '') !== Database::METADATA) { continue; } - if (!$database->getCollection($key)->isEmpty()) { + if (!$dbForConsole->getCollection($key)->isEmpty()) { continue; } + + /** + * Skip to prevent 0.15 migration issues. + */ + if ($key === 'databases' && $dbForConsole->exists(App::getEnv('_APP_DB_SCHEMA', 'appwrite'), 'collections')) { + continue; + } + Console::success('[Setup] - Creating collection: ' . $collection['$id'] . '...'); $attributes = []; @@ -130,12 +138,12 @@ $http->on('start', function (Server $http) use ($payloadSize, $register) { ]); } - $database->createCollection($key, $attributes, $indexes); + $dbForConsole->createCollection($key, $attributes, $indexes); } - if ($database->getDocument('buckets', 'default')->isEmpty()) { + if ($dbForConsole->getDocument('buckets', 'default')->isEmpty()) { Console::success('[Setup] - Creating default bucket...'); - $database->createDocument('buckets', new Document([ + $dbForConsole->createDocument('buckets', new Document([ '$id' => 'default', '$collection' => 'buckets', 'name' => 'Default', @@ -150,7 +158,7 @@ $http->on('start', function (Server $http) use ($payloadSize, $register) { 'search' => 'buckets Default', ])); - $bucket = $database->getDocument('buckets', 'default'); + $bucket = $dbForConsole->getDocument('buckets', 'default'); Console::success('[Setup] - Creating files collection for default bucket...'); $files = $collections['files'] ?? []; @@ -185,7 +193,7 @@ $http->on('start', function (Server $http) use ($payloadSize, $register) { ]); } - $database->createCollection('bucket_' . $bucket->getInternalId(), $attributes, $indexes); + $dbForConsole->createCollection('bucket_' . $bucket->getInternalId(), $attributes, $indexes); } call_user_func($returnDatabase);