mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-06 02:54:06 +00:00
Fixing testing
This commit is contained in:
parent
f5f03f8097
commit
0887790ce4
3 changed files with 29 additions and 9 deletions
|
|
@ -6,6 +6,7 @@ namespace Stancl\Tenancy;
|
|||
|
||||
use Closure;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Stancl\Tenancy\Contracts\TenantCannotBeCreatedException;
|
||||
use Illuminate\Database\DatabaseManager as BaseDatabaseManager;
|
||||
use Illuminate\Foundation\Application;
|
||||
use Stancl\Tenancy\Contracts\Future\CanSetConnection;
|
||||
|
|
@ -110,9 +111,9 @@ class DatabaseManager
|
|||
* Get the name of the connection that $connectionName should be based on.
|
||||
*
|
||||
* @param string $connectionName
|
||||
* @return string
|
||||
* @return string|null
|
||||
*/
|
||||
public function getBaseConnection(string $connectionName): string
|
||||
public function getBaseConnection(string $connectionName): ?string
|
||||
{
|
||||
return ($connectionName !== 'tenant' ? $connectionName : null) // 'tenant' is not a specific connection, it's the default
|
||||
?? $this->app['config']['tenancy.database.based_on']
|
||||
|
|
@ -149,6 +150,8 @@ class DatabaseManager
|
|||
* @param Tenant $tenant
|
||||
* @return void
|
||||
* @throws TenantCannotBeCreatedException
|
||||
* @throws DatabaseManagerNotRegisteredException
|
||||
* @throws TenantDatabaseAlreadyExistsException
|
||||
*/
|
||||
public function ensureTenantCanBeCreated(Tenant $tenant): void
|
||||
{
|
||||
|
|
@ -163,6 +166,7 @@ class DatabaseManager
|
|||
* @param Tenant $tenant
|
||||
* @param ShouldQueue[]|callable[] $afterCreating
|
||||
* @return void
|
||||
* @throws DatabaseManagerNotRegisteredException
|
||||
*/
|
||||
public function createDatabase(Tenant $tenant, array $afterCreating = [])
|
||||
{
|
||||
|
|
@ -204,6 +208,7 @@ class DatabaseManager
|
|||
*
|
||||
* @param Tenant $tenant
|
||||
* @return void
|
||||
* @throws DatabaseManagerNotRegisteredException
|
||||
*/
|
||||
public function deleteDatabase(Tenant $tenant)
|
||||
{
|
||||
|
|
@ -226,6 +231,7 @@ class DatabaseManager
|
|||
*
|
||||
* @param Tenant $tenant
|
||||
* @return TenantDatabaseManager
|
||||
* @throws DatabaseManagerNotRegisteredException
|
||||
*/
|
||||
public function getTenantDatabaseManager(Tenant $tenant): TenantDatabaseManager
|
||||
{
|
||||
|
|
|
|||
|
|
@ -4,18 +4,25 @@ declare(strict_types=1);
|
|||
|
||||
namespace Stancl\Tenancy\TenantDatabaseManagers;
|
||||
|
||||
use Illuminate\Database\Connection;
|
||||
use Illuminate\Contracts\Config\Repository;
|
||||
use Illuminate\Database\DatabaseManager as IlluminateDatabaseManager;
|
||||
use Stancl\Tenancy\Contracts\Future\CanSetConnection;
|
||||
use Illuminate\Database\DatabaseManager;
|
||||
use Stancl\Tenancy\Contracts\TenantDatabaseManager;
|
||||
|
||||
class PostgreSQLSchemaManager implements TenantDatabaseManager
|
||||
class PostgreSQLSchemaManager implements TenantDatabaseManager, CanSetConnection
|
||||
{
|
||||
/** @var \Illuminate\Database\Connection */
|
||||
/** @var Connection */
|
||||
protected $database;
|
||||
|
||||
public function __construct(Repository $config, IlluminateDatabaseManager $databaseManager)
|
||||
/** @var string */
|
||||
protected $connection;
|
||||
|
||||
public function __construct(Repository $config, DatabaseManager $databaseManager)
|
||||
{
|
||||
$this->database = $databaseManager->connection($config['tenancy.database_manager_connections.pgsql']);
|
||||
$this->connection = $config['tenancy.database_manager_connections.pgsql'];
|
||||
|
||||
$this->database = $databaseManager->connection($this->connection);
|
||||
}
|
||||
|
||||
public function createDatabase(string $name): bool
|
||||
|
|
@ -32,4 +39,9 @@ class PostgreSQLSchemaManager implements TenantDatabaseManager
|
|||
{
|
||||
return (bool) $this->database->select("SELECT schema_name FROM information_schema.schemata WHERE schema_name = '$name'");
|
||||
}
|
||||
|
||||
public function setConnection(string $connection): void
|
||||
{
|
||||
$this->connection = $connection;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue