mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 04:34:03 +00:00
Supported named in-memory SQLite databases (#69)
This PR adds support for named in-memory SQLite databases, making it feasible to use in-memory SQLite for tenant databases in tests. The usage is simply creating a tenant with 'tenancy_db_name' => ':memory:' and the bootstrapper will automatically update the tenant with a database name derived from its tenant key. There are static property hooks for keeping these DBs alive (at least one connection needs to be open, they don't have process lifetime and are essentially "refcounted") and closing them when the database is deleted. This gives the user control over the lifetimes of these databases.
This commit is contained in:
parent
85bdbd57f7
commit
48b916e182
2 changed files with 95 additions and 5 deletions
|
|
@ -9,6 +9,7 @@ use Illuminate\Contracts\Foundation\Application;
|
|||
use Illuminate\Database\DatabaseManager as BaseDatabaseManager;
|
||||
use Stancl\Tenancy\Contracts\TenantCannotBeCreatedException;
|
||||
use Stancl\Tenancy\Database\Contracts\TenantWithDatabase;
|
||||
use Stancl\Tenancy\Database\TenantDatabaseManagers\SQLiteDatabaseManager;
|
||||
|
||||
/**
|
||||
* @internal Class is subject to breaking changes in minor and patch versions.
|
||||
|
|
@ -71,7 +72,9 @@ class DatabaseManager
|
|||
$manager = $tenant->database()->manager();
|
||||
|
||||
if ($manager->databaseExists($database = $tenant->database()->getName())) {
|
||||
throw new Exceptions\TenantDatabaseAlreadyExistsException($database);
|
||||
if (! $manager instanceof SQLiteDatabaseManager || ! SQLiteDatabaseManager::isInMemory($database)) {
|
||||
throw new Exceptions\TenantDatabaseAlreadyExistsException($database);
|
||||
}
|
||||
}
|
||||
|
||||
if ($manager instanceof Contracts\ManagesDatabaseUsers) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue