1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-13 09:44:03 +00:00

Merge hotfix branch (#834)

* try specifying the signature in __construct

* constructor doesn't work since Reflection is used, try specifying getDefaultName() instead

* Fixed: make migration commands compatible

* Fix failing tests

* Fix username generation

* Re-create tmp dir as well if needed

* wip
This commit is contained in:
Samuel Štancl 2022-03-30 18:00:55 +02:00 committed by GitHub
parent 4f19609797
commit 349125c02e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 75 additions and 27 deletions

View file

@ -7,10 +7,12 @@ namespace Stancl\Tenancy\Database;
use Illuminate\Config\Repository;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Database\DatabaseManager as BaseDatabaseManager;
use Stancl\Tenancy\Contracts\ManagesDatabaseUsers;
use Stancl\Tenancy\Contracts\TenantCannotBeCreatedException;
use Stancl\Tenancy\Contracts\TenantWithDatabase;
use Stancl\Tenancy\Exceptions\DatabaseManagerNotRegisteredException;
use Stancl\Tenancy\Exceptions\TenantDatabaseAlreadyExistsException;
use Stancl\Tenancy\Exceptions\TenantDatabaseUserAlreadyExistsException;
/**
* @internal Class is subject to breaking changes in minor and patch versions.
@ -90,8 +92,14 @@ class DatabaseManager
*/
public function ensureTenantCanBeCreated(TenantWithDatabase $tenant): void
{
if ($tenant->database()->manager()->databaseExists($database = $tenant->database()->getName())) {
$manager = $tenant->database()->manager();
if ($manager->databaseExists($database = $tenant->database()->getName())) {
throw new TenantDatabaseAlreadyExistsException($database);
}
if ($manager instanceof ManagesDatabaseUsers && $manager->userExists($username = $tenant->database()->getUsername())) {
throw new TenantDatabaseUserAlreadyExistsException($username);
}
}
}