mirror of
https://github.com/archtechx/tenancy.git
synced 2026-05-06 15:24:03 +00:00
33 lines
921 B
PHP
33 lines
921 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Stancl\Tenancy\Database\TenantDatabaseManagers;
|
|
|
|
use Stancl\Tenancy\Database\Contracts\TenantWithDatabase;
|
|
|
|
class PostgreSQLDatabaseManager extends TenantDatabaseManager
|
|
{
|
|
public function createDatabase(TenantWithDatabase $tenant): bool
|
|
{
|
|
$name = $tenant->database()->getName();
|
|
|
|
$this->validateParameter($name);
|
|
|
|
return $this->connection()->statement("CREATE DATABASE \"{$name}\" WITH TEMPLATE=template0");
|
|
}
|
|
|
|
public function deleteDatabase(TenantWithDatabase $tenant): bool
|
|
{
|
|
$name = $tenant->database()->getName();
|
|
|
|
$this->validateParameter($name);
|
|
|
|
return $this->connection()->statement("DROP DATABASE \"{$name}\"");
|
|
}
|
|
|
|
public function databaseExists(string $name): bool
|
|
{
|
|
return (bool) $this->connection()->select('SELECT datname FROM pg_database WHERE datname = ?', [$name]);
|
|
}
|
|
}
|