mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 15:54:03 +00:00
Store string instead of Connection instance
This commit is contained in:
parent
68b74642c8
commit
9a13cac9d2
1 changed files with 19 additions and 19 deletions
|
|
@ -12,36 +12,36 @@ use Stancl\Tenancy\Contracts\TenantDatabaseManager;
|
||||||
|
|
||||||
class PostgreSQLSchemaManager implements TenantDatabaseManager, CanSetConnection
|
class PostgreSQLSchemaManager implements TenantDatabaseManager, CanSetConnection
|
||||||
{
|
{
|
||||||
/** @var Connection */
|
|
||||||
protected $database;
|
|
||||||
|
|
||||||
/** @var string */
|
/** @var string */
|
||||||
protected $connection;
|
protected $connection;
|
||||||
|
|
||||||
public function __construct(Repository $config, DatabaseManager $databaseManager)
|
public function __construct(Repository $config)
|
||||||
{
|
{
|
||||||
$this->connection = $config['tenancy.database_manager_connections.pgsql'];
|
$this->connection = $config->get('tenancy.database_manager_connections.mysql');
|
||||||
|
|
||||||
$this->database = $databaseManager->connection($this->connection);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createDatabase(string $name): bool
|
protected function database(): Connection
|
||||||
{
|
{
|
||||||
return $this->database->statement("CREATE SCHEMA \"$name\"");
|
return DB::connection($this->connection);
|
||||||
}
|
|
||||||
|
|
||||||
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'");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setConnection(string $connection): void
|
public function setConnection(string $connection): void
|
||||||
{
|
{
|
||||||
$this->connection = $connection;
|
$this->connection = $connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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