<?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()
    {
        Schema::table('purchase_histories', function (Blueprint $table) {
            // Hapus kolom teks lama
            $table->dropColumn('supplier_name');
            // Tambahkan kolom ID yang berelasi ke tabel suppliers
            $table->foreignId('supplier_id')->nullable()->constrained('suppliers')->onDelete('set null')->after('unit_cost');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down()
    {
        Schema::table('purchase_histories', function (Blueprint $table) {
            $table->dropForeign(['supplier_id']);
            $table->dropColumn('supplier_id');
            $table->string('supplier_name')->nullable();
        });
    }
};
