mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 21:54:03 +00:00
Make database creation queueable (#17)
* SOLIDify database creation * Return the result of fclose in SQLiteDBCreator * Make database creation queueable * Add DatabaseCreationTest * Make comment more descriptive [ci skip] * Add composer script to copy .env.example to .env * Minor tweaks * Fix env section * Fix DB_PASSWORD for Travis
This commit is contained in:
parent
136862369d
commit
c53a05cff4
13 changed files with 186 additions and 24 deletions
|
|
@ -3,6 +3,7 @@
|
|||
namespace Stancl\Tenancy;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Stancl\Tenancy\Jobs\QueuedDatabaseCreator;
|
||||
use Illuminate\Database\DatabaseManager as BaseDatabaseManager;
|
||||
|
||||
class DatabaseManager
|
||||
|
|
@ -34,14 +35,18 @@ class DatabaseManager
|
|||
{
|
||||
$this->createTenantConnection($name);
|
||||
$driver = $driver ?: $this->getDriver();
|
||||
if ($driver === "sqlite") {
|
||||
$f = fopen(database_path($name), 'w');
|
||||
fclose($f);
|
||||
|
||||
return;
|
||||
|
||||
$databaseCreators = config('tenancy.database_creators');
|
||||
|
||||
if (! array_key_exists($driver, $databaseCreators)) {
|
||||
throw new \Exception("Database could not be created: no database creator for driver $driver is registered.");
|
||||
}
|
||||
|
||||
return DB::statement("CREATE DATABASE `$name` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci");
|
||||
if (config('tenancy.queue_database_creation', false)) {
|
||||
QueuedDatabaseCreator::dispatch(app($databaseCreators[$driver]), $name);
|
||||
} else {
|
||||
app($databaseCreators[$driver])->createDatabase($name);
|
||||
}
|
||||
}
|
||||
|
||||
public function delete()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue