<?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::table('peminjaman', function (Blueprint $table) {
            $table->unsignedBigInteger('id_anggota')->nullable()->after('id_peminjaman');
            $table->unsignedBigInteger('id_user')->nullable()->change();
            
            $table->foreign('id_anggota')->references('id')->on('anggotas')->onDelete('set null');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('peminjaman', function (Blueprint $table) {
            $table->dropForeign(['id_anggota']);
            $table->dropColumn('id_anggota');
            $table->unsignedBigInteger('id_user')->nullable(false)->change();
        });
    }
};
