From 5754f8bdc4226d72fdfcc181f346ae19ed3ae431 Mon Sep 17 00:00:00 2001 From: lukinovec Date: Mon, 5 Jun 2023 10:08:48 +0200 Subject: [PATCH] Get central connection name from the config --- .../Integrations/PostgresRLSBootstrapper.php | 11 ++++++++--- tests/PostgresTest.php | 4 ++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Bootstrappers/Integrations/PostgresRLSBootstrapper.php b/src/Bootstrappers/Integrations/PostgresRLSBootstrapper.php index 2de6a0e2..7fa4fed9 100644 --- a/src/Bootstrappers/Integrations/PostgresRLSBootstrapper.php +++ b/src/Bootstrappers/Integrations/PostgresRLSBootstrapper.php @@ -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); } } diff --git a/tests/PostgresTest.php b/tests/PostgresTest.php index e4eda5e1..42459bd6 100644 --- a/tests/PostgresTest.php +++ b/tests/PostgresTest.php @@ -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' => [