Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Pg adapter installation #9772

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 20 commits into
base: 1.8.x
Choose a base branch
Loading
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
bfdcd13
add postges installtion command
ArnabChatterjee20k May 16, 2025
083e490
updated compose file and installation script
ArnabChatterjee20k May 16, 2025
f846e41
linting
ArnabChatterjee20k May 16, 2025
5f7afa2
added conditonal for .env for mariadb and psotgres
ArnabChatterjee20k May 16, 2025
26c3248
used env var in the registers for the pool
ArnabChatterjee20k May 16, 2025
9f22ab4
added the callable resource in the pg adapter
ArnabChatterjee20k May 16, 2025
2460f0c
updated composer lock
ArnabChatterjee20k May 16, 2025
b775a54
Merge branch '1.6.x' into pg-adapter
ArnabChatterjee20k May 16, 2025
78de031
added changes
ArnabChatterjee20k May 16, 2025
e1207ca
updated the environment of the services in the docker compose of install
ArnabChatterjee20k May 16, 2025
e88aebd
added upgrade limit for db
ArnabChatterjee20k May 16, 2025
f2ed034
Merge branch 'main' into pg-adapter
ArnabChatterjee20k May 19, 2025
e45befb
updated local docker for ci test on github actions and tests yml
ArnabChatterjee20k May 20, 2025
60be482
changed the depends on to scheme
ArnabChatterjee20k May 20, 2025
9ca6527
Merge branch 'main' into pg-adapter
ArnabChatterjee20k May 20, 2025
58e04b4
removed trailing comma from the matrix db adapter of the test
ArnabChatterjee20k May 20, 2025
f5c54bb
added _APP_DB_ADAPTER
ArnabChatterjee20k May 21, 2025
e7f5102
updated updating database in the installation
ArnabChatterjee20k May 21, 2025
f1b2ac0
updated tests yml
ArnabChatterjee20k May 21, 2025
be1e525
updated depends on to the host instead of adapter and changed to the …
ArnabChatterjee20k May 27, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add postges installtion command
  • Loading branch information
ArnabChatterjee20k committed May 16, 2025
commit bfdcd13f80beb7ba42a49f5a085ade45b3fe8c65
1 change: 1 addition & 0 deletions 1 .env
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ _APP_REDIS_HOST=redis
_APP_REDIS_PORT=6379
_APP_REDIS_PASS=
_APP_REDIS_USER=
_APP_DB_SCHEME=postgresql
_APP_DB_HOST=mariadb
_APP_DB_PORT=3306
_APP_DB_SCHEMA=appwrite
Expand Down
28 changes: 23 additions & 5 deletions 28 app/init/registers.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Utopia\Config\Config;
use Utopia\Database\Adapter\MariaDB;
use Utopia\Database\Adapter\MySQL;
use Utopia\Database\Adapter\Postgres;
use Utopia\Database\Adapter\SQL;
use Utopia\Database\PDO;
use Utopia\Domains\Validator\PublicDomain;
Expand Down Expand Up @@ -120,19 +121,19 @@
'type' => 'database',
'dsns' => $fallbackForDB,
'multiple' => false,
'schemes' => ['mariadb', 'mysql'],
'schemes' => ['mariadb', 'mysql','postgresql'],
],
'database' => [
'type' => 'database',
'dsns' => $fallbackForDB,
'multiple' => true,
'schemes' => ['mariadb', 'mysql'],
'schemes' => ['mariadb', 'mysql','postgresql'],
],
'logs' => [
'type' => 'database',
'dsns' => System::getEnv('_APP_CONNECTIONS_DB_LOGS', $fallbackForDB),
'multiple' => false,
'schemes' => ['mariadb', 'mysql'],
'schemes' => ['mariadb', 'mysql','postgresql'],
],
'publisher' => [
'type' => 'publisher',
Expand Down Expand Up @@ -225,6 +226,17 @@
));
});
},
'postgresql' => function () use ($dsnHost, $dsnPort, $dsnUser, $dsnPass, $dsnDatabase) {
return new PDOProxy(function () use ($dsnHost, $dsnPort, $dsnUser, $dsnPass, $dsnDatabase) {
return new PDO("pgsql:host={$dsnHost};port={$dsnPort};dbname={$dsnDatabase}", $dsnUser, $dsnPass, array(
\PDO::ATTR_TIMEOUT => 3, // Seconds
\PDO::ATTR_PERSISTENT => false,
\PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC,
\PDO::ATTR_EMULATE_PREPARES => true,
\PDO::ATTR_STRINGIFY_FETCHES => true
));
});
},
abnegate marked this conversation as resolved.
Show resolved Hide resolved
'redis' => function () use ($dsnHost, $dsnPort, $dsnPass) {
$redis = new \Redis();
@$redis->pconnect($dsnHost, (int)$dsnPort);
Expand All @@ -245,6 +257,7 @@
$adapter = match ($dsn->getScheme()) {
'mariadb' => new MariaDB($resource()),
'mysql' => new MySQL($resource()),
'postgresql' => new Postgres($resource),
default => null
};

Expand Down Expand Up @@ -286,10 +299,15 @@
$dbPort = System::getEnv('_APP_DB_PORT', '');
$dbUser = System::getEnv('_APP_DB_USER', '');
$dbPass = System::getEnv('_APP_DB_PASS', '');
$dbScheme = System::getEnv('_APP_DB_SCHEMA', '');
$dbSchema = System::getEnv('_APP_DB_SCHEMA', '');
$dbScheme = System::getEnv('_APP_DB_SCHEME', 'mariadb');
$dsn = ($dbScheme === 'postgresql')
? "pgsql:host={$dbHost};port={$dbPort};dbname={$dbSchema}"
: "mysql:host={$dbHost};port={$dbPort};dbname={$dbSchema};charset=utf8mb4";
abnegate marked this conversation as resolved.
Show resolved Hide resolved


return new PDO(
"mysql:host={$dbHost};port={$dbPort};dbname={$dbScheme};charset=utf8mb4",
$dsn,
$dbUser,
$dbPass,
SQL::getPDOAttributes()
Expand Down
24 changes: 22 additions & 2 deletions 24 app/views/install/compose.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,12 @@ $image = $this->getParam('image', '');
- appwrite-certificates:/storage/certificates:rw
- appwrite-functions:/storage/functions:rw
depends_on:
- mariadb
- redis
<?php if ($this->getParam('_APP_DB_SCHEME', 'mariadb') === 'mariadb'): ?>
- mariadb
<?php else: ?>
- postgres
<?php endif; ?>
# - clamav
environment:
- _APP_ENV
Expand Down Expand Up @@ -100,6 +104,7 @@ $image = $this->getParam('image', '');
- _APP_DB_SCHEMA
- _APP_DB_USER
- _APP_DB_PASS
- _APP_DB_SCHEME
- _APP_SMTP_HOST
- _APP_SMTP_PORT
- _APP_SMTP_SECURE
Expand Down Expand Up @@ -211,8 +216,8 @@ $image = $this->getParam('image', '');
networks:
- appwrite
depends_on:
- mariadb
- redis
- mariadb
environment:
- _APP_ENV
- _APP_WORKER_PER_CORE
Expand Down Expand Up @@ -897,6 +902,20 @@ $image = $this->getParam('image', '');
- MARIADB_AUTO_UPGRADE=1
command: 'mysqld --innodb-flush-method=fsync'

postgres:
image: postgres:15-alpine
container_name: appwrite-postgres
<<: *x-logging
restart: unless-stopped
networks:
- appwrite
volumes:
- appwrite-postgres:/var/lib/postgresql/data:rw
environment:
- POSTGRES_DB=${_APP_DB_SCHEMA}
- POSTGRES_USER=${_APP_DB_USER}
- POSTGRES_PASSWORD=${_APP_DB_PASS}

redis:
image: redis:7.2.4-alpine
container_name: appwrite-redis
Expand Down Expand Up @@ -938,3 +957,4 @@ volumes:
appwrite-functions:
appwrite-builds:
appwrite-config:
appwrite-postgres:
12 changes: 6 additions & 6 deletions 12 composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 27 additions & 4 deletions 31 src/Appwrite/Platform/Tasks/Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,25 @@ public function __construct()
->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)
->callback(fn ($httpPort, $httpsPort, $organization, $image, $interactive, $noStart) => $this->action($httpPort, $httpsPort, $organization, $image, $interactive, $noStart));
->param('database', 'mariadb', new Text(0), 'Database to use (mariadb|postgresql)', true)
->callback(fn ($httpPort, $httpsPort, $organization, $image, $interactive, $noStart, $database) => $this->action($httpPort, $httpsPort, $organization, $image, $interactive, $noStart, $database));
abnegate marked this conversation as resolved.
Show resolved Hide resolved
}

public function action(string $httpPort, string $httpsPort, string $organization, string $image, string $interactive, bool $noStart): void
public function action(string $httpPort, string $httpsPort, string $organization, string $image, string $interactive, bool $noStart, string $database): void
{
$config = Config::getParam('variables');
$defaultHTTPPort = '80';
$defaultHTTPSPort = '443';
/** @var array<string, array<string, string>> $vars array whre key is variable name and value is variable */
$vars = [];
$vars['_APP_DB_SCHEME'] = [
'name' => '_APP_DB_SCHEME',
'default' => $database,
'required' => false,
'filter' => '',
'overwrite' => true,
'question' => 'Choose your database (mariadb|postgresql)',
];

foreach ($config as $category) {
foreach ($category['variables'] ?? [] as $var) {
Expand Down Expand Up @@ -171,6 +180,19 @@ public function action(string $httpPort, string $httpsPort, string $organization
continue;
}

if ($var['name'] === '_APP_DB_SCHEME') {
$input[$var['name']] = Console::confirm('Choose your database (mariadb|postgresql): (default: ' . $var['default'] . ')');
if (empty($input[$var['name']])) {
$input[$var['name']] = $var['default'];
}
if (!in_array($input[$var['name']], ['mariadb', 'postgresql'])) {
Console::error('Invalid database choice. Please choose either mariadb or postgresql.');
Console::exit(1);
}
$database = $input[$var['name']];
continue;
}

$input[$var['name']] = Console::confirm($var['question'] . ' (default: \'' . $var['default'] . '\')');

if (empty($input[$var['name']])) {
Expand All @@ -196,8 +218,9 @@ public function action(string $httpPort, string $httpsPort, string $organization
->setParam('httpsPort', $httpsPort)
->setParam('version', APP_VERSION_STABLE)
->setParam('organization', $organization)
->setParam('image', $image);

->setParam('image', $image)
->setParam('database',$database);
$input['_APP_DB_SCHEME'] = $database;
$templateForEnv->setParam('vars', $input);

if (!file_put_contents($this->path . '/docker-compose.yml', $templateForCompose->render(false))) {
Expand Down
7 changes: 4 additions & 3 deletions 7 src/Appwrite/Platform/Tasks/Upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ public function __construct()
->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)
->callback(fn ($httpPort, $httpsPort, $organization, $image, $interactive, $noStart) => $this->action($httpPort, $httpsPort, $organization, $image, $interactive, $noStart));
->param('database', 'mariadb', new Text(0), 'Database to use (mariadb|postgresql)', true)
abnegate marked this conversation as resolved.
Show resolved Hide resolved
->callback(fn ($httpPort, $httpsPort, $organization, $image, $interactive, $noStart, $database) => $this->action($httpPort, $httpsPort, $organization, $image, $interactive, $noStart, $database));
}

public function action(string $httpPort, string $httpsPort, string $organization, string $image, string $interactive, bool $noStart): void
public function action(string $httpPort, string $httpsPort, string $organization, string $image, string $interactive, bool $noStart, string $database): void
{
// Check for previous installation
$data = @file_get_contents($this->path . '/docker-compose.yml');
Expand All @@ -39,6 +40,6 @@ public function action(string $httpPort, string $httpsPort, string $organization
Console::log(' └── docker-compose.yml');
Console::exit(1);
}
parent::action($httpPort, $httpsPort, $organization, $image, $interactive, $noStart);
parent::action($httpPort, $httpsPort, $organization, $image, $interactive, $noStart, $database);
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.