<?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
    {
        \DB::delete('DELETE t1 FROM user_roles t1
            INNER JOIN user_roles t2 
            WHERE t1.id < t2.id AND t1.user_id = t2.user_id AND t1.role_id = t2.role_id
        ');

        Schema::table('user_roles', function (Blueprint $table)
        {
            $table->unique(['user_id', 'role_id']);
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
    }
};
