1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-05-06 16:24:03 +00:00

Only specify ENCODING= in CREATE DATABASE if charset is configured

If the charset is null, Postgres creates the DB with the server's default charset

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
lukinovec 2026-04-24 11:52:18 +02:00
parent 1aa3e25962
commit 7001e2d161

View file

@ -11,9 +11,16 @@ class PostgreSQLDatabaseManager extends TenantDatabaseManager
public function createDatabase(TenantWithDatabase $tenant): bool public function createDatabase(TenantWithDatabase $tenant): bool
{ {
$database = $tenant->database()->getName(); $database = $tenant->database()->getName();
$charset = strtoupper($this->connection()->getConfig('charset') ?? 'UTF8'); // If null, Postgres creates the DB with the server's default charset
$charset = $this->connection()->getConfig('charset');
return $this->connection()->statement("CREATE DATABASE \"{$database}\" WITH TEMPLATE=template0 ENCODING='{$charset}'"); $query = "CREATE DATABASE \"{$database}\" WITH TEMPLATE=template0";
if ($charset !== null) {
$query .= " ENCODING='" . strtoupper($charset) . "'";
}
return $this->connection()->statement($query);
} }
public function deleteDatabase(TenantWithDatabase $tenant): bool public function deleteDatabase(TenantWithDatabase $tenant): bool