Add column migration checker contd
This commit is contained in:
@@ -14,14 +14,14 @@ class AddTunggakanToGadaiTable extends Migration
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @var object $db_connection
|
* @var object $db_connection
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
public function getActiveDB(){
|
public function getActiveDB(){
|
||||||
$config_db = array_keys(config("database.connections"));
|
$config_db = array_keys(config("database.connections"));
|
||||||
|
|
||||||
$db_connection = array_filter($config_db,function($connection){
|
$db_connection = array_filter($config_db,function($connection){
|
||||||
try{
|
try{
|
||||||
if($connection == 'mysql7')
|
if($connection == 'mysql7')
|
||||||
@@ -39,14 +39,23 @@ class AddTunggakanToGadaiTable extends Migration
|
|||||||
public function up()
|
public function up()
|
||||||
{
|
{
|
||||||
$db_connection = $this->getActiveDB();
|
$db_connection = $this->getActiveDB();
|
||||||
|
|
||||||
foreach($db_connection as $dbase){
|
foreach($db_connection as $dbase){
|
||||||
Schema::connection($dbase)->table('gadai', function (Blueprint $table) {
|
Schema::connection($dbase)->table('gadai', function (Blueprint $table) use($dbase) {
|
||||||
$table->decimal('tunggakanujrah', 9, 2);
|
|
||||||
$table->decimal('tunggakanonepercent', 9, 2);
|
$isTunggakanUjrah = Schema::connection($dbase)->hasColumn('gadai', 'tunggakanujrah');
|
||||||
|
$isTunggakkanOnePercent = Schema::connection($dbase)->hasColumn('gadai', 'tunggakanonepercent');
|
||||||
|
|
||||||
|
if (! $isTunggakanUjrah) {
|
||||||
|
$table->decimal('tunggakanujrah', 9, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $isTunggakkanOnePercent) {
|
||||||
|
$table->decimal('tunggakanonepercent', 9, 2);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -66,4 +75,4 @@ class AddTunggakanToGadaiTable extends Migration
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user