<?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
{
    if (!Schema::hasTable('challenge_kelas')) {
        Schema::create('challenge_kelas', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('id_challenge');
            $table->unsignedBigInteger('id_kelas');
            $table->timestamps();
            $table->foreign('id_challenge')
                  ->references('id_challenge')
                  ->on('challenges')
                  ->onDelete('cascade');
            $table->foreign('id_kelas')
                  ->references('id_kelas')
                  ->on('kelas')
                  ->onDelete('cascade');
        });
    }
}

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('challenge_kelas');
    }
};
