From eb5829175e0fe5d37406e09958c8a019788dd13f Mon Sep 17 00:00:00 2001 From: lukinovec Date: Fri, 16 Jun 2023 09:57:58 +0200 Subject: [PATCH] Test if the db statement is incorrect --- src/Commands/CreateRLSPoliciesForTenantTables.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Commands/CreateRLSPoliciesForTenantTables.php b/src/Commands/CreateRLSPoliciesForTenantTables.php index df48688f..15327f69 100644 --- a/src/Commands/CreateRLSPoliciesForTenantTables.php +++ b/src/Commands/CreateRLSPoliciesForTenantTables.php @@ -32,8 +32,6 @@ class CreateRLSPoliciesForTenantTables extends Command $table = $model->getTable(); $tenantKey = tenancy()->tenantKeyColumn(); - DB::statement("DROP POLICY IF EXISTS {$table}_rls_policy ON {$table}"); - if (tenancy()->modelBelongsToTenant($model)) { DB::statement("CREATE POLICY {$table}_rls_policy ON {$table} USING ({$tenantKey}::TEXT = current_user);"); @@ -48,7 +46,6 @@ class CreateRLSPoliciesForTenantTables extends Command $parentKey = $model->$parentName()->getForeignKeyName(); $parentTable = $model->$parentName()->make()->getTable(); - DB::enableQueryLog(); DB::statement("CREATE POLICY {$table}_rls_policy ON {$table} USING ( {$parentKey} IN ( SELECT id @@ -60,8 +57,11 @@ class CreateRLSPoliciesForTenantTables extends Command )) ) )"); - dump(DB::getQueryLog()); - DB::disableQueryLog(); + dump(DB::select('SELECT * FROM pg_policies')); + + DB::statement("CREATE POLICY {$table}_rls_policy ON {$table} USING ({$tenantKey}::TEXT = current_user);"); + + dd(DB::select('SELECT * FROM pg_policies')); $this->enableRls($table);