<?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('pegawai_pilihan_pelatihan', function (Blueprint $table) {
            $table->id();
            $table->foreignId('pegawai_id')->constrained('pegawai')->cascadeOnDelete();
            $table->foreignId('rekomendasi_pelatihan_id')->constrained('rekomendasi_pelatihan')->cascadeOnDelete();
            $table->unsignedSmallInteger('periode_tahun');
            $table->timestamps();

            $table->unique(['pegawai_id', 'rekomendasi_pelatihan_id', 'periode_tahun'], 'ppp_unique_index');
        });
    }

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