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

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('m_store_raw_materials', function (Blueprint $table) {
            // Add back delete_flag column if migration is rolled back
            if (!Schema::hasColumn('m_store_raw_materials', 'delete_flag')) {
                $table->integer('delete_flag')->default(0)->after('notes');
            }
        });
    }
};
