<?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('accounts', function (Blueprint $table) {
            $table->unsignedBigInteger('uom_id')->nullable()->after('chart_of_account_id');
            $table->foreign('uom_id')->references('id')->on('uoms')->onDelete('set null');
            $table->index('uom_id');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('accounts', function (Blueprint $table) {
            $table->dropForeign(['uom_id']);
            $table->dropIndex(['uom_id']);
            $table->dropColumn('uom_id');
        });
    }
};
