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

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

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

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