mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 13:14:05 +00:00
Add support for postgres schema
This commit is contained in:
parent
fd00be646e
commit
2ff3dd4283
5 changed files with 127 additions and 2 deletions
35
src/TenantDatabaseManagers/PostgreSQLSchemaManager.php
Normal file
35
src/TenantDatabaseManagers/PostgreSQLSchemaManager.php
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stancl\Tenancy\TenantDatabaseManagers;
|
||||
|
||||
use Illuminate\Contracts\Config\Repository;
|
||||
use Illuminate\Database\DatabaseManager as IlluminateDatabaseManager;
|
||||
use Stancl\Tenancy\Contracts\TenantDatabaseManager;
|
||||
|
||||
class PostgreSQLSchemaManager implements TenantDatabaseManager
|
||||
{
|
||||
/** @var \Illuminate\Database\Connection */
|
||||
protected $database;
|
||||
|
||||
public function __construct(Repository $config, IlluminateDatabaseManager $databaseManager)
|
||||
{
|
||||
$this->database = $databaseManager->connection($config['tenancy.database_manager_connections.schema']);
|
||||
}
|
||||
|
||||
public function createDatabase(string $name): bool
|
||||
{
|
||||
return $this->database->statement("CREATE SCHEMA \"$name\"");
|
||||
}
|
||||
|
||||
public function deleteDatabase(string $name): bool
|
||||
{
|
||||
return $this->database->statement("DROP SCHEMA \"$name\"");
|
||||
}
|
||||
|
||||
public function databaseExists(string $name): bool
|
||||
{
|
||||
return (bool) $this->database->select("SELECT schema_name FROM information_schema.schemata WHERE schema_name = '$name'");
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue