1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-05-06 17:04:04 +00:00

refactor TenantDatabaseManagers

This commit is contained in:
Samuel Štancl 2022-08-27 22:29:08 +02:00
parent 824292e6df
commit d2e1ce0a1e
10 changed files with 52 additions and 126 deletions

View file

@ -2,34 +2,12 @@
declare(strict_types=1);
// todo likely move all of these classes to Database\
namespace Stancl\Tenancy\Database\TenantDatabaseManagers;
use Illuminate\Database\Connection;
use Illuminate\Support\Facades\DB;
use Stancl\Tenancy\Database\Contracts\TenantDatabaseManager;
use Stancl\Tenancy\Database\Contracts\TenantWithDatabase;
use Stancl\Tenancy\Database\Exceptions\NoConnectionSetException;
class MicrosoftSQLDatabaseManager implements TenantDatabaseManager
class MicrosoftSQLDatabaseManager extends TenantDatabaseManager
{
protected string $connection; // todo docblock, in all of these classes
protected function database(): Connection // todo consider abstracting this method & setConnection() into a base class
{
if ($this->connection === null) {
throw new NoConnectionSetException(static::class);
}
return DB::connection($this->connection);
}
public function setConnection(string $connection): void
{
$this->connection = $connection;
}
public function createDatabase(TenantWithDatabase $tenant): bool
{
$database = $tenant->database()->getName();
@ -48,11 +26,4 @@ class MicrosoftSQLDatabaseManager implements TenantDatabaseManager
{
return (bool) $this->database()->select("SELECT name FROM master.sys.databases WHERE name = '$name'");
}
public function makeConnectionConfig(array $baseConfig, string $databaseName): array
{
$baseConfig['database'] = $databaseName;
return $baseConfig;
}
}