<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
    public function up()
    {
        Schema::table('materi', function (Blueprint $table) {
            // Tambah primary key gabungan jika belum ada
            $table->dropPrimary(); // Buang primary key lama jika ada
            $table->primary(['id_style', 'id_materi']);

            // Tambah foreign key ke tabel hasil
            $table->foreign('id_style')
                  ->references('id_style')
                  ->on('hasil')
                  ->onDelete('cascade');
        });
    }

    public function down()
    {
        Schema::table('materi', function (Blueprint $table) {
            $table->dropForeign(['id_style']);
            $table->dropPrimary();
        });
    }
};
