1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-05 07:14:05 +00:00

chore formatting

This commit is contained in:
Justin van Elst 2025-01-09 10:54:17 +01:00
parent 55bc56356f
commit ec792cd9c6
No known key found for this signature in database
2 changed files with 9 additions and 7 deletions

View file

@ -108,9 +108,9 @@ class CreateUserWithRLSPolicies extends Command
foreach ($rlsQueries as $table => $queries) {
foreach ($queries as $type => $query) {
[$hash, $policyQuery] = $this->hashPolicy($query);
$expectedName = $table .'_'.$type.'_rls_policy_' . $hash;
$expectedName = $table . '_' . $type . '_rls_policy_' . $hash;
$tableRLSPolicy = $this->findTableRLSPolicy($table,$type);
$tableRLSPolicy = $this->findTableRLSPolicy($table, $type);
$olderPolicyExists = $tableRLSPolicy && $tableRLSPolicy->policyname !== $expectedName;
// Drop the policy if an outdated version exists
@ -124,7 +124,7 @@ class CreateUserWithRLSPolicies extends Command
}
// Create RLS policy if the table doesn't have it or if the --force option is used
$createPolicy = $dropPolicy || ! $tableRLSPolicy || $this->option('force');
$createPolicy = $dropPolicy || !$tableRLSPolicy || $this->option('force');
if ($createPolicy) {
DB::statement($policyQuery);
@ -138,7 +138,7 @@ class CreateUserWithRLSPolicies extends Command
}
}
if (! empty($createdPolicies)) {
if (!empty($createdPolicies)) {
$managerName = str($rlsPolicyManager::class)->afterLast('\\')->toString();
$this->components->info("RLS policies created for tables (using {$managerName}):");
@ -152,7 +152,7 @@ class CreateUserWithRLSPolicies extends Command
}
/** @return \stdClass|null */
protected function findTableRLSPolicy(string $table): object|null
protected function findTableRLSPolicy(string $table, string $type): object|null
{
return DB::selectOne(<<<SQL
SELECT * FROM pg_policies

View file

@ -249,9 +249,11 @@ class TableRLSManager implements RLSPolicyManager
// -1 because the last item is the tenant table reference which is not a nested where
for ($i = count($path) - 1; $i > 0; $i--) {
$query .= str_repeat(' ', $i * 4) . ")\n";
} // closing for CREATE POLICY
}
return $query . ');';
$query .= ');'; // closing for CREATE POLICY
return $query;
}
protected function getComment(string $tableName, string $columnName): string|null