mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 17:24:03 +00:00
Make DB storage driver prefix sqlite DBs with database_path()
This commit is contained in:
parent
f87c2b69ec
commit
5edf582269
2 changed files with 17 additions and 3 deletions
|
|
@ -89,9 +89,11 @@ final class DatabaseManager
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDriver(): ?string
|
public function getDriver($connectionName = null): ?string
|
||||||
{
|
{
|
||||||
return config('database.connections.tenant.driver');
|
$connectionName = $connectionName ?: $this->defaultTenantConnectionName;
|
||||||
|
|
||||||
|
return config("database.connections.$connectionName.driver");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createTenantConnection(string $databaseName, string $connectionName = null)
|
public function createTenantConnection(string $databaseName, string $connectionName = null)
|
||||||
|
|
@ -105,7 +107,7 @@ final class DatabaseManager
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Change DB name
|
// Change DB name
|
||||||
$databaseName = $this->getDriver() === 'sqlite' ? database_path($databaseName) : $databaseName;
|
$databaseName = $this->getDriver($connectionName) === 'sqlite' ? database_path($databaseName) : $databaseName;
|
||||||
config()->set(["database.connections.$connectionName.database" => $databaseName]);
|
config()->set(["database.connections.$connectionName.database" => $databaseName]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
namespace Stancl\Tenancy\Tests;
|
namespace Stancl\Tenancy\Tests;
|
||||||
|
|
||||||
|
use Stancl\Tenancy\DatabaseManager;
|
||||||
|
|
||||||
class DatabaseManagerTest extends TestCase
|
class DatabaseManagerTest extends TestCase
|
||||||
{
|
{
|
||||||
public $autoInitTenancy = false;
|
public $autoInitTenancy = false;
|
||||||
|
|
@ -17,4 +19,14 @@ class DatabaseManagerTest extends TestCase
|
||||||
$this->assertSame($old_connection_name, $new_connection_name);
|
$this->assertSame($old_connection_name, $new_connection_name);
|
||||||
$this->assertNotEquals('tenant', $new_connection_name);
|
$this->assertNotEquals('tenant', $new_connection_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
public function db_name_is_prefixed_with_db_path_when_sqlite_is_used()
|
||||||
|
{
|
||||||
|
config(['database.connections.tenant.driver' => 'mysql']);
|
||||||
|
app(DatabaseManager::class)->createTenantConnection('foodb', 'fooconn');
|
||||||
|
|
||||||
|
// make tenant not sqlite so that it has to detect sqlite from fooconn
|
||||||
|
$this->assertSame(config('database.connections.fooconn.database'), database_path('foodb'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue