<?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('purchases', function (Blueprint $table) {
            $table->unsignedBigInteger('approval_id')
                ->nullable()
                ->after('withdrawal_id')
                ->comment('연결된 품의서/지출결의서 ID');

            $table->index('approval_id', 'idx_approval');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('purchases', function (Blueprint $table) {
            $table->dropIndex('idx_approval');
            $table->dropColumn('approval_id');
        });
    }
};
