<?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('tenants') || ! Schema::hasColumn('tenants', 'workspace_id')) {
            return;
        }

        Schema::table('tenants', function (Blueprint $table): void {
            $table->unique(['id', 'workspace_id'], 'tenants_id_workspace_id_unique');
        });
    }

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

        Schema::table('tenants', function (Blueprint $table): void {
            $table->dropUnique('tenants_id_workspace_id_unique');
        });
    }
};
