mirror of
https://github.com/archtechx/tenancy.git
synced 2026-06-21 04:04:03 +00:00
Improve hardening
Make hardening work correctly even for named SQLite DBs, also make the related test test named SQLite DBs instead of just MySQL (the SQLite dataset fails when the DatabaseTenancyBootstrapper changes get reverted).
This commit is contained in:
parent
7972da5475
commit
540e3635e2
2 changed files with 12 additions and 11 deletions
|
|
@ -90,11 +90,11 @@ class DatabaseTenancyBootstrapper implements TenancyBootstrapper
|
|||
protected function verifyTenantCanUseDatabase(Tenant $tenant): void
|
||||
{
|
||||
/** @var \Stancl\Tenancy\Database\Models\Tenant $tenant */
|
||||
$dbName = DB::getDatabaseName();
|
||||
$tenantDbName = $tenant->database()->getName();
|
||||
|
||||
// Check if any other tenant uses this tenant's database
|
||||
if ($tenant::where($tenant->getTenantKeyName(), '!=', $tenant->getTenantKey())
|
||||
->where($tenant::getDataColumn() . '->' . $tenant->internalPrefix() . 'db_name', $dbName)
|
||||
->where($tenant::getDataColumn() . '->' . $tenant->internalPrefix() . 'db_name', $tenantDbName)
|
||||
->exists()) {
|
||||
throw new RuntimeException('Tenant cannot use a database of another tenant.');
|
||||
}
|
||||
|
|
@ -104,7 +104,7 @@ class DatabaseTenancyBootstrapper implements TenancyBootstrapper
|
|||
config('tenancy.database.central_connection', 'central')
|
||||
)->getDatabaseName();
|
||||
|
||||
if ($dbName === $centralDbName) {
|
||||
if (DB::getDatabaseName() === $centralDbName) {
|
||||
throw new RuntimeException('Tenant cannot use the central database.');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue