<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    public function up(): void
    {
        if (Schema::hasTable('budgets') && !Schema::hasColumn('budgets', 'end_date')) {
            Schema::table('budgets', function (Blueprint $table) {
                $table->date('end_date')->nullable()->after('start_date');
            });
        }
    }

    public function down(): void
    {
        if (Schema::hasTable('budgets') && Schema::hasColumn('budgets', 'end_date')) {
            Schema::table('budgets', function (Blueprint $table) {
                $table->dropColumn('end_date');
            });
        }
    }
};
