1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-05 16:34:04 +00:00

Set Internal DB Connection Name

This commit is contained in:
Bogdan Kharchenko 2021-10-15 17:19:49 -04:00
parent 20e1fa1959
commit 77248089af

View file

@ -78,6 +78,11 @@ class DatabaseConfig
return $this->tenant->getInternal('db_password') ?? null; return $this->tenant->getInternal('db_password') ?? null;
} }
public function getDbConnectionName(): ?string
{
return $this->tenant->getInternal('db_connection') ?? null;
}
/** /**
* Generate DB name, username & password and write them to the tenant model. * Generate DB name, username & password and write them to the tenant model.
* *
@ -86,6 +91,7 @@ class DatabaseConfig
public function makeCredentials(): void public function makeCredentials(): void
{ {
$this->tenant->setInternal('db_name', $this->getName() ?? (static::$databaseNameGenerator)($this->tenant)); $this->tenant->setInternal('db_name', $this->getName() ?? (static::$databaseNameGenerator)($this->tenant));
$this->tenant->setInternal('db_connection', $this->getTemplateConnectionName());
if ($this->manager() instanceof ManagesDatabaseUsers) { if ($this->manager() instanceof ManagesDatabaseUsers) {
$this->tenant->setInternal('db_username', $this->getUsername() ?? (static::$usernameGenerator)($this->tenant)); $this->tenant->setInternal('db_username', $this->getUsername() ?? (static::$usernameGenerator)($this->tenant));
@ -99,7 +105,7 @@ class DatabaseConfig
public function getTemplateConnectionName(): string public function getTemplateConnectionName(): string
{ {
return $this->tenant->getInternal('db_connection') return $this->getDbConnectionName()
?? config('tenancy.database.template_tenant_connection') ?? config('tenancy.database.template_tenant_connection')
?? config('tenancy.database.central_connection'); ?? config('tenancy.database.central_connection');
} }