diff --git a/src/Bootstrappers/Integrations/PostgresTenancyBootstrapper.php b/src/Bootstrappers/Integrations/PostgresTenancyBootstrapper.php new file mode 100644 index 00000000..0a795ada --- /dev/null +++ b/src/Bootstrappers/Integrations/PostgresTenancyBootstrapper.php @@ -0,0 +1,41 @@ +originalCentralConnectionConfig = $config->get('database.connections.central'); + $this->originalPostgresConfig = $config->get('database.connections.pgsql'); + } + + public function bootstrap(Tenant $tenant): void + { + $this->database->purge('central'); + + $this->config->set('database.connections.pgsql.username', $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')); + } + + public function revert(): void + { + $this->database->purge('central'); + + $this->config->set('database.connections.central', $this->originalCentralConnectionConfig); + $this->config->set('database.connections.pgsql', $this->originalPostgresConfig); + } +}