From bad5c693ab9bca2a6a9a1392667ebf5185a1e6f3 Mon Sep 17 00:00:00 2001 From: lukinovec Date: Mon, 5 Jun 2023 16:33:26 +0200 Subject: [PATCH] Add `config('tenancy.database.rls')` --- assets/config.php | 11 +++++++---- src/Database/Concerns/BelongsToTenant.php | 4 ++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/assets/config.php b/assets/config.php index 661aa07a..3518a623 100644 --- a/assets/config.php +++ b/assets/config.php @@ -10,10 +10,6 @@ return [ * Configuration for the models used by Tenancy. */ 'models' => [ - 'rls' => [ - // The tenants:create-rls-policies comand will create RLS policies - // For tables of the models specified here - ], 'tenant' => Stancl\Tenancy\Database\Models\Tenant::class, 'domain' => Stancl\Tenancy\Database\Models\Domain::class, @@ -179,6 +175,13 @@ return [ // todo docblock 'drop_tenant_databases_on_migrate_fresh' => false, + + /** + * Scope tenant models using RLS. + * + * Requires Postgres with single-database tenancy. + */ + 'rls' => false, ], /** diff --git a/src/Database/Concerns/BelongsToTenant.php b/src/Database/Concerns/BelongsToTenant.php index f6911854..c5323065 100644 --- a/src/Database/Concerns/BelongsToTenant.php +++ b/src/Database/Concerns/BelongsToTenant.php @@ -21,8 +21,8 @@ trait BelongsToTenant public static function bootBelongsToTenant(): void { - // Queries of models present in the tenancy.models.rls config are scoped using Postgres RLS instead of the global scope - if (! in_array(static::class, config('tenancy.models.rls'))) { + // If tenancy.database.rls is true, scope queries using Postgres RLS instead of TenantScope + if (! config('tenancy.database.rls')) { static::addGlobalScope(new TenantScope); }