<?php

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

/**
 * What is appended to the destination URL so a click can be attributed.
 *
 * There was nothing: no column, no default, no way to set one, so every ad
 * published sent traffic to a bare landing page and nothing downstream could
 * tell where it came from. SERP-1833 names it as part of the ad-level intake.
 *
 * Stored as the query string itself rather than as separate source, medium and
 * campaign columns. Meta takes it as one string, buyers write it as one string,
 * and splitting it would only have to be rejoined, losing anything that is not
 * one of the five named parameters.
 *
 * Nullable, and null means nobody was asked: the same distinction the special
 * ad categories column keeps, so a campaign deliberately published untracked
 * stays different from one where the question never came up.
 */
return new class extends Migration
{
    public function up(): void
    {
        Schema::table('campaigns', function (Blueprint $table): void {
            $table->string('utm', 500)->nullable()->after('landing_url');
        });
    }

    public function down(): void
    {
        Schema::table('campaigns', function (Blueprint $table): void {
            $table->dropColumn('utm');
        });
    }
};
