Merged in feature-batu-permata (pull request #140)
Feature batu permata
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddBatuPermataToMarhun 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' || $connection == 'lelong')
|
||||
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('marhun', function (Blueprint $table) use ($dbase) {
|
||||
|
||||
$isBatuPermataExist = Schema::connection($dbase)->hasColumn('marhun', 'batu_permata');
|
||||
$isBatuPermataExist = Schema::connection($dbase)->hasColumn('marhun', 'berat_batu_permata');
|
||||
|
||||
if (!$isBatuPermataExist) {
|
||||
$table->string('batu_permata')->nullable();
|
||||
$table->decimal('berat_batu_permata', 7, 2)->nullable();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
$db_connection = $this->getActiveDB();
|
||||
|
||||
foreach ($db_connection as $dbase) {
|
||||
$columns = ['batu_permata', 'berat_batu_permata'];
|
||||
|
||||
|
||||
$columns_exist = array_filter($columns, function ($column) use ($dbase) {
|
||||
return Schema::connection($dbase)->hasColumn('marhun', $column);
|
||||
});
|
||||
|
||||
Schema::connection($dbase)->table('marhun', function (Blueprint $table) use ($columns_exist) {
|
||||
foreach ($columns_exist as $column) {
|
||||
$table->dropColumn($column);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class AlterBatuPermataColumnInMarhunTable 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' || $connection == 'lelong')
|
||||
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) {
|
||||
$isColumnBatuPermataExist = Schema::connection($dbase)->hasColumn('marhun', 'batu_permata');
|
||||
if ($isColumnBatuPermataExist) {
|
||||
Schema::connection($dbase)->table('marhun', function (Blueprint $table) use ($dbase) {
|
||||
$table->dropColumn('batu_permata');
|
||||
});
|
||||
}
|
||||
Schema::connection($dbase)->table('marhun', function (Blueprint $table) use ($dbase) {
|
||||
$table->integer('tag_permata')->default(0);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
$db_connection = $this->getActiveDB();
|
||||
|
||||
foreach ($db_connection as $dbase) {
|
||||
Schema::connection($dbase)->table('marhun', function (Blueprint $table) use ($dbase) {
|
||||
$table->dropColumn('tag_permata');
|
||||
});
|
||||
$isColumnBatuPermataExist = Schema::connection($dbase)->hasColumn('marhun', 'batu_permata');
|
||||
if (!$isColumnBatuPermataExist) {
|
||||
Schema::connection($dbase)->table('marhun', function (Blueprint $table) use ($dbase) {
|
||||
$table->string('batu_permata')->nullable();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
use App\Jemas;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class SortJenisEmas extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
||||
public function run()
|
||||
{
|
||||
Jemas::on('mysql7')->where('marhun', '=', 'G/T')->update([
|
||||
'ordernum' => '1',
|
||||
]);
|
||||
|
||||
Jemas::on('mysql7')->where('marhun', '=', 'CIN')->update([
|
||||
'ordernum' => '2',
|
||||
]);
|
||||
|
||||
Jemas::on('mysql7')->where('marhun', '=', 'R/K')->update([
|
||||
'ordernum' => '3',
|
||||
]);
|
||||
|
||||
Jemas::on('mysql7')->where('marhun', '=', 'SBG')->update([
|
||||
'ordernum' => '4',
|
||||
]);
|
||||
|
||||
Jemas::on('mysql7')->where('marhun', '=', 'L/L')->update([
|
||||
'ordernum' => '5',
|
||||
]);
|
||||
|
||||
Jemas::on('mysql7')->where('marhun', '=', 'LKT')->update([
|
||||
'ordernum' => '6',
|
||||
]);
|
||||
|
||||
Jemas::on('mysql7')->where('marhun', '=', 'R/T')->update([
|
||||
'ordernum' => '7',
|
||||
]);
|
||||
|
||||
Jemas::on('mysql7')->where('marhun', '=', 'K/B')->update([
|
||||
'ordernum' => '8',
|
||||
]);
|
||||
|
||||
Jemas::on('mysql7')->where('marhun', '=', 'DNR')->update([
|
||||
'ordernum' => '9',
|
||||
]);
|
||||
|
||||
Jemas::on('mysql7')->where('marhun', '=', 'SYE')->update([
|
||||
'ordernum' => '10',
|
||||
]);
|
||||
|
||||
Jemas::on('mysql7')->where('marhun', '=', 'WFR')->update([
|
||||
'ordernum' => '11',
|
||||
]);
|
||||
|
||||
Jemas::on('mysql7')->where('marhun', '=', 'G/B')->update([
|
||||
'ordernum' => '12',
|
||||
]);
|
||||
|
||||
Jemas::on('mysql7')->where('marhun', '=', 'SPE')->update([
|
||||
'ordernum' => '13',
|
||||
]);
|
||||
|
||||
Jemas::on('mysql7')->where('marhun', '=', 'R/L')->update([
|
||||
'ordernum' => '14',
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user