mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 02:34:03 +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();
|
||||
$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';");
|
||||
} catch (QueryException $exception) {
|
||||
// Skip creating Postgres user if it already exists
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,14 +35,13 @@ class DeleteTenantsPostgresUser implements ShouldQueue
|
|||
*/
|
||||
public function handle()
|
||||
{
|
||||
$tenantKey = $this->tenant->getTenantKey();
|
||||
$name = $this->tenant->getTenantKey();
|
||||
|
||||
// Revoke all permissions of a Postgres user before dropping it
|
||||
try {
|
||||
DB::statement("DROP OWNED BY \"{$tenantKey}\";");
|
||||
DB::statement("DROP USER \"{$tenantKey}\";");
|
||||
} catch (QueryException $exception) {
|
||||
// Skip dropping permissions if the user doesn't exist
|
||||
// Skip dropping permissions if the user doesn't exist
|
||||
if (count(DB::select("SELECT usename FROM pg_user WHERE usename = '$name';")) > 0) {
|
||||
DB::statement("DROP OWNED BY \"{$name}\";");
|
||||
DB::statement("DROP USER \"{$name}\";");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue