skl/database/migrations/2025_03_11_132906_create_ko...

59 lines
1.9 KiB
PHP

<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('Komponen', function (Blueprint $table) {
$table->id('KomponenId');
$table->unsignedInteger('RefPelaporanId');
$table->unsignedInteger('JenisKomponenId');
$table->unsignedInteger('GroupHasilId')->nullable();
$table->string('Kode', 45);
$table->string('Nama', 255);
$table->tinyInteger('Lampiran');
$table->text('Info')->nullable();
$table->decimal('Bobot', 5, 2)->nullable();
// Menambahkan foreign key untuk relasi dengan tabel RefPelaporan
$table->foreign('RefPelaporanId')
->references('RefPelaporanId')
->on('RefPelaporan')
->onDelete('cascade');
// Menambahkan foreign key untuk relasi dengan tabel JenisKomponen
$table->foreign('JenisKomponenId')
->references('JenisKomponenId')
->on('JenisKomponen')
->onDelete('cascade');
// Menambahkan foreign key untuk relasi dengan tabel GroupHasil (opsional)
$table->foreign('GroupHasilId')
->references('GroupHasilId')
->on('GroupHasil')
->onDelete('cascade');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('Komponen', function (Blueprint $table) {
$table->dropForeign(['RefPelaporanId']);
$table->dropForeign(['JenisKomponenId']);
$table->dropForeign(['GroupHasilId']);
});
Schema::dropIfExists('Komponen');
}
};