mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-13 03:54:02 +00:00
Add command tests
This commit is contained in:
parent
33fcb8a936
commit
e1def355f9
13 changed files with 98 additions and 15 deletions
|
|
@ -7,7 +7,6 @@ use Stancl\Tenancy\DatabaseManager;
|
|||
use Illuminate\Database\Migrations\Migrator;
|
||||
use Stancl\Tenancy\Traits\HasATenantsOption;
|
||||
use Stancl\Tenancy\Traits\DealsWithMigrations;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Illuminate\Database\Console\Migrations\MigrateCommand;
|
||||
|
||||
class Migrate extends MigrateCommand
|
||||
|
|
@ -57,5 +56,7 @@ class Migrate extends MigrateCommand
|
|||
// Migrate
|
||||
parent::handle();
|
||||
});
|
||||
|
||||
$this->database->disconnect();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ use Stancl\Tenancy\DatabaseManager;
|
|||
use Illuminate\Database\Migrations\Migrator;
|
||||
use Stancl\Tenancy\Traits\HasATenantsOption;
|
||||
use Stancl\Tenancy\Traits\DealsWithMigrations;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Illuminate\Database\Console\Migrations\RollbackCommand;
|
||||
|
||||
class Rollback extends RollbackCommand
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ use Illuminate\Console\Command;
|
|||
use Stancl\Tenancy\DatabaseManager;
|
||||
use Stancl\Tenancy\Traits\HasATenantsOption;
|
||||
use Illuminate\Database\Migrations\Migrator;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Illuminate\Database\Console\Seeds\SeedCommand;
|
||||
use Illuminate\Database\ConnectionResolverInterface;
|
||||
|
||||
|
|
|
|||
|
|
@ -9,8 +9,11 @@ use Illuminate\Database\DatabaseManager as BaseDatabaseManager;
|
|||
|
||||
class DatabaseManager
|
||||
{
|
||||
public $originalDefaultConnection;
|
||||
|
||||
public function __construct(BaseDatabaseManager $database)
|
||||
{
|
||||
$this->originalDefaultConnection = config('database.default');
|
||||
$this->database = $database;
|
||||
}
|
||||
|
||||
|
|
@ -28,8 +31,9 @@ class DatabaseManager
|
|||
|
||||
public function disconnect()
|
||||
{
|
||||
$this->database->reconnect('default');
|
||||
$this->database->setDefaultConnection('default');
|
||||
$default_connection = $this->originalDefaultConnection;
|
||||
$this->database->reconnect($default_connection);
|
||||
$this->database->setDefaultConnection($default_connection);
|
||||
}
|
||||
|
||||
public function create(string $name, string $driver = null)
|
||||
|
|
|
|||
|
|
@ -170,6 +170,16 @@ class TenantManager
|
|||
return $tenant;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reconnects to the default database.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function disconnectDatabase()
|
||||
{
|
||||
$this->database->disconnect();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all tenants.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ use Illuminate\Support\Facades\Storage;
|
|||
|
||||
trait BootstrapsTenancy
|
||||
{
|
||||
public $oldStoragePaths = [];
|
||||
public $originalSettings = [];
|
||||
|
||||
public function bootstrap()
|
||||
{
|
||||
|
|
@ -41,7 +41,7 @@ trait BootstrapsTenancy
|
|||
|
||||
public function suffixFilesystemRootPaths()
|
||||
{
|
||||
$old = $this->oldStoragePaths ?: [
|
||||
$old = $this->originalSettings ?: [
|
||||
"storage_disks" => [],
|
||||
"storage_path" => $this->app->storagePath(),
|
||||
];
|
||||
|
|
@ -64,6 +64,6 @@ trait BootstrapsTenancy
|
|||
$old['storage_disks'][$disk] = $root;
|
||||
}
|
||||
|
||||
$this->oldStoragePaths = $old;
|
||||
$this->originalSettings = $old;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,6 @@ trait DealsWithMigrations
|
|||
{
|
||||
protected function getMigrationPaths()
|
||||
{
|
||||
return [database_path('migrations/tenant')];
|
||||
return [config('tenancy.migrations_directory')];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace Stancl\Tenancy\Traits;
|
||||
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
trait HasATenantsOption
|
||||
{
|
||||
protected function getOptions()
|
||||
|
|
|
|||
|
|
@ -41,4 +41,5 @@ return [
|
|||
],
|
||||
'queue_database_creation' => false,
|
||||
'queue_database_deletion' => false,
|
||||
'migrations_directory' => database_path('migrations/tenant'),
|
||||
];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue