From 69b49c6ae734c49aa57fc7b8b5fd6c3204e24378 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Sun, 30 Apr 2017 19:09:13 +0300 Subject: [PATCH] Multi-db support --- app/Console/Commands/InitLookup.php | 51 +++++++++++++++++++++++++++++ app/Console/Kernel.php | 1 + app/Models/DbServer.php | 24 ++++++++++++++ config/database.php | 39 ++++++++++++++++++++++ 4 files changed, 115 insertions(+) create mode 100644 app/Console/Commands/InitLookup.php create mode 100644 app/Models/DbServer.php diff --git a/app/Console/Commands/InitLookup.php b/app/Console/Commands/InitLookup.php new file mode 100644 index 0000000000..cf2d95c4eb --- /dev/null +++ b/app/Console/Commands/InitLookup.php @@ -0,0 +1,51 @@ +info(date('Y-m-d') . ' Running InitLookup...'); + + DB::purge(DB::getDefaultConnection()); + DB::Reconnect('db-ninja-0'); + + if (! DbServer::count()) { + DbServer::create(['name' => 'db-ninja-1']); + } + } +} diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 34938ea4c5..2f2eca9da4 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -28,6 +28,7 @@ class Kernel extends ConsoleKernel 'App\Console\Commands\TestOFX', 'App\Console\Commands\MakeModule', 'App\Console\Commands\MakeClass', + 'App\Console\Commands\InitLookup', ]; /** diff --git a/app/Models/DbServer.php b/app/Models/DbServer.php new file mode 100644 index 0000000000..005a19ebb8 --- /dev/null +++ b/app/Models/DbServer.php @@ -0,0 +1,24 @@ + 'InnoDB', ], + 'db-ninja-0' => [ + 'driver' => 'mysql', + 'host' => env('DB_HOST', env('DB_HOST0', 'localhost')), + 'database' => env('DB_DATABASE0', env('DB_DATABASE', 'forge')), + 'username' => env('DB_USERNAME0', env('DB_USERNAME', 'forge')), + 'password' => env('DB_PASSWORD0', env('DB_PASSWORD', '')), + 'charset' => 'utf8', + 'collation' => 'utf8_unicode_ci', + 'prefix' => '', + 'strict' => env('DB_STRICT', false), + 'engine' => 'InnoDB', + ], + + 'db-ninja-1' => [ + 'driver' => 'mysql', + 'host' => env('DB_HOST', env('DB_HOST1', 'localhost')), + 'database' => env('DB_DATABASE1', env('DB_DATABASE', 'forge')), + 'username' => env('DB_USERNAME1', env('DB_USERNAME', 'forge')), + 'password' => env('DB_PASSWORD1', env('DB_PASSWORD', '')), + 'charset' => 'utf8', + 'collation' => 'utf8_unicode_ci', + 'prefix' => '', + 'strict' => env('DB_STRICT', false), + 'engine' => 'InnoDB', + ], + + 'db-ninja-2' => [ + 'driver' => 'mysql', + 'host' => env('DB_HOST', env('DB_HOST2', 'localhost')), + 'database' => env('DB_DATABASE2', env('DB_DATABASE', 'forge')), + 'username' => env('DB_USERNAME2', env('DB_USERNAME', 'forge')), + 'password' => env('DB_PASSWORD2', env('DB_PASSWORD', '')), + 'charset' => 'utf8', + 'collation' => 'utf8_unicode_ci', + 'prefix' => '', + 'strict' => env('DB_STRICT', false), + 'engine' => 'InnoDB', + ], + 'pgsql' => [ 'driver' => 'pgsql', 'host' => env('DB_HOST', 'localhost'),