From 58470bfa7f9ad7a1c73f97bfc5e2bd695e0ecc2b Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Wed, 17 Dec 2025 18:36:23 +1300 Subject: [PATCH] Update upgrade/install flows --- src/Appwrite/Platform/Tasks/Install.php | 8 ++++++ src/Appwrite/Platform/Tasks/Upgrade.php | 33 ++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Tasks/Install.php b/src/Appwrite/Platform/Tasks/Install.php index 427575e363..a61942831c 100644 --- a/src/Appwrite/Platform/Tasks/Install.php +++ b/src/Appwrite/Platform/Tasks/Install.php @@ -137,6 +137,14 @@ class Install extends Action } } } + + // Block database type changes on existing installations + $existingDatabase = $vars['_APP_DB_ADAPTER']['default'] ?? null; + if ($existingDatabase !== null && $existingDatabase !== $database) { + Console::error("Cannot change database type from '{$existingDatabase}' to '{$database}'."); + Console::error('Changing database types on an existing installation is not supported.'); + Console::exit(1); + } } if (empty($httpPort)) { diff --git a/src/Appwrite/Platform/Tasks/Upgrade.php b/src/Appwrite/Platform/Tasks/Upgrade.php index a9f8a2a53e..4eb5a6be0c 100644 --- a/src/Appwrite/Platform/Tasks/Upgrade.php +++ b/src/Appwrite/Platform/Tasks/Upgrade.php @@ -2,6 +2,8 @@ namespace Appwrite\Platform\Tasks; +use Appwrite\Docker\Compose; +use Appwrite\Docker\Env; use Utopia\CLI\Console; use Utopia\System\System; use Utopia\Validator\Boolean; @@ -41,7 +43,36 @@ class Upgrade extends Install Console::log(' └── docker-compose.yml'); Console::exit(1); } - $database = System::getEnv('_APP_DB_ADAPTER', 'mariadb'); + + // Extract existing database adapter from docker-compose.yml + $database = null; + $compose = new Compose($data); + foreach ($compose->getServices() as $service) { + if (!$service) { + continue; + } + $env = $service->getEnvironment()->list(); + if (isset($env['_APP_DB_ADAPTER'])) { + $database = $env['_APP_DB_ADAPTER']; + break; + } + } + + // Fallback to .env file if not found in compose + if ($database === null) { + $envData = @file_get_contents($this->path . '/.env'); + if ($envData !== false) { + $envFile = new Env($envData); + $database = $envFile->list()['_APP_DB_ADAPTER'] ?? null; + } + } + + // Final fallback to environment variable or default + if ($database === null) { + // TODO: Change default to 'mongodb' after next release + $database = System::getEnv('_APP_DB_ADAPTER', 'mariadb'); + } + parent::action($httpPort, $httpsPort, $organization, $image, $interactive, $noStart, $database); } }