Tukar step pampasan v3 ke v2:

This commit is contained in:
aiman
2025-09-14 15:54:31 +08:00
committed by Afiq Hamzah
parent 1f27d90698
commit 977fab853d
6 changed files with 205 additions and 16 deletions
@@ -69,10 +69,10 @@ class AddNmJbgUntungPembiayaanColumnsToPalsuTable extends Migration
// Add index and foreign key constraint to existing norujukan column
if (Schema::connection($dbase)->hasColumn('palsu', 'norujukan')) {
// Add index to norujukan column for better performance
$table->index('norujukan');
// $table->index('norujukan');
// Add foreign key constraint named 'norujukan'
$table->foreign('norujukan', 'norujukan')->references('norujukan')->on('gadai');
// $table->foreign('norujukan', 'norujukan')->references('norujukan')->on('gadai');
}
});
@@ -87,21 +87,21 @@ class AddNmJbgUntungPembiayaanColumnsToPalsuTable extends Migration
Schema::connection($dbase)->table('palsu', function (Blueprint $table) use ($dbase) {
// Drop foreign key constraint and index from norujukan column
if (Schema::connection($dbase)->hasColumn('palsu', 'norujukan')) {
try {
$table->dropForeign('norujukan');
echo "Dropped foreign key 'norujukan' on connection '{$dbase}'\n";
} catch (\Exception $e) {
echo "Warning: Could not drop foreign key 'norujukan' on connection '{$dbase}': " . $e->getMessage() . "\n";
}
// if (Schema::connection($dbase)->hasColumn('palsu', 'norujukan')) {
// try {
// $table->dropForeign('norujukan');
// echo "Dropped foreign key 'norujukan' on connection '{$dbase}'\n";
// } catch (\Exception $e) {
// echo "Warning: Could not drop foreign key 'norujukan' on connection '{$dbase}': " . $e->getMessage() . "\n";
// }
try {
$table->dropIndex(['norujukan']);
echo "Dropped index on 'norujukan' column on connection '{$dbase}'\n";
} catch (\Exception $e) {
echo "Warning: Could not drop index on 'norujukan' on connection '{$dbase}': " . $e->getMessage() . "\n";
}
}
// try {
// $table->dropIndex(['norujukan']);
// echo "Dropped index on 'norujukan' column on connection '{$dbase}'\n";
// } catch (\Exception $e) {
// echo "Warning: Could not drop index on 'norujukan' on connection '{$dbase}': " . $e->getMessage() . "\n";
// }
// }
// Drop other columns if they exist
$columnsToCheck = ['nilaimarhun', 'jbg', 'untung','untungonepercent','untungcajlain', 'pembiayaan'];
@@ -0,0 +1,57 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;
class CreatePampasanTable extends Migration
{
private function getActiveDB(): array
{
$config_db = array_keys(config('database.connections'));
$db_connection = array_filter($config_db, function ($connection) {
try {
if ($connection === 'mysql7') return false; // ikut pattern sedia ada
DB::connection($connection)->select('SELECT 1');
return true;
} catch (\Exception $e) {
return false;
}
});
return $db_connection ? array_values($db_connection) : [];
}
public function up()
{
foreach ($this->getActiveDB() as $dbase) {
if (!Schema::connection($dbase)->hasTable('pampasan')) {
Schema::connection($dbase)->create('pampasan', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('norujukan', 50)->unique()->index();
$table->string('baucerno', 30)->index();
$table->string('kodcaw', 20)->index();
$table->decimal('jumlah_pampasan', 11, 2);
if (Schema::getConnection()->getPdo()->getAttribute(PDO::ATTR_SERVER_VERSION) >= '5.7') {
$table->json('denominasi')->nullable();
} else {
$table->longText('denominasi')->nullable();
}
$table->string('teller', 100);
$table->tinyInteger('status')
->default(0)
->comment('0 = belum dituntut, 1 = dituntut');
$table->timestamps();
});
}
}
}
public function down()
{
foreach ($this->getActiveDB() as $dbase) {
Schema::connection($dbase)->dropIfExists('pampasan');
}
}
}