diff --git a/src/Bootstrappers/Integrations/PostgresSingleDatabaseBootstrapper.php b/src/Bootstrappers/Integrations/PostgresRLSBootstrapper.php similarity index 79% rename from src/Bootstrappers/Integrations/PostgresSingleDatabaseBootstrapper.php rename to src/Bootstrappers/Integrations/PostgresRLSBootstrapper.php index 6422dd98..2de6a0e2 100644 --- a/src/Bootstrappers/Integrations/PostgresSingleDatabaseBootstrapper.php +++ b/src/Bootstrappers/Integrations/PostgresRLSBootstrapper.php @@ -11,12 +11,14 @@ use Stancl\Tenancy\Contracts\Tenant; use Stancl\Tenancy\Database\Contracts\TenantWithDatabase; /** - * Purge central connection, set Postgres credentials to the tenant's credentials - * and use Postgres as the central connection. + * Set Postgres credentials to the tenant's credentials and use Postgres as the central connection. * - * This bootstrapper is intended to be used with single-database tenancy. + * This bootstrapper is intended to be used with Postgres RLS (single-database tenancy). + * + * @see \Stancl\Tenancy\Commands\CreatePostgresUserForTenants + * @see \Stancl\Tenancy\Commands\CreateRLSPoliciesForTenantTables */ -class PostgresSingleDatabaseBootstrapper implements TenancyBootstrapper +class PostgresRLSBootstrapper implements TenancyBootstrapper { protected array $originalCentralConnectionConfig; protected array $originalPostgresConfig; @@ -32,8 +34,6 @@ class PostgresSingleDatabaseBootstrapper implements TenancyBootstrapper public function bootstrap(Tenant $tenant): void { /** @var TenantWithDatabase $tenant */ - $this->database->purge('central'); - $this->config->set('database.connections.pgsql.username', $tenant->database()->getUsername() ?? $tenant->getTenantKey()); $this->config->set('database.connections.pgsql.password', $tenant->database()->getPassword() ?? 'password'); diff --git a/tests/PostgresTest.php b/tests/PostgresTest.php index 2591257d..e4eda5e1 100644 --- a/tests/PostgresTest.php +++ b/tests/PostgresTest.php @@ -17,7 +17,7 @@ use Stancl\Tenancy\Jobs\DeleteTenantsPostgresUser; use Illuminate\Database\Eloquent\Concerns\HasUuids; use Stancl\Tenancy\Jobs\CreatePostgresUserForTenant; use Stancl\Tenancy\Listeners\RevertToCentralContext; -use Stancl\Tenancy\Bootstrappers\Integrations\PostgresSingleDatabaseBootstrapper; +use Stancl\Tenancy\Bootstrappers\Integrations\PostgresRLSBootstrapper; beforeEach(function () { DB::purge('central'); @@ -25,7 +25,7 @@ beforeEach(function () { Event::listen(TenancyInitialized::class, BootstrapTenancy::class); Event::listen(TenancyEnded::class, RevertToCentralContext::class); - config(['tenancy.bootstrappers' => [PostgresSingleDatabaseBootstrapper::class]]); + config(['tenancy.bootstrappers' => [PostgresRLSBootstrapper::class]]); config(['database.connections.central' => config('database.connections.pgsql')]); config(['tenancy.models.tenant_key_column' => 'tenant_id']); config(['tenancy.models.tenant' => $tenantClass = Tenant::class]);