diff --git a/src/Jobs/CreatePostgresRoleForTenant.php b/src/Jobs/CreatePostgresRoleForTenant.php new file mode 100644 index 00000000..0f3e9dcb --- /dev/null +++ b/src/Jobs/CreatePostgresRoleForTenant.php @@ -0,0 +1,45 @@ +tenant->getTenantKey(); + $password = $this->tenant->database()->getPassword() ?? 'password'; + + try { + DB::statement("CREATE ROLE \"$name\" LOGIN PASSWORD '$password';"); + } catch (QueryException $exception) { + // Skip creating Postgres role if it already exists + } + } +} diff --git a/src/Jobs/DeleteTenantsPostgresRole.php b/src/Jobs/DeleteTenantsPostgresRole.php new file mode 100644 index 00000000..15151c9a --- /dev/null +++ b/src/Jobs/DeleteTenantsPostgresRole.php @@ -0,0 +1,46 @@ +tenant->getTenantKey(); + + // Revoke all permissions of a role before dropping it + try { + DB::statement("DROP OWNED BY \"{$tenantKey}\";"); + DB::statement("DROP ROLE \"{$tenantKey}\";"); + } catch (QueryException $exception) { + // Skip dropping permissions if the role doesn't exist + } + } +}