<?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
    {
        // Hapus foreign key dan ubah tipe kolom
        Schema::table('rekomendasi_ahli', function (Blueprint $table) {
            $table->dropForeign(['makanan_id']);
        });

        // Ubah kolom menjadi text (rename lalu tambahkan kembali)
        Schema::table('rekomendasi_ahli', function (Blueprint $table) {
            $table->dropColumn('makanan_id');
        });

        Schema::table('rekomendasi_ahli', function (Blueprint $table) {
            $table->text('makanan_id')->after('id');
        });
    }

    public function down(): void
    {
        // Revert: ubah kembali ke foreign key integer
        Schema::table('rekomendasi_ahli', function (Blueprint $table) {
            $table->dropColumn('makanan_id');
        });

        Schema::table('rekomendasi_ahli', function (Blueprint $table) {
            $table->foreignId('makanan_id')->constrained('makanans')->onDelete('cascade');
        });
    }
};
