mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-09 20:52:56 +01:00
Multi-db support
This commit is contained in:
parent
02e0a38d11
commit
69b49c6ae7
51
app/Console/Commands/InitLookup.php
Normal file
51
app/Console/Commands/InitLookup.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use DB;
|
||||
use App\Models\DbServer;
|
||||
|
||||
class InitLookup extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'ninja:init-lookup';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Initialize lookup tables';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->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']);
|
||||
}
|
||||
}
|
||||
}
|
@ -28,6 +28,7 @@ class Kernel extends ConsoleKernel
|
||||
'App\Console\Commands\TestOFX',
|
||||
'App\Console\Commands\MakeModule',
|
||||
'App\Console\Commands\MakeClass',
|
||||
'App\Console\Commands\InitLookup',
|
||||
];
|
||||
|
||||
/**
|
||||
|
24
app/Models/DbServer.php
Normal file
24
app/Models/DbServer.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Eloquent;
|
||||
|
||||
/**
|
||||
* Class ExpenseCategory.
|
||||
*/
|
||||
class DbServer extends Eloquent
|
||||
{
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public $timestamps = false;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name',
|
||||
];
|
||||
|
||||
}
|
@ -65,6 +65,45 @@ return [
|
||||
'engine' => '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'),
|
||||
|
Loading…
Reference in New Issue
Block a user