<?php

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

// The original create_campaign_events_table migration was edited to add
// node_id after it had already run, so the column never reached the live
// database (Laravel only tracks "has this migration run," not file
// changes since) — same class of bug as the crm_notifications table.
return new class extends Migration
{
    public function up(): void
    {
        if (!Schema::hasColumn('campaign_events', 'node_id')) {
            Schema::table('campaign_events', function (Blueprint $table) {
                $table->string('node_id', 64)->nullable()->after('contact_id');
            });
        }
    }

    public function down(): void
    {
        if (Schema::hasColumn('campaign_events', 'node_id')) {
            Schema::table('campaign_events', function (Blueprint $table) {
                $table->dropColumn('node_id');
            });
        }
    }
};
