mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 21:54:03 +00:00
[2.x] Don't purge central connections (#189)
* Make sure central connections aren't ever purged * Extract setDefaultConnection() * Regression test w/ markTestIncomplete() * Apply fixes from StyleCI
This commit is contained in:
parent
c8a0a58df6
commit
479df83027
2 changed files with 32 additions and 1 deletions
|
|
@ -39,6 +39,7 @@ class DatabaseManager
|
|||
public function connect(Tenant $tenant)
|
||||
{
|
||||
$this->createTenantConnection($tenant->getDatabaseName(), $tenant->getConnectionName());
|
||||
$this->setDefaultConnection($tenant->getConnectionName());
|
||||
$this->switchConnection($tenant->getConnectionName());
|
||||
}
|
||||
|
||||
|
|
@ -49,9 +50,23 @@ class DatabaseManager
|
|||
*/
|
||||
public function reconnect()
|
||||
{
|
||||
// Opposite order to connect() because we don't
|
||||
// want to ever purge the central connection
|
||||
$this->setDefaultConnection($this->originalDefaultConnectionName);
|
||||
$this->switchConnection($this->originalDefaultConnectionName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the default database connection config.
|
||||
*
|
||||
* @param string $connection
|
||||
* @return void
|
||||
*/
|
||||
public function setDefaultConnection(string $connection)
|
||||
{
|
||||
$this->app['config']['database.default'] = $connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the tenant database connection.
|
||||
*
|
||||
|
|
@ -102,7 +117,6 @@ class DatabaseManager
|
|||
*/
|
||||
public function switchConnection(string $connection)
|
||||
{
|
||||
$this->app['config']['database.default'] = $connection;
|
||||
$this->database->purge();
|
||||
$this->database->reconnect($connection);
|
||||
$this->database->setDefaultConnection($connection);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue