mirror of
https://github.com/archtechx/tenancy.git
synced 2026-05-06 17:04:04 +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:
parent
1aa3e25962
commit
7001e2d161
1 changed files with 9 additions and 2 deletions
|
|
@ -11,9 +11,16 @@ class PostgreSQLDatabaseManager extends TenantDatabaseManager
|
|||
public function createDatabase(TenantWithDatabase $tenant): bool
|
||||
{
|
||||
$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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue