<?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::hasTable('accounting_vouchers') || Schema::hasColumn('accounting_vouchers', 'source_fingerprint')) {
            return;
        }

        Schema::table('accounting_vouchers', function (Blueprint $table) {
            $table->string('source_fingerprint', 191)->nullable()->unique()->after('source_id');
        });
    }

    public function down(): void
    {
        if (! Schema::hasTable('accounting_vouchers') || ! Schema::hasColumn('accounting_vouchers', 'source_fingerprint')) {
            return;
        }

        Schema::table('accounting_vouchers', function (Blueprint $table) {
            $table->dropColumn('source_fingerprint');
        });
    }
};
