Merge pull request #12860 from appwrite/feat/installer-default-postgres

Default self-hosted installer to PostgreSQL
This commit is contained in:
Chirag Aggarwal authored and GitHub committed 2026-07-13 12:22:36 +05:30
commit 17d3e069a1
14 files changed
+138 -53

No files matched your search

+8 -8
View File
@@ -380,31 +380,31 @@ 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' => 'mongodb',
'default' => 'postgresql',
'required' => true,
'question' => 'Choose your database (mariadb|mongodb|postgresql)',
'question' => 'Choose your database (postgresql|mariadb|mongodb)',
'filter' => ''
],
[
'name' => '_APP_DB_HOST',
'description' => 'Database server host name address. Default value is: \'mongodb\'.',
'description' => 'Database server host name address. Default value is: \'postgresql\'.',
'introduction' => '',
'default' => 'mongodb',
'default' => 'postgresql',
'required' => false,
'question' => '',
'filter' => ''
],
[
'name' => '_APP_DB_PORT',
'description' => 'Database server TCP port. Default value is: \'27017\'.',
'description' => 'Database server TCP port. Default value is: \'5432\'.',
'introduction' => '',
'default' => '27017',
'default' => '5432',
'required' => false,
'question' => '',
'filter' => ''
+5 -4
View File
@@ -7,9 +7,8 @@ $defaultHttpsPort ??= '443';
$defaultAppDomain = $vars['_APP_DOMAIN']['default'] ?? 'localhost';
$defaultAppDomain = ($defaultAppDomain === 'traefik') ? 'localhost' : $defaultAppDomain;
$defaultEmailCertificates ??= '';
$defaultDatabase = $vars['_APP_DB_ADAPTER']['default'] ?? 'mongodb';
$lockedDatabase = $isUpgrade && empty($lockedDatabase) ? $defaultDatabase : $lockedDatabase;
$enabledDatabases ??= ['mongodb', 'mariadb'];
$defaultDatabase = $vars['_APP_DB_ADAPTER']['default'] ?? 'postgresql';
$enabledDatabases ??= ['postgresql', 'mariadb', 'mongodb'];
$isLocalInstall ??= false;
@@ -122,7 +121,9 @@ $installerVersion = @filemtime(__DIR__ . '/installer/js/installer.js') ?: time()
</div>
<div class="install-screen" aria-live="polite">
<div class="install-screen-content">
<?php if ($step === 5) { include __DIR__ . '/installer/templates/steps/step-5.phtml'; } ?>
<?php if ($step === 5) {
include __DIR__ . '/installer/templates/steps/step-5.phtml';
} ?>
</div>
</div>
</main>
@@ -4,8 +4,8 @@
const getLockedDatabase = () => getBodyDataset().lockedDatabase || '';
const getEnabledDatabases = () => {
const raw = getBodyDataset().enabledDatabases;
if (!raw) return ['mongodb', 'mariadb'];
try { return JSON.parse(raw); } catch (e) { return ['mongodb', 'mariadb']; }
if (!raw) return ['postgresql', 'mariadb', 'mongodb'];
try { return JSON.parse(raw); } catch (e) { return ['postgresql', 'mariadb', 'mongodb']; }
};
const STEP_IDS = Object.freeze({
@@ -367,7 +367,7 @@
installId,
httpPort: normalizedHttpPort,
httpsPort: normalizedHttpsPort,
database: formState?.database || 'mongodb',
database: formState?.database || 'postgresql',
appDomain: normalizedDomain,
emailCertificates: normalizedEmail,
opensslKey: (formState?.opensslKey || '').trim(),
@@ -6,8 +6,8 @@ $defaultHttpPort ??= '80';
$defaultHttpsPort ??= '443';
$defaultEmailCertificates ??= '';
$defaultAssistantOpenAIKey ??= '';
$defaultDatabase ??= 'mongodb';
$enabledDatabases ??= ['mongodb', 'mariadb'];
$defaultDatabase ??= '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>
@@ -6,7 +6,7 @@ $defaultHttpPort = $defaultHttpPort ?? '80';
$defaultHttpsPort = $defaultHttpsPort ?? '443';
$defaultEmailCertificates = $defaultEmailCertificates ?? '';
$defaultSecretKey = $defaultSecretKey ?? '';
$defaultDatabase = $defaultDatabase ?? 'mongodb';
$defaultDatabase = $defaultDatabase ?? 'postgresql';
$selectedDatabase = $lockedDatabase ?: $defaultDatabase;
$defaultDatabaseLabel = match ($selectedDatabase) {
'mariadb' => 'MariaDB',
+5 -5
View File
@@ -8,20 +8,20 @@ class Generator
{
private const array SELECTABLE_SERVICE_GROUPS = [
'database' => [
'default' => 'mongodb',
'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'],
],
];
@@ -43,7 +43,7 @@ class Generator
private const array PARAM_DEFAULTS = [
'version' => 'latest',
'database' => 'mongodb',
'database' => 'postgresql',
'hostPath' => '',
'enableAssistant' => false,
];
@@ -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,
@@ -225,7 +225,7 @@ class Install extends Action
'_APP_DOMAIN' => $appDomain ?: 'localhost',
'_APP_DOMAIN_TARGET' => $appDomain ?: 'localhost',
'_APP_EMAIL_CERTIFICATES' => $emailCertificates,
'_APP_DB_ADAPTER' => $lockedDatabase ?? ($database ?: 'mongodb'),
'_APP_DB_ADAPTER' => $lockedDatabase ?? ($database ?: 'postgresql'),
'_APP_ASSISTANT_OPENAI_API_KEY' => $assistantOpenAIKey,
];
@@ -294,7 +294,7 @@ class Install extends Action
'payload' => [
'httpPort' => $httpPort ?: $config->getDefaultHttpPort(),
'httpsPort' => $httpsPort ?: $config->getDefaultHttpsPort(),
'database' => $lockedDatabase ?? ($database ?: 'mongodb'),
'database' => $lockedDatabase ?? ($database ?: 'postgresql'),
'appDomain' => $appDomain ?: 'localhost',
'emailCertificates' => $emailCertificates,
'opensslKeyHash' => $state->hashSensitiveValue($opensslKey),
@@ -27,7 +27,7 @@ final class Config
private bool $isLocal = false;
private ?string $hostPath = null;
private ?string $lockedDatabase = null;
private array $enabledDatabases = ['mongodb', 'mariadb'];
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
+6 -6
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', 'mongodb', new WhiteList(['mongodb', 'mariadb']), 'Database to use (mongodb|mariadb)', 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'];
$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'];
$enabledDatabases = $installerConfig['enabledDatabases'] ?? ['postgresql', 'mariadb', 'mongodb'];
if ($isUpgrade && $lockedDatabase !== null && !in_array($lockedDatabase, $enabledDatabases, true)) {
$enabledDatabases[] = $lockedDatabase;
}
@@ -436,7 +436,7 @@ class Install extends Action
}
// Set database-specific connection details
$database = $input['_APP_DB_ADAPTER'] ?? 'mongodb';
$database = $input['_APP_DB_ADAPTER'] ?? 'postgresql';
if ($database === 'mongodb') {
$input['_APP_DB_HOST'] = 'mongodb';
$input['_APP_DB_PORT'] = 27017;
@@ -541,7 +541,7 @@ class Install extends Action
}
$composeGenerator = new Generator($composeYaml);
$database = $input['_APP_DB_ADAPTER'] ?? 'mongodb';
$database = $input['_APP_DB_ADAPTER'] ?? 'postgresql';
$version = \getenv('_APP_VERSION') ?: (\defined('APP_VERSION_STABLE') ? APP_VERSION_STABLE : 'latest');
if ($isLocalInstall) {
@@ -874,7 +874,7 @@ class Install extends Action
}
$type = $isUpgrade ? 'upgrade' : 'install';
$database = $input['_APP_DB_ADAPTER'] ?? 'mongodb';
$database = $input['_APP_DB_ADAPTER'] ?? 'postgresql';
$name = $account['name'] ?? 'Admin';
$email = $account['email'] ?? 'admin@selfhosted.local';
@@ -35,6 +35,18 @@ final class GeneratorTest extends TestCase
$this->assertArrayNotHasKey('appwrite-postgresql', $compose['volumes']);
}
public function testDefaultsToPostgreSQL(): void
{
$compose = $this->render();
$this->assertArrayHasKey('postgresql', $compose['services']);
$this->assertArrayNotHasKey('mongodb', $compose['services']);
$this->assertArrayNotHasKey('mariadb', $compose['services']);
$this->assertArrayHasKey('appwrite-postgresql', $compose['volumes']);
$this->assertArrayNotHasKey('appwrite-mongodb', $compose['volumes']);
$this->assertArrayNotHasKey('appwrite-mariadb', $compose['volumes']);
}
public function testTogglesAssistantService(): void
{
$disabled = $this->render([
@@ -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'], $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'], $array['enabledDatabases']);
$this->assertEquals(['postgresql', 'mariadb', 'mongodb'], $array['enabledDatabases']);
}
public function testMultipleApplyCallsAccumulate(): void
@@ -494,10 +494,10 @@ final class ConfigTest extends TestCase
public function testDefaultEnabledDatabases(): void
{
$config = new Config();
$this->assertSame(['mongodb', 'mariadb'], $config->getEnabledDatabases());
$this->assertSame(['postgresql', 'mariadb', 'mongodb'], $config->getEnabledDatabases());
$this->assertTrue($config->isDatabaseEnabled('mongodb'));
$this->assertTrue($config->isDatabaseEnabled('mariadb'));
$this->assertFalse($config->isDatabaseEnabled('postgresql'));
$this->assertTrue($config->isDatabaseEnabled('postgresql'));
}
public function testSetEnabledDatabases(): void
@@ -535,7 +535,7 @@ final class ConfigTest extends TestCase
{
$config = new Config();
$config->apply(['enabledDatabases' => 'mongodb']);
$this->assertSame(['mongodb', 'mariadb'], $config->getEnabledDatabases());
$this->assertSame(['postgresql', 'mariadb', 'mongodb'], $config->getEnabledDatabases());
}
public function testEnabledDatabasesInToArray(): void