<?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
    {
        Schema::table('field_job_settings', function (Blueprint $table) {
            if (! Schema::hasColumn('field_job_settings', 'queue_segment_id')) {
                $table->foreignId('queue_segment_id')->nullable()->constrained('segments')->nullOnDelete();
            }
        });
    }

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