From c25aa221cb00648fff7c37c66316f083f88e6f09 Mon Sep 17 00:00:00 2001 From: lukinovec Date: Fri, 16 Jun 2023 10:31:55 +0200 Subject: [PATCH] Drop policy if exists --- src/Commands/CreateRLSPoliciesForTenantTables.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Commands/CreateRLSPoliciesForTenantTables.php b/src/Commands/CreateRLSPoliciesForTenantTables.php index eee3533d..cdcae3e4 100644 --- a/src/Commands/CreateRLSPoliciesForTenantTables.php +++ b/src/Commands/CreateRLSPoliciesForTenantTables.php @@ -34,6 +34,8 @@ 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);");