<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        try {
            Schema::table('platform_settings', function (Blueprint $table): void {
                $table->dropUnique('platform_settings_key_unique');
            });
        } catch (\Throwable) {
            // Some local SQLite databases cannot drop this generated index.
            // MySQL production deployments will use the group/key unique index below.
        }

        Schema::table('platform_settings', function (Blueprint $table): void {
            $table->index('key');
            $table->unique(['group', 'key'], 'platform_settings_group_key_unique');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('platform_settings', function (Blueprint $table): void {
            $table->dropUnique('platform_settings_group_key_unique');
            $table->dropIndex(['key']);
            $table->unique('key');
        });
    }
};
