mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-04 19:24:02 +00:00
Dump DB statement
This commit is contained in:
parent
796a251b7d
commit
9aee480a80
1 changed files with 14 additions and 2 deletions
|
|
@ -19,9 +19,7 @@ class CreateRLSPoliciesForTenantTables extends Command
|
|||
|
||||
public function handle(): int
|
||||
{
|
||||
dump('Current RLS tables', DB::select('SELECT * FROM pg_policies'));
|
||||
tenancy()->getModels()->each(fn (Model $model) => $this->useRlsOnModel($model));
|
||||
dump('RLS tables created', DB::select('SELECT * FROM pg_policies'));
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
|
@ -50,6 +48,18 @@ class CreateRLSPoliciesForTenantTables extends Command
|
|||
$parentKey = $model->$parentName()->getForeignKeyName();
|
||||
$parentTable = $model->$parentName()->make()->getTable();
|
||||
|
||||
dump("CREATE POLICY {$table}_rls_policy ON {$table} USING (
|
||||
{$parentKey} IN (
|
||||
SELECT id
|
||||
FROM {$parentTable}
|
||||
WHERE ({$tenantKey} = (
|
||||
SELECT {$tenantKey}
|
||||
FROM {$parentTable}
|
||||
WHERE id = {$parentKey}
|
||||
))
|
||||
)
|
||||
)");
|
||||
|
||||
DB::statement("CREATE POLICY {$table}_rls_policy ON {$table} USING (
|
||||
{$parentKey} IN (
|
||||
SELECT id
|
||||
|
|
@ -62,6 +72,8 @@ class CreateRLSPoliciesForTenantTables extends Command
|
|||
)
|
||||
)");
|
||||
|
||||
dump('statement completed');
|
||||
|
||||
$this->enableRls($table);
|
||||
|
||||
$this->components->info("Created RLS policy for table '$table'");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue