<?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::hasColumn('serenatas', 'serenata_package_id')) {
            Schema::table('serenatas', function (Blueprint $table) {
                $table->foreignId('serenata_package_id')
                    ->nullable()
                    ->after('mariachi_group_id')
                    ->constrained('serenata_packages')
                    ->nullOnDelete();
            });
        }
    }

    public function down(): void
    {
        if (Schema::hasColumn('serenatas', 'serenata_package_id')) {
            Schema::table('serenatas', function (Blueprint $table) {
                $table->dropConstrainedForeignId('serenata_package_id');
            });
        }
    }
};

