1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 19:34:04 +00:00

Add support for postgres schema (#237)

* Add support for postgres schema

* wip

* Apply fixes from StyleCI

* revert to db as default for pgsql

* Move separate_by to database

* Fixing testing

* Fixing style

* Reverted change

* Store string instead of Connection instance

* Remove use statement

* Add use statement for DB facade

* mysql -> pgsql

Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com>
This commit is contained in:
Noor Adiana 2020-03-11 02:15:07 +07:00 committed by GitHub
parent e02bd3927a
commit d0023c482a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 221 additions and 2 deletions

View file

@ -0,0 +1,47 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\TenantDatabaseManagers;
use Illuminate\Contracts\Config\Repository;
use Illuminate\Database\Connection;
use Illuminate\Support\Facades\DB;
use Stancl\Tenancy\Contracts\Future\CanSetConnection;
use Stancl\Tenancy\Contracts\TenantDatabaseManager;
class PostgreSQLSchemaManager implements TenantDatabaseManager, CanSetConnection
{
/** @var string */
protected $connection;
public function __construct(Repository $config)
{
$this->connection = $config->get('tenancy.database_manager_connections.pgsql');
}
protected function database(): Connection
{
return DB::connection($this->connection);
}
public function setConnection(string $connection): void
{
$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'");
}
}