<?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('categoria_contabile', function (Blueprint $table) {
            $table->bigInteger('attivita_id')->unsigned()->nullable()->after('id');
            $table->foreign('attivita_id')->references('id')->on('attivita')->onDelete('cascade');
            // $table->dropUnique(['nome']);
            $table->unique(['attivita_id', 'nome']);
        });
    }

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