mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 21:34:03 +00:00
Add DatabaseCreationTest
This commit is contained in:
parent
c71e639767
commit
f993308b16
8 changed files with 128 additions and 50 deletions
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Stancl\Tenancy\DatabaseCreators;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Stancl\Tenancy\Interfaces\DatabaseCreator;
|
||||
|
||||
class MySQLDatabaseCreator implements DatabaseCreator
|
||||
|
|
|
|||
|
|
@ -2,14 +2,9 @@
|
|||
|
||||
namespace Stancl\Tenancy;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Stancl\Tenancy\Jobs\QueuedDatabaseCreator;
|
||||
use Illuminate\Database\DatabaseManager as BaseDatabaseManager;
|
||||
use Stancl\Tenancy\Interfaces\DatabaseCreator;
|
||||
|
||||
class DatabaseManager
|
||||
{
|
||||
|
|
@ -48,7 +43,7 @@ class DatabaseManager
|
|||
}
|
||||
|
||||
if (config('tenancy.queue_database_creation', false)) {
|
||||
QueuedDatabaseCreator::dispatch(app($databaseCreators[$driver], $name));
|
||||
QueuedDatabaseCreator::dispatch(app($databaseCreators[$driver]), $name);
|
||||
} else {
|
||||
app($databaseCreators[$driver])->createDatabase($name);
|
||||
}
|
||||
|
|
@ -77,31 +72,3 @@ class DatabaseManager
|
|||
config()->set(['database.connections.tenant.database' => $database_name]);
|
||||
}
|
||||
}
|
||||
|
||||
class QueuedDatabaseCreator implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param DatabaseCreator $databaseCreator
|
||||
* @param string $databaseName
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(DatabaseCreator $databaseCreator, string $databaseName)
|
||||
{
|
||||
$this->databaseCreator = $databaseCreator;
|
||||
$this->databaseName = $databaseName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->databaseCreator->createDatabase($databaseName);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
38
src/Jobs/QueuedDatabaseCreator.php
Normal file
38
src/Jobs/QueuedDatabaseCreator.php
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
namespace Stancl\Tenancy\Jobs;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Stancl\Tenancy\Interfaces\DatabaseCreator;
|
||||
|
||||
class QueuedDatabaseCreator implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param DatabaseCreator $databaseCreator
|
||||
* @param string $databaseName
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(DatabaseCreator $databaseCreator, string $databaseName)
|
||||
{
|
||||
$this->databaseCreator = $databaseCreator;
|
||||
$this->databaseName = $databaseName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->databaseCreator->createDatabase($databaseName);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue