mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 15:34:03 +00:00
sqlite: use .sqlite suffix if db.suffix is empty
This commit is contained in:
parent
c6ba62bdd0
commit
836a258a78
1 changed files with 14 additions and 8 deletions
|
|
@ -25,21 +25,21 @@ class DatabaseConfig
|
||||||
/**
|
/**
|
||||||
* Database username generator (can be set by the developer.).
|
* Database username generator (can be set by the developer.).
|
||||||
*
|
*
|
||||||
* @var Closure(Model&Tenant): string
|
* @var Closure(Model&Tenant, self): string
|
||||||
*/
|
*/
|
||||||
public static Closure $usernameGenerator;
|
public static Closure $usernameGenerator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Database password generator (can be set by the developer.).
|
* Database password generator (can be set by the developer.).
|
||||||
*
|
*
|
||||||
* @var Closure(Model&Tenant): string
|
* @var Closure(Model&Tenant, self): string
|
||||||
*/
|
*/
|
||||||
public static Closure $passwordGenerator;
|
public static Closure $passwordGenerator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Database name generator (can be set by the developer.).
|
* Database name generator (can be set by the developer.).
|
||||||
*
|
*
|
||||||
* @var Closure(Model&Tenant): string
|
* @var Closure(Model&Tenant, self): string
|
||||||
*/
|
*/
|
||||||
public static Closure $databaseNameGenerator;
|
public static Closure $databaseNameGenerator;
|
||||||
|
|
||||||
|
|
@ -58,8 +58,14 @@ class DatabaseConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! isset(static::$databaseNameGenerator)) {
|
if (! isset(static::$databaseNameGenerator)) {
|
||||||
static::$databaseNameGenerator = function (Model&Tenant $tenant) {
|
static::$databaseNameGenerator = function (Model&Tenant $tenant, self $self) {
|
||||||
return config('tenancy.database.prefix') . $tenant->getTenantKey() . config('tenancy.database.suffix');
|
$suffix = config('tenancy.database.suffix');
|
||||||
|
|
||||||
|
if (! $suffix && $self->getTemplateConnection()['driver'] === 'sqlite') {
|
||||||
|
$suffix = '.sqlite';
|
||||||
|
}
|
||||||
|
|
||||||
|
return config('tenancy.database.prefix') . $tenant->getTenantKey() . $suffix;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -89,7 +95,7 @@ class DatabaseConfig
|
||||||
|
|
||||||
public function getName(): string
|
public function getName(): string
|
||||||
{
|
{
|
||||||
return $this->tenant->getInternal('db_name') ?? (static::$databaseNameGenerator)($this->tenant);
|
return $this->tenant->getInternal('db_name') ?? (static::$databaseNameGenerator)($this->tenant, $this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getUsername(): ?string
|
public function getUsername(): ?string
|
||||||
|
|
@ -110,8 +116,8 @@ class DatabaseConfig
|
||||||
$this->tenant->setInternal('db_name', $this->getName());
|
$this->tenant->setInternal('db_name', $this->getName());
|
||||||
|
|
||||||
if ($this->connectionDriverManager($this->getTemplateConnectionDriver()) instanceof Contracts\ManagesDatabaseUsers) {
|
if ($this->connectionDriverManager($this->getTemplateConnectionDriver()) instanceof Contracts\ManagesDatabaseUsers) {
|
||||||
$this->tenant->setInternal('db_username', $this->getUsername() ?? (static::$usernameGenerator)($this->tenant));
|
$this->tenant->setInternal('db_username', $this->getUsername() ?? (static::$usernameGenerator)($this->tenant, $this));
|
||||||
$this->tenant->setInternal('db_password', $this->getPassword() ?? (static::$passwordGenerator)($this->tenant));
|
$this->tenant->setInternal('db_password', $this->getPassword() ?? (static::$passwordGenerator)($this->tenant, $this));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->tenant->exists) {
|
if ($this->tenant->exists) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue