Refactor tenant database configuration to use dynamic config values
- Replace hardcoded database names (online_arrahn, master_krk, kaunterpkb) with configurable values across the codebase - Rename tennant_master.php to tennant_database.php for clearer naming - Update config keys: 'database' → 'master_db', add 'kaunter_db' - Update env variables: TENNANT_MASTER_DB and TENNANT_KAUNTER_DB - Modify Helper.php to use dynamic database references in getOnlineArrahnConnection(), getActiveCawanganDbConnection(), and getInactiveCawanganDbConnection() methods - Update database JOIN queries in CustomerController and MarhunController to use config values instead of hardcoded database names - Simplify migration logic by removing redundant hardcoded database checks - Update debug messages in CawanganDebugConnections to show actual configured database name - Update bootstrap/app.php to load tennant_database config This change improves multi-environment flexibility and eliminates environment-specific hardcoded values, making the application more configurable for different deployment scenarios (KRK, KGMK, etc).
This commit is contained in:
@@ -80,7 +80,7 @@ class CawanganDebugConnections extends Command
|
||||
return $idToNameMap[$item['mysql']] !== $item['database'];
|
||||
});
|
||||
} catch (\Throwable $th) {
|
||||
dump(sprintf('Connection %s not found in table online_arrahn.arrahn_master_db but present in config. Make sure both of connection exist in both app/config and arrahn_master_db', $tested_connection));
|
||||
dump(sprintf('Connection %s not found in table %s.arrahn_master_db but present in config. Make sure both of connection exist in both app/config and arrahn_master_db', $tested_connection, config('tennant_database.master_db')));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -12,7 +12,7 @@ class Helper
|
||||
{
|
||||
|
||||
$online_arrahn_connection = array_filter(config('database.connections'), function ($connection) {
|
||||
if ($connection['database'] === 'online_arrahn') {
|
||||
if ($connection['database'] === config('tennant_database.master_db')) {
|
||||
return $connection;
|
||||
}
|
||||
});
|
||||
@@ -43,7 +43,7 @@ class Helper
|
||||
}
|
||||
});
|
||||
|
||||
$non_cawangan_database = ['lelong', 'online_arrahn', 'kaunterpkb'];
|
||||
$non_cawangan_database = ['lelong', config('tennant_database.master_db'), config('tennant_database.kaunter_db')];
|
||||
|
||||
$all_cawangan_db = array_filter($all_active_db_keys, function ($db_key) use ($non_cawangan_database) {
|
||||
$isNotCawangan = in_array(config('database.connections.' . $db_key . '.database'), $non_cawangan_database);
|
||||
@@ -74,7 +74,7 @@ class Helper
|
||||
}
|
||||
});
|
||||
|
||||
$non_cawangan_database = ['lelong', 'online_arrahn', 'kaunterpkb'];
|
||||
$non_cawangan_database = ['lelong', config('tennant_database.master_db'), config('tennant_database.kaunter_db')];
|
||||
|
||||
$all_cawangan_db = array_filter($all_inactive_db_keys, function ($db_key) use ($non_cawangan_database) {
|
||||
$isNotCawangan = in_array(config('database.connections.' . $db_key . '.database'), $non_cawangan_database);
|
||||
|
||||
@@ -720,7 +720,7 @@ class CustomerController extends Controller
|
||||
$customer = Customer::on($cawangan['mysql'])
|
||||
->where('kplama','=',$nokp)
|
||||
->orWhere('kpbaru','=',$nokp)
|
||||
->rightJoin('online_arrahn.bank', 'bank.id', '=', 'customer.kodbank')
|
||||
->rightJoin(config('tennant_database.master_db') . '.bank', 'bank.id', '=', 'customer.kodbank')
|
||||
->first();
|
||||
|
||||
if(!empty($customer))
|
||||
|
||||
@@ -203,7 +203,7 @@ class MarhunController extends Controller
|
||||
$marhun = Marhun::on($cawangan['mysql'])
|
||||
->select('marhun.norujukan','gadai.nokp','customer.nama','marhun.marhun','marhun.nota','marhun.berat','marhun.karat','marhun.harga','marhun.n_marhun','marhun.t_gadai','marhun.tag_permata', 'marhun.berat_batu_permata')
|
||||
->rightJoin('gadai', 'gadai.norujukan', '=', 'marhun.norujukan')
|
||||
->rightJoin('master_krk.customer as customer', 'customer.kpbaru','=','gadai.nokp')
|
||||
->rightJoin(config('tennant_database.master_db') . '.customer as customer', 'customer.kpbaru','=','gadai.nokp')
|
||||
->where('marhun.t_gadai','=',$tarikh)
|
||||
->orderBy('marhun.t_gadai')
|
||||
->get();
|
||||
@@ -221,7 +221,7 @@ class MarhunController extends Controller
|
||||
$marhun = Marhun::on($cawangan['mysql'])
|
||||
->select('marhun.norujukan','gadai.sttebus','gadai.pinjaman','gadai.nokp','customer.nama','marhun.marhun','marhun.nota','marhun.berat','marhun.karat','marhun.harga','marhun.n_marhun','marhun.t_gadai')
|
||||
->rightJoin('gadai', 'gadai.norujukan', '=', 'marhun.norujukan')
|
||||
->rightJoin('master_krk.customer as customer', 'customer.kpbaru','=','gadai.nokp')
|
||||
->rightJoin(config('tennant_database.master_db') . '.customer as customer', 'customer.kpbaru','=','gadai.nokp')
|
||||
->where('marhun.t_gadai','<=',$tarikh)
|
||||
->whereYear('marhun.t_gadai','=',$current->year)
|
||||
->where('gadai.sttebus','=','')
|
||||
|
||||
+1
-1
@@ -61,7 +61,7 @@ $app->singleton(
|
||||
|
||||
$app->configure('app');
|
||||
$app->configure('tinker');
|
||||
$app->configure('tennant_master');
|
||||
$app->configure('tennant_database');
|
||||
$app->configure('report');
|
||||
$app->configure('app_parameter');
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'master_db' => env('TENNANT_MASTER_DB','online_arrahn'),
|
||||
'kaunter_db' => env('TENNANT_KAUNTER_DB','kaunterpkb')
|
||||
];
|
||||
@@ -1,5 +0,0 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'database' => env('TENNANT_MASTER_DB','master_krk')
|
||||
];
|
||||
@@ -42,7 +42,7 @@ class AddColumnsToKomuditiTransaksi extends Migration
|
||||
{
|
||||
$online_arrahn_connection_array = array_filter(config('database.connections'), function($connection) {
|
||||
|
||||
if($connection['database'] === 'online_arrahn' || $connection['database'] === 'master_krk' || $connection['database'] === config('tennant_master.database')){
|
||||
if($connection['database'] === config('tennant_database.master_db')){
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ class AddColumnsToKomuditiTransaksi extends Migration
|
||||
|
||||
|
||||
if(empty($online_arrahn_connection_array)){
|
||||
throw new Exception("online_arrahn or master_krk doesn't exist in config.database.connections array");
|
||||
throw new Exception("Tennant master database (" . config('tennant_database.master_db') . ") doesn't exist in config.database.connections array");
|
||||
}
|
||||
|
||||
return array_keys($online_arrahn_connection_array)[0];
|
||||
|
||||
@@ -11,7 +11,7 @@ $all_active_db_keys = array_filter(array_keys(config('database.connections')), f
|
||||
}
|
||||
});
|
||||
|
||||
$non_cawangan_database = ['lelong', 'online_arrahn', 'kaunterpkb'];
|
||||
$non_cawangan_database = ['lelong', config('tennant_database.master_db'), config('tennant_database.kaunter_db')];
|
||||
|
||||
$all_cawangan_db = array_filter($all_active_db_keys, function($db_key) use($non_cawangan_database){
|
||||
$isNotCawangan = in_array(config('database.connections.' . $db_key . '.database'), $non_cawangan_database);
|
||||
|
||||
Reference in New Issue
Block a user