<?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
    {
        Schema::table('settings', function (Blueprint $table) {
            // Drop the old single-column unique index that blocks multiple orgs
            // from sharing the same key name (e.g. 'business_logo').
            $table->dropUnique('settings_key_unique');

            // Composite unique: each org can have its own set of setting keys.
            $table->unique(['key', 'organization_id'], 'settings_key_org_unique');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('settings', function (Blueprint $table) {
            $table->dropUnique('settings_key_org_unique');
            $table->unique('key', 'settings_key_unique');
        });
    }
};
