<?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
    {
        // Check if column exists before dropping
        if (Schema::hasColumn('m_raw_materials', 'periode_order')) {
            Schema::table('m_raw_materials', function (Blueprint $table) {
                $table->dropColumn('periode_order');
            });
        }
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        // Restore column if needed
        if (!Schema::hasColumn('m_raw_materials', 'periode_order')) {
            Schema::table('m_raw_materials', function (Blueprint $table) {
                $table->string('periode_order', 20)->nullable()->after('tipe_barang');
            });
        }
    }
};
