fix database migration

This commit is contained in:
Hafifie PKB
2023-11-14 16:07:13 +08:00
parent 7b4ea9b742
commit 5283d87a4e
4 changed files with 113 additions and 3 deletions
@@ -13,6 +13,12 @@ class AddOnepercentToGadaiTable extends Migration
* @return void
*/
/**
*
* @var object $db_connection
*/
public function getActiveDB(){
$config_db = array_keys(config("database.connections"));
@@ -40,6 +46,7 @@ class AddOnepercentToGadaiTable extends Migration
$table->decimal('ujrah', 9, 2);
$table->decimal('onepercent', 9, 2);
$table->decimal('margin_semasa', 5, 2);
$table->tinyInteger('tagbaru')->default(0);
});
}
@@ -56,8 +63,7 @@ class AddOnepercentToGadaiTable extends Migration
foreach($db_connection as $dbase){
Schema::connection($dbase)->table('gadai', function (Blueprint $table) {
// $table->dropColumn('votes');
$table->dropColumn(['kadarujrah', 'ujrah', 'onepercent','margin_semasa']);
$table->dropColumn(['kadarujrah', 'ujrah', 'onepercent','margin_semasa','tagbaru']);
});
}
}
@@ -27,7 +27,8 @@ class AddOnepercentToKadarupahTable extends Migration
public function down()
{
Schema::connection('mysql7')->table('kadarupah', function (Blueprint $table) {
$table->dropColumn(['kadarujrah', 'kadaronepercent']);
$table->dropColumn(['kadarujrah','kadaronepercent']);
});
}
}
@@ -0,0 +1,38 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddOnepercentToTransactionKeuntunganTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::connection('mysql7')->table('transaksi_keuntungan', function (Blueprint $table) {
$table->decimal('ujrah', 5, 2);
$table->decimal('ujrah_rebet', 5, 2);
$table->decimal('onepercent', 5, 2);
$table->decimal('onepercent_rebet', 5, 2);
$table->decimal('tempoh', 5, 2);
$table->decimal('beza_tempoh', 5, 2);
$table->decimal('margin_semasa', 5, 2);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::connection('mysql7')->table('transaksi_keuntungan', function (Blueprint $table) {
$table->dropColumn(['ujrah', 'ujrah_rebet', 'onepercent', 'onepercent_rebet', 'tempoh', 'beza_tempoh', 'margin_semasa']);
});
}
}
@@ -0,0 +1,65 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
class AddOnepercentToTebusTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
/**
*
* @var object $db_connection
*/
public function getActiveDB(){
$config_db = array_keys(config("database.connections"));
$db_connection = array_filter($config_db,function($connection){
try{
if($connection == 'mysql7')
return false;
$db = DB::connection($connection)->getPdo();
return true;
} catch(\Exception $e){
return false;
}
});
return $db_connection;
}
public function up()
{
$db_connection = $this->getActiveDB();
foreach($db_connection as $dbase){
Schema::connection($dbase)->table('tebus', function (Blueprint $table) {
$table->decimal('ujrah', 9, 2);
$table->decimal('onepercent', 9, 2);
});
};
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
$db_connection = $this->getActiveDB();
foreach($db_connection as $dbase){
Schema::connection($dbase)->table('tebus', function (Blueprint $table) {
$table->dropColumn(['ujrah', 'onepercent']);
});
}
}
}