mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-04 19:24:02 +00:00
Get central connection name from the config
This commit is contained in:
parent
12b36f407d
commit
5754f8bdc4
2 changed files with 10 additions and 5 deletions
|
|
@ -37,14 +37,19 @@ class PostgresRLSBootstrapper implements TenancyBootstrapper
|
|||
$this->config->set('database.connections.pgsql.username', $tenant->database()->getUsername() ?? $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'));
|
||||
$this->config->set(
|
||||
'database.connections.' . $this->config->get('tenancy.database.central_connection'),
|
||||
$this->config->get('database.connections.pgsql')
|
||||
);
|
||||
}
|
||||
|
||||
public function revert(): void
|
||||
{
|
||||
$this->database->purge('central');
|
||||
$centralConnection = $this->config->get('tenancy.database.central_connection');
|
||||
|
||||
$this->config->set('database.connections.central', $this->originalCentralConnectionConfig);
|
||||
$this->database->purge($centralConnection);
|
||||
|
||||
$this->config->set('database.connections.' . $centralConnection, $this->originalCentralConnectionConfig);
|
||||
$this->config->set('database.connections.pgsql', $this->originalPostgresConfig);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,13 +20,13 @@ use Stancl\Tenancy\Listeners\RevertToCentralContext;
|
|||
use Stancl\Tenancy\Bootstrappers\Integrations\PostgresRLSBootstrapper;
|
||||
|
||||
beforeEach(function () {
|
||||
DB::purge('central');
|
||||
DB::purge($centralConnection = config('tenancy.database.central_connection'));
|
||||
|
||||
Event::listen(TenancyInitialized::class, BootstrapTenancy::class);
|
||||
Event::listen(TenancyEnded::class, RevertToCentralContext::class);
|
||||
|
||||
config(['tenancy.bootstrappers' => [PostgresRLSBootstrapper::class]]);
|
||||
config(['database.connections.central' => config('database.connections.pgsql')]);
|
||||
config(['database.connections.' . $centralConnection => config('database.connections.pgsql')]);
|
||||
config(['tenancy.models.tenant_key_column' => 'tenant_id']);
|
||||
config(['tenancy.models.tenant' => $tenantClass = Tenant::class]);
|
||||
config(['tenancy.models.rls' => [
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue