<?php

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

return new class extends Migration
{
    private string $indexName = 'activation_histories_transaction_id_unique';

    public function up(): void
    {
        if (!Schema::hasTable('activation_histories')) {
            return;
        }

        Schema::table('activation_histories', function (Blueprint $table) {
            $table->unique('transaction_id', $this->indexName);
        });
    }

    public function down(): void
    {
        if (!Schema::hasTable('activation_histories')) {
            return;
        }

        Schema::table('activation_histories', function (Blueprint $table) {
            $table->dropUnique($this->indexName);
        });
    }
};
