mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 16:34:04 +00:00
Add Postgres bootstrapper
This commit is contained in:
parent
eb7baa5360
commit
3c098dc78e
1 changed files with 41 additions and 0 deletions
|
|
@ -0,0 +1,41 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Stancl\Tenancy\Bootstrappers\Integrations;
|
||||||
|
|
||||||
|
use Stancl\Tenancy\Contracts\Tenant;
|
||||||
|
use Illuminate\Database\DatabaseManager;
|
||||||
|
use Illuminate\Contracts\Config\Repository;
|
||||||
|
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
|
||||||
|
|
||||||
|
class PostgresTenancyBootstrapper implements TenancyBootstrapper
|
||||||
|
{
|
||||||
|
protected array $originalCentralConnectionConfig;
|
||||||
|
protected array $originalPostgresConfig;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
protected Repository $config,
|
||||||
|
protected DatabaseManager $database,
|
||||||
|
) {
|
||||||
|
$this->originalCentralConnectionConfig = $config->get('database.connections.central');
|
||||||
|
$this->originalPostgresConfig = $config->get('database.connections.pgsql');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function bootstrap(Tenant $tenant): void
|
||||||
|
{
|
||||||
|
$this->database->purge('central');
|
||||||
|
|
||||||
|
$this->config->set('database.connections.pgsql.username', $tenant->getTenantKey());
|
||||||
|
$this->config->set('database.connections.pgsql.password', $tenant->database()->getPassword() ?? 'password');
|
||||||
|
$this->config->set('database.connections.central', $this->config->get('database.connections.pgsql'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function revert(): void
|
||||||
|
{
|
||||||
|
$this->database->purge('central');
|
||||||
|
|
||||||
|
$this->config->set('database.connections.central', $this->originalCentralConnectionConfig);
|
||||||
|
$this->config->set('database.connections.pgsql', $this->originalPostgresConfig);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue