Refine installer database selection

This commit is contained in:
Chirag Aggarwal committed 2026-07-13 11:46:13 +05:30
1 parent 2a886e8b49
commit 867868a4b3
11 files changed
+106 -35

No files matched your search

+3 -3
View File
@@ -380,15 +380,15 @@ return [
],
[
'category' => 'Database',
'description' => 'Appwrite uses a database for storing user and meta data. You can choose between MariaDB, MongoDB or PostgreSQL.',
'description' => 'Appwrite uses a database for storing user and meta data. You can choose between PostgreSQL, MariaDB or MongoDB.',
'variables' => [
[
'name' => '_APP_DB_ADAPTER',
'description' => 'Which database to use. Must be one of: MariaDB, MongoDB, or PostgreSQL',
'description' => 'Which database to use. Must be one of: PostgreSQL, MariaDB, or MongoDB',
'introduction' => '1.9.0',
'default' => 'postgresql',
'required' => true,
'question' => 'Choose your database (mariadb|mongodb|postgresql)',
'question' => 'Choose your database (postgresql|mariadb|mongodb)',
'filter' => ''
],
[
+1 -2
View File
@@ -8,8 +8,7 @@ $defaultAppDomain = $vars['_APP_DOMAIN']['default'] ?? 'localhost';
$defaultAppDomain = ($defaultAppDomain === 'traefik') ? 'localhost' : $defaultAppDomain;
$defaultEmailCertificates ??= '';
$defaultDatabase = $vars['_APP_DB_ADAPTER']['default'] ?? 'postgresql';
$lockedDatabase = $isUpgrade && empty($lockedDatabase) ? $defaultDatabase : $lockedDatabase;
$enabledDatabases ??= ['mongodb', 'mariadb', 'postgresql'];
$enabledDatabases ??= ['postgresql', 'mariadb', 'mongodb'];
$isLocalInstall ??= false;
@@ -4,8 +4,8 @@
const getLockedDatabase = () => getBodyDataset().lockedDatabase || '';
const getEnabledDatabases = () => {
const raw = getBodyDataset().enabledDatabases;
if (!raw) return ['mongodb', 'mariadb', 'postgresql'];
try { return JSON.parse(raw); } catch (e) { return ['mongodb', 'mariadb', 'postgresql']; }
if (!raw) return ['postgresql', 'mariadb', 'mongodb'];
try { return JSON.parse(raw); } catch (e) { return ['postgresql', 'mariadb', 'mongodb']; }
};
const STEP_IDS = Object.freeze({
@@ -7,7 +7,7 @@ $defaultHttpsPort ??= '443';
$defaultEmailCertificates ??= '';
$defaultAssistantOpenAIKey ??= '';
$defaultDatabase ??= 'postgresql';
$enabledDatabases ??= ['mongodb', 'mariadb', 'postgresql'];
$enabledDatabases ??= ['postgresql', 'mariadb', 'mongodb'];
$selectedDatabase = $lockedDatabase ?: $defaultDatabase;
$isDatabaseLocked = !empty($lockedDatabase);
$mongoEnabled = in_array('mongodb', $enabledDatabases, true);
@@ -47,15 +47,15 @@ $assistantOpenAIKeyValue = htmlspecialchars((string) $defaultAssistantOpenAIKey,
<div class="input-group stack-xs">
<label class="label-text typography-text-m-500 text-neutral-secondary">Database</label>
<div class="selector-group<?php echo $isDatabaseLocked ? ' is-locked' : ''; ?>">
<?php if ($mongoEnabled) { ?>
<label class="selector-card <?php echo ($selectedDatabase === 'mongodb') ? 'selected' : ''; ?><?php echo $mongoDisabled ? ' is-disabled has-tooltip' : ''; ?>"<?php echo $mongoDisabled ? ' aria-disabled="true"' : ''; ?>>
<input type="radio" name="database" value="mongodb" <?php echo ($selectedDatabase === 'mongodb') ? 'checked' : ''; ?> class="sr-only" <?php echo $mongoDisabled ? 'disabled' : ''; ?>>
<?php if ($postgresEnabled) { ?>
<label class="selector-card <?php echo ($selectedDatabase === 'postgresql') ? 'selected' : ''; ?><?php echo $postgresDisabled ? ' is-disabled has-tooltip' : ''; ?>"<?php echo $postgresDisabled ? ' aria-disabled="true"' : ''; ?>>
<input type="radio" name="database" value="postgresql" <?php echo ($selectedDatabase === 'postgresql') ? 'checked' : ''; ?> class="sr-only" <?php echo $postgresDisabled ? 'disabled' : ''; ?>>
<div class="selector-content">
<div class="typography-text-m-500 text-neutral-primary">MongoDB</div>
<div class="typography-text-xs-400 text-neutral-secondary">Document based database</div>
<div class="typography-text-m-500 text-neutral-primary">PostgreSQL</div>
<div class="typography-text-xs-400 text-neutral-secondary">Relational SQL database</div>
</div>
<img src="installer/icons/mongodb.svg" alt="MongoDB" class="selector-icon">
<?php if ($mongoDisabled) { ?>
<img src="installer/icons/postgresql.svg" alt="PostgreSQL" class="selector-icon">
<?php if ($postgresDisabled) { ?>
<span class="tooltip tooltip-db-locked typography-text-m-400 text-on-invert" role="tooltip" data-tooltip-portal="true">Database cannot be changed after initial setup.</span>
<?php } ?>
</label>
@@ -75,15 +75,15 @@ $assistantOpenAIKeyValue = htmlspecialchars((string) $defaultAssistantOpenAIKey,
</label>
<?php } ?>
<?php if ($postgresEnabled) { ?>
<label class="selector-card <?php echo ($selectedDatabase === 'postgresql') ? 'selected' : ''; ?><?php echo $postgresDisabled ? ' is-disabled has-tooltip' : ''; ?>"<?php echo $postgresDisabled ? ' aria-disabled="true"' : ''; ?>>
<input type="radio" name="database" value="postgresql" <?php echo ($selectedDatabase === 'postgresql') ? 'checked' : ''; ?> class="sr-only" <?php echo $postgresDisabled ? 'disabled' : ''; ?>>
<?php if ($mongoEnabled) { ?>
<label class="selector-card <?php echo ($selectedDatabase === 'mongodb') ? 'selected' : ''; ?><?php echo $mongoDisabled ? ' is-disabled has-tooltip' : ''; ?>"<?php echo $mongoDisabled ? ' aria-disabled="true"' : ''; ?>>
<input type="radio" name="database" value="mongodb" <?php echo ($selectedDatabase === 'mongodb') ? 'checked' : ''; ?> class="sr-only" <?php echo $mongoDisabled ? 'disabled' : ''; ?>>
<div class="selector-content">
<div class="typography-text-m-500 text-neutral-primary">PostgreSQL</div>
<div class="typography-text-xs-400 text-neutral-secondary">Relational SQL database</div>
<div class="typography-text-m-500 text-neutral-primary">MongoDB</div>
<div class="typography-text-xs-400 text-neutral-secondary">Document based database</div>
</div>
<img src="installer/icons/postgresql.svg" alt="PostgreSQL" class="selector-icon">
<?php if ($postgresDisabled) { ?>
<img src="installer/icons/mongodb.svg" alt="MongoDB" class="selector-icon">
<?php if ($mongoDisabled) { ?>
<span class="tooltip tooltip-db-locked typography-text-m-400 text-on-invert" role="tooltip" data-tooltip-portal="true">Database cannot be changed after initial setup.</span>
<?php } ?>
</label>
+3 -3
View File
@@ -10,18 +10,18 @@ class Generator
'database' => [
'default' => 'postgresql',
'services' => [
'postgresql',
'mariadb',
'mongodb',
'postgresql',
],
],
];
private const array SELECTABLE_VOLUME_GROUPS = [
'database' => [
'postgresql' => ['appwrite-postgresql'],
'mariadb' => ['appwrite-mariadb'],
'mongodb' => ['appwrite-mongodb', 'appwrite-mongodb-keyfile'],
'postgresql' => ['appwrite-postgresql'],
],
];
@@ -77,9 +77,9 @@ class Generator
private array $params = [];
private array $selectableServices = [
'postgresql',
'mariadb',
'mongodb',
'postgresql',
];
public function __construct(string $compose)
@@ -40,7 +40,7 @@ class Install extends Action
->param('assistantOpenAIKey', '', new Text(256, 0), 'OpenAI API key for assistant', true)
->param('accountEmail', '', new Email(allowEmpty: true), 'Account email address', true)
->param('accountPassword', '', new Password(allowEmpty: true), 'Account password', true)
->param('database', '', new WhiteList(['mongodb', 'mariadb', 'postgresql']), 'Database adapter', true)
->param('database', '', new WhiteList(['postgresql', 'mariadb', 'mongodb']), 'Database adapter', true)
->param('installId', '', new Text(64, 0), 'Installation ID', true)
->param('retryStep', null, new Nullable(new WhiteList([
Server::STEP_CONFIG_FILES,
@@ -27,7 +27,7 @@ final class Config
private bool $isLocal = false;
private ?string $hostPath = null;
private ?string $lockedDatabase = null;
private array $enabledDatabases = ['mongodb', 'mariadb', 'postgresql'];
private array $enabledDatabases = ['postgresql', 'mariadb', 'mongodb'];
private array $vars = [];
public function __construct(array $values = [])
@@ -199,7 +199,7 @@ class State
public function isValidDatabaseAdapter(string $value): bool
{
return in_array($value, ['mongodb', 'mariadb', 'postgresql'], true);
return in_array($value, ['postgresql', 'mariadb', 'mongodb'], true);
}
public function progressFilePath(string $installId): string
+3 -3
View File
@@ -59,7 +59,7 @@ class Install extends Action
->param('image', 'appwrite', new Text(0), 'Main appwrite docker image', true)
->param('interactive', 'Y', new Text(1), 'Run an interactive session', true)
->param('no-start', false, new Boolean(true), 'Run an interactive session', true)
->param('database', 'postgresql', new WhiteList(['mongodb', 'mariadb', 'postgresql']), 'Database to use (mongodb|mariadb|postgresql)', true)
->param('database', 'postgresql', new WhiteList(['postgresql', 'mariadb', 'mongodb']), 'Database to use (postgresql|mariadb|mongodb)', true)
->callback($this->action(...));
}
@@ -202,7 +202,7 @@ class Install extends Action
}
$installerConfig = $this->readInstallerConfig();
$enabledDatabases = $installerConfig['enabledDatabases'] ?? ['mongodb', 'mariadb', 'postgresql'];
$enabledDatabases = $installerConfig['enabledDatabases'] ?? ['postgresql', 'mariadb', 'mongodb'];
$isExistingDatabase = $isUpgrade && $existingDatabase !== null && $database === $existingDatabase;
if (!in_array($database, $enabledDatabases, true) && !$isExistingDatabase) {
Console::error("Database '{$database}' is not available. Available options: " . implode(', ', $enabledDatabases));
@@ -335,7 +335,7 @@ class Install extends Action
$state->clearStaleLock();
$installerConfig = $this->readInstallerConfig();
$enabledDatabases = $installerConfig['enabledDatabases'] ?? ['mongodb', 'mariadb', 'postgresql'];
$enabledDatabases = $installerConfig['enabledDatabases'] ?? ['postgresql', 'mariadb', 'mongodb'];
if ($isUpgrade && $lockedDatabase !== null && !in_array($lockedDatabase, $enabledDatabases, true)) {
$enabledDatabases[] = $lockedDatabase;
}
@@ -0,0 +1,72 @@
<?php
declare(strict_types=1);
namespace Tests\Unit\Platform\Modules\Installer\Http\Installer;
use PHPUnit\Framework\TestCase;
use Throwable;
final class ViewTest extends TestCase
{
public function testDatabaseOptionsFollowPreferredOrder(): void
{
$html = $this->render();
$postgres = strpos($html, '>PostgreSQL</div>');
$maria = strpos($html, '>MariaDB</div>');
$mongo = strpos($html, '>MongoDB</div>');
$this->assertNotFalse($postgres);
$this->assertNotFalse($maria);
$this->assertNotFalse($mongo);
$this->assertLessThan($maria, $postgres);
$this->assertLessThan($mongo, $maria);
}
public function testUpgradeWithoutDetectedDatabaseRemainsSelectable(): void
{
$html = $this->render([
'isUpgrade' => true,
'lockedDatabase' => null,
]);
$this->assertStringNotContainsString('data-locked-database=', $html);
$this->assertStringNotContainsString('selector-group is-locked', $html);
$this->assertDoesNotMatchRegularExpression('/<input type="radio" name="database"[^>]*disabled/', $html);
$this->assertMatchesRegularExpression('/name="database" value="postgresql"[^>]*checked/', $html);
}
public function testUpgradeWithDetectedDatabaseRemainsLocked(): void
{
$html = $this->render([
'isUpgrade' => true,
'lockedDatabase' => 'mongodb',
]);
$this->assertStringContainsString('data-locked-database="mongodb"', $html);
$this->assertStringContainsString('selector-group is-locked', $html);
$this->assertMatchesRegularExpression('/name="database" value="mongodb"[^>]*checked/', $html);
$this->assertMatchesRegularExpression('/name="database" value="postgresql"[^>]*disabled/', $html);
}
private function render(array $values = []): string
{
$step = 1;
$isUpgrade = false;
$lockedDatabase = null;
$vars = [];
$enabledDatabases = ['postgresql', 'mariadb', 'mongodb'];
$csrfToken = 'test-token';
extract($values, EXTR_OVERWRITE);
ob_start();
try {
include dirname(__DIR__, 7) . '/app/views/install/installer.phtml';
return (string) ob_get_clean();
} catch (Throwable $error) {
ob_end_clean();
throw $error;
}
}
}
@@ -22,7 +22,7 @@ final class ConfigTest extends TestCase
$this->assertFalse($config->isLocal());
$this->assertNull($config->getHostPath());
$this->assertNull($config->getLockedDatabase());
$this->assertSame(['mongodb', 'mariadb', 'postgresql'], $config->getEnabledDatabases());
$this->assertSame(['postgresql', 'mariadb', 'mongodb'], $config->getEnabledDatabases());
$this->assertEmpty($config->getVars());
}
@@ -439,7 +439,7 @@ final class ConfigTest extends TestCase
$this->assertFalse($array['isLocal']);
$this->assertNull($array['hostPath']);
$this->assertNull($array['lockedDatabase']);
$this->assertEquals(['mongodb', 'mariadb', 'postgresql'], $array['enabledDatabases']);
$this->assertEquals(['postgresql', 'mariadb', 'mongodb'], $array['enabledDatabases']);
}
public function testMultipleApplyCallsAccumulate(): void
@@ -494,7 +494,7 @@ final class ConfigTest extends TestCase
public function testDefaultEnabledDatabases(): void
{
$config = new Config();
$this->assertSame(['mongodb', 'mariadb', 'postgresql'], $config->getEnabledDatabases());
$this->assertSame(['postgresql', 'mariadb', 'mongodb'], $config->getEnabledDatabases());
$this->assertTrue($config->isDatabaseEnabled('mongodb'));
$this->assertTrue($config->isDatabaseEnabled('mariadb'));
$this->assertTrue($config->isDatabaseEnabled('postgresql'));
@@ -535,7 +535,7 @@ final class ConfigTest extends TestCase
{
$config = new Config();
$config->apply(['enabledDatabases' => 'mongodb']);
$this->assertSame(['mongodb', 'mariadb', 'postgresql'], $config->getEnabledDatabases());
$this->assertSame(['postgresql', 'mariadb', 'mongodb'], $config->getEnabledDatabases());
}
public function testEnabledDatabasesInToArray(): void