Merged in afiqhamzah/feat/add-column-migration-checker (pull request #38)
Add column migration checker
This commit is contained in:
@@ -14,14 +14,14 @@ class AddOnepercentToGadaiTable extends Migration
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @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')
|
||||
@@ -39,17 +39,23 @@ class AddOnepercentToGadaiTable extends Migration
|
||||
public function up()
|
||||
{
|
||||
$db_connection = $this->getActiveDB();
|
||||
|
||||
|
||||
foreach($db_connection as $dbase){
|
||||
Schema::connection($dbase)->table('gadai', function (Blueprint $table) {
|
||||
$table->decimal('kadarujrah', 5, 2);
|
||||
Schema::connection($dbase)->table('gadai', function (Blueprint $table) use($dbase) {
|
||||
|
||||
$isKadarUjrahExist = Schema::connection($dbase)->hasColumn('gadai', 'kadarujrah');
|
||||
|
||||
if(! $isKadarUjrahExist){
|
||||
$table->decimal('kadarujrah', 5, 2);
|
||||
}
|
||||
|
||||
$table->decimal('ujrah', 9, 2);
|
||||
$table->decimal('onepercent', 9, 2);
|
||||
$table->decimal('margin_semasa', 5, 2);
|
||||
$table->tinyInteger('tagbaru')->default(0);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -62,11 +68,18 @@ class AddOnepercentToGadaiTable extends Migration
|
||||
$db_connection = $this->getActiveDB();
|
||||
|
||||
foreach($db_connection as $dbase){
|
||||
if (Schema::connection('mysql7')->hasColumn('kadarujrah', 'ujrah', 'onepercent','margin_semasa','tagbaru')){
|
||||
Schema::connection($dbase)->table('gadai', function (Blueprint $table) {
|
||||
$table->dropColumn(['kadarujrah', 'ujrah', 'onepercent','margin_semasa','tagbaru']);
|
||||
});
|
||||
}
|
||||
$columns = ['kadarujrah', 'ujrah', 'onepercent','margin_semasa','tagbaru'];
|
||||
|
||||
|
||||
$columns_exist = array_filter($columns,function($column) use($dbase){
|
||||
return Schema::connection($dbase)->hasColumn('gadai', $column);
|
||||
});
|
||||
|
||||
Schema::connection($dbase)->table('gadai', function(Blueprint $table) use($columns_exist){
|
||||
foreach($columns_exist as $column){
|
||||
$table->dropColumn($column);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,8 +14,17 @@ class AddOnepercentToKadarupahTable extends Migration
|
||||
public function up()
|
||||
{
|
||||
Schema::connection('mysql7')->table('kadarupah', function (Blueprint $table) {
|
||||
$table->decimal('kadarujrah', 5, 2);
|
||||
$table->decimal('kadaronepercent', 5, 2);
|
||||
|
||||
$isKadarUjrahExist = Schema::connection('mysql7')->hasColumn('kadarupah', 'kadarujrah');
|
||||
$isKadarOnePercentExist = Schema::connection('mysql7')->hasColumn('kadarupah', 'kadaronepercent');
|
||||
|
||||
if (!$isKadarUjrahExist) {
|
||||
$table->decimal('kadarujrah', 5, 2);
|
||||
}
|
||||
if (!$isKadarOnePercentExist) {
|
||||
$table->decimal('kadaronepercent', 5, 2);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@@ -26,8 +35,14 @@ class AddOnepercentToKadarupahTable extends Migration
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::connection('mysql7')->table('kadarupah', function (Blueprint $table) {
|
||||
$table->dropColumn(['kadarujrah','kadaronepercent']);
|
||||
$columns = ['kadarujrah', 'kadaronepercent'];
|
||||
|
||||
$columns_exist = array_filter($columns, function ($column) {
|
||||
return Schema::connection('mysql7')->hasColumn('kadarupah', $column);
|
||||
});
|
||||
|
||||
Schema::connection('mysql7')->table('kadarupah', function (Blueprint $table) use($columns_exist) {
|
||||
$table->dropColumn($columns_exist);
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
+19
-14
@@ -13,15 +13,16 @@ class AddOnepercentToTransactionKeuntunganTable extends Migration
|
||||
*/
|
||||
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);
|
||||
$table->decimal('rounded', 5, 2);
|
||||
$columns = ['ujrah', 'ujrah_rebet', 'onepercent', 'onepercent_rebet', 'tempoh', 'beza_tempoh', 'margin_semasa'];
|
||||
|
||||
$columns_not_exist = array_filter($columns, function ($column) {
|
||||
return !Schema::connection('mysql7')->hasColumn('transaksi_keuntungan', $column);
|
||||
});
|
||||
|
||||
Schema::connection('mysql7')->table('transaksi_keuntungan', function (Blueprint $table) use ($columns_not_exist) {
|
||||
array_walk($columns_not_exist, function ($column) use ($table) {
|
||||
$table->decimal($column, 5, 2);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -32,10 +33,14 @@ class AddOnepercentToTransactionKeuntunganTable extends Migration
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
if (Schema::connection('mysql7')->hasColumn('ujrah', 'onepercent')){
|
||||
Schema::connection('mysql7')->table('transaksi_keuntungan', function (Blueprint $table) {
|
||||
$table->dropColumn(['ujrah', 'ujrah_rebet', 'onepercent', 'onepercent_rebet', 'tempoh', 'beza_tempoh', 'margin_semasa','rounded']);
|
||||
});
|
||||
}
|
||||
$columns = ['ujrah', 'ujrah_rebet', 'onepercent', 'onepercent_rebet', 'tempoh', 'beza_tempoh', 'margin_semasa'];
|
||||
|
||||
$columns_exist = array_filter($columns, function ($column) {
|
||||
return Schema::connection('mysql7')->hasColumn('transaksi_keuntungan', $column);
|
||||
});
|
||||
|
||||
Schema::connection('mysql7')->table('transaksi_keuntungan', function (Blueprint $table) use($columns_exist) {
|
||||
$table->dropColumn($columns_exist);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,35 +14,47 @@ class AddOnepercentToTebusTable extends Migration
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @var object $db_connection
|
||||
*/
|
||||
|
||||
public function getActiveDB(){
|
||||
public function getActiveDB()
|
||||
{
|
||||
$config_db = array_keys(config("database.connections"));
|
||||
|
||||
$db_connection = array_filter($config_db,function($connection){
|
||||
try{
|
||||
if($connection == 'mysql7')
|
||||
|
||||
$db_connection = array_filter($config_db, function ($connection) {
|
||||
try {
|
||||
if ($connection == 'mysql7') {
|
||||
return false;
|
||||
}
|
||||
|
||||
$db = DB::connection($connection)->getPdo();
|
||||
return true;
|
||||
} catch(\Exception $e){
|
||||
} 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);
|
||||
|
||||
foreach ($db_connection as $dbase) {
|
||||
|
||||
$columns = ['ujrah', 'onepercent'];
|
||||
|
||||
$columns_not_exist = array_filter($columns, function ($column) use ($dbase) {
|
||||
return !Schema::connection($dbase)->hasColumn('tebus', $column);
|
||||
});
|
||||
|
||||
Schema::connection($dbase)->table('tebus', function (Blueprint $table) use ($columns_not_exist) {
|
||||
|
||||
array_walk($columns_not_exist, function ($column) use ($table) {
|
||||
$table->decimal($column, 9, 2);
|
||||
});
|
||||
|
||||
});
|
||||
};
|
||||
}
|
||||
@@ -56,12 +68,17 @@ class AddOnepercentToTebusTable extends Migration
|
||||
{
|
||||
$db_connection = $this->getActiveDB();
|
||||
|
||||
foreach($db_connection as $dbase){
|
||||
if (Schema::connection($dbase)->hasColumn('ujrah', 'onepercent')){
|
||||
Schema::connection($dbase)->table('tebus', function (Blueprint $table) {
|
||||
$table->dropColumn(['ujrah', 'onepercent']);
|
||||
});
|
||||
}
|
||||
foreach ($db_connection as $dbase) {
|
||||
|
||||
$columns = ['ujrah', 'onepercent'];
|
||||
|
||||
$columns_exist = array_filter($columns, function ($column) use($dbase) {
|
||||
return Schema::connection($dbase)->hasColumn('tebus', $column);
|
||||
});
|
||||
|
||||
Schema::connection($dbase)->table('tebus', function (Blueprint $table) use ($columns_exist) {
|
||||
$table->dropColumn($columns_exist);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ class AddColumnsToKomuditiTransaksi extends Migration
|
||||
{
|
||||
$online_arrahn_connection_array = array_filter(config('database.connections'), function($connection) {
|
||||
|
||||
if($connection['database'] === 'online_arrahn2' || $connection['database'] === 'master_krk'){
|
||||
if($connection['database'] === 'online_arrahn' || $connection['database'] === 'master_krk'){
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user