From 2461f76e59b9b9a657b7746b1887a69d3c70b3ea Mon Sep 17 00:00:00 2001 From: lukinovec Date: Wed, 24 May 2023 10:50:03 +0200 Subject: [PATCH] Use `$tenant->database()->getUsername()`, default to `$tenant->getTenantKey()` --- src/Bootstrappers/Integrations/PostgresTenancyBootstrapper.php | 3 ++- src/Jobs/CreatePostgresUserForTenant.php | 2 +- src/Jobs/DeleteTenantsPostgresUser.php | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Bootstrappers/Integrations/PostgresTenancyBootstrapper.php b/src/Bootstrappers/Integrations/PostgresTenancyBootstrapper.php index 0e36c7fd..cb202d44 100644 --- a/src/Bootstrappers/Integrations/PostgresTenancyBootstrapper.php +++ b/src/Bootstrappers/Integrations/PostgresTenancyBootstrapper.php @@ -28,8 +28,9 @@ class PostgresTenancyBootstrapper implements TenancyBootstrapper /** @var TenantWithDatabase $tenant */ $this->database->purge('central'); - $this->config->set('database.connections.pgsql.username', $tenant->getTenantKey()); + $this->config->set('database.connections.pgsql.username', $tenant->database()->getUsername() ?? $tenant->getTenantKey()); $this->config->set('database.connections.pgsql.password', $tenant->database()->getPassword() ?? 'password'); + $this->config->set('database.connections.central', $this->config->get('database.connections.pgsql')); } diff --git a/src/Jobs/CreatePostgresUserForTenant.php b/src/Jobs/CreatePostgresUserForTenant.php index 1ecda635..b81c64a8 100644 --- a/src/Jobs/CreatePostgresUserForTenant.php +++ b/src/Jobs/CreatePostgresUserForTenant.php @@ -34,7 +34,7 @@ class CreatePostgresUserForTenant implements ShouldQueue */ public function handle() { - $name = $this->tenant->getTenantKey(); + $name = $this->tenant->database()->getUsername() ?? $this->tenant->getTenantKey(); $password = $this->tenant->database()->getPassword() ?? 'password'; // Create the user only if it doesn't already exist diff --git a/src/Jobs/DeleteTenantsPostgresUser.php b/src/Jobs/DeleteTenantsPostgresUser.php index 81b90c46..6c5e9689 100644 --- a/src/Jobs/DeleteTenantsPostgresUser.php +++ b/src/Jobs/DeleteTenantsPostgresUser.php @@ -34,7 +34,7 @@ class DeleteTenantsPostgresUser implements ShouldQueue */ public function handle() { - $name = $this->tenant->getTenantKey(); + $name = $this->tenant->database()->getUsername() ?? $this->tenant->getTenantKey(); // Revoke all permissions of a Postgres user before dropping it // Skip dropping permissions if the user doesn't exist