mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 14:14:03 +00:00
Add support for postgres schema
This commit is contained in:
parent
fd00be646e
commit
2ff3dd4283
5 changed files with 127 additions and 2 deletions
|
|
@ -100,7 +100,12 @@ class DatabaseManager
|
|||
|
||||
// Change database name.
|
||||
$databaseName = $this->getDriver($connectionName) === 'sqlite' ? database_path($databaseName) : $databaseName;
|
||||
$this->app['config']["database.connections.$connectionName.database"] = $databaseName;
|
||||
|
||||
if ($this->isUsingSchema($connectionName)) {
|
||||
$this->app['config']["database.connections.$connectionName.schema"] = $databaseName;
|
||||
} else {
|
||||
$this->app['config']["database.connections.$connectionName.database"] = $databaseName;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -226,7 +231,7 @@ class DatabaseManager
|
|||
*/
|
||||
public function getTenantDatabaseManager(Tenant $tenant): TenantDatabaseManager
|
||||
{
|
||||
$driver = $this->getDriver($this->getBaseConnection($tenant->getConnectionName()));
|
||||
$driver = $this->isUsingSchema($tenant->getConnectionName()) ? 'schema' : $this->getDriver($this->getBaseConnection($tenant->getConnectionName()));
|
||||
|
||||
$databaseManagers = $this->app['config']['tenancy.database_managers'];
|
||||
|
||||
|
|
@ -236,4 +241,15 @@ class DatabaseManager
|
|||
|
||||
return $this->app[$databaseManagers[$driver]];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if using schema connection
|
||||
*
|
||||
* @param string $connectionName
|
||||
* @return bool
|
||||
*/
|
||||
protected function isUsingSchema(string $connectionName): bool
|
||||
{
|
||||
return $this->getDriver($this->getBaseConnection($connectionName)) === 'pgsql' && $this->app['config']['tenancy.using_schema_connection'];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue