<?php

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

/**
 * The host's own name in DNS, e.g. fsn-01 → fsn-01.node.clupilot.com.
 *
 * Stored rather than derived, because a derived sequence would shift the moment
 * a host is removed and silently rename its neighbours.
 */
return new class extends Migration
{
    public function up(): void
    {
        Schema::table('hosts', function (Blueprint $table) {
            $table->string('dns_name')->nullable()->unique()->after('name');
            $table->string('dns_record_id')->nullable()->after('dns_name');
        });
    }

    public function down(): void
    {
        Schema::table('hosts', function (Blueprint $table) {
            $table->dropUnique(['dns_name']);
            $table->dropColumn(['dns_name', 'dns_record_id']);
        });
    }
};
