mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 11:34:02 +00:00
Swap try/catch for if statements
This commit is contained in:
parent
2d75f185b8
commit
eae4d378f7
2 changed files with 6 additions and 9 deletions
|
|
@ -38,10 +38,8 @@ class CreatePostgresUserForTenant implements ShouldQueue
|
||||||
$name = $this->tenant->getTenantKey();
|
$name = $this->tenant->getTenantKey();
|
||||||
$password = $this->tenant->database()->getPassword() ?? 'password';
|
$password = $this->tenant->database()->getPassword() ?? 'password';
|
||||||
|
|
||||||
try {
|
if (count(DB::select("SELECT usename FROM pg_user WHERE usename = '$name';")) > 0) {
|
||||||
DB::statement("CREATE USER \"$name\" LOGIN PASSWORD '$password';");
|
DB::statement("CREATE USER \"$name\" LOGIN PASSWORD '$password';");
|
||||||
} catch (QueryException $exception) {
|
|
||||||
// Skip creating Postgres user if it already exists
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,14 +35,13 @@ class DeleteTenantsPostgresUser implements ShouldQueue
|
||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
$tenantKey = $this->tenant->getTenantKey();
|
$name = $this->tenant->getTenantKey();
|
||||||
|
|
||||||
// Revoke all permissions of a Postgres user before dropping it
|
// Revoke all permissions of a Postgres user before dropping it
|
||||||
try {
|
// Skip dropping permissions if the user doesn't exist
|
||||||
DB::statement("DROP OWNED BY \"{$tenantKey}\";");
|
if (count(DB::select("SELECT usename FROM pg_user WHERE usename = '$name';")) > 0) {
|
||||||
DB::statement("DROP USER \"{$tenantKey}\";");
|
DB::statement("DROP OWNED BY \"{$name}\";");
|
||||||
} catch (QueryException $exception) {
|
DB::statement("DROP USER \"{$name}\";");
|
||||||
// Skip dropping permissions if the user doesn't exist
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue