mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-14 06:04:03 +00:00
[3.x] DB users (#382)
* Initial draft * Apply fixes from StyleCI * Use CI on master branch too * Pass correct argument to queued DB creators/deleters * Apply fixes from StyleCI * Remove new interface from MySQLDBManager * Make phpunit run * Apply fixes from StyleCI * Fix static property * Default databaseName * Use database transactions for creating users & granting permissions * Apply fixes from StyleCI * Get old tests to pass * Apply fixes from StyleCI * Add tests for PermissionControlledMySQLDatabaseManager * Apply fixes from StyleCI * Write test for extra config, fix bug with extra config * Apply fixes from StyleCI
This commit is contained in:
parent
60665517a0
commit
3bb2759fe2
41 changed files with 756 additions and 286 deletions
|
|
@ -9,6 +9,7 @@ use Illuminate\Database\Connection;
|
|||
use Illuminate\Support\Facades\DB;
|
||||
use Stancl\Tenancy\Contracts\Future\CanSetConnection;
|
||||
use Stancl\Tenancy\Contracts\TenantDatabaseManager;
|
||||
use Stancl\Tenancy\Tenant;
|
||||
|
||||
class MySQLDatabaseManager implements TenantDatabaseManager, CanSetConnection
|
||||
{
|
||||
|
|
@ -20,6 +21,11 @@ class MySQLDatabaseManager implements TenantDatabaseManager, CanSetConnection
|
|||
$this->connection = $config->get('tenancy.database_manager_connections.mysql');
|
||||
}
|
||||
|
||||
public function getSeparator(): string
|
||||
{
|
||||
return 'database';
|
||||
}
|
||||
|
||||
protected function database(): Connection
|
||||
{
|
||||
return DB::connection($this->connection);
|
||||
|
|
@ -30,17 +36,18 @@ class MySQLDatabaseManager implements TenantDatabaseManager, CanSetConnection
|
|||
$this->connection = $connection;
|
||||
}
|
||||
|
||||
public function createDatabase(string $name): bool
|
||||
public function createDatabase(Tenant $tenant): bool
|
||||
{
|
||||
$database = $tenant->database()->getName();
|
||||
$charset = $this->database()->getConfig('charset');
|
||||
$collation = $this->database()->getConfig('collation');
|
||||
|
||||
return $this->database()->statement("CREATE DATABASE `$name` CHARACTER SET `$charset` COLLATE `$collation`");
|
||||
return $this->database()->statement("CREATE DATABASE `{$database}` CHARACTER SET `$charset` COLLATE `$collation`");
|
||||
}
|
||||
|
||||
public function deleteDatabase(string $name): bool
|
||||
public function deleteDatabase(Tenant $tenant): bool
|
||||
{
|
||||
return $this->database()->statement("DROP DATABASE `$name`");
|
||||
return $this->database()->statement("DROP DATABASE `{$tenant->database()->getName()}`");
|
||||
}
|
||||
|
||||
public function databaseExists(string $name): bool
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue