<?php
/**
 * Migration Class
 *
 * @version     1.0.$Revision:$
 * @version     SVN: $Id:$
 * @package     bplan-base/globals
 * @subpackage  Migrations
 * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
 * @copyright   Copyright (C) 2025, 2026 bplan-solutions GmbH & Co. KG <https://www.bplan-solutions.de/>
 * /Δ\
 */


use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;


/**
 * Migration Class
 *
 * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
 */
return new class extends Migration
{

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('role_has_permissions');

    } // down()


    /**
     * Run the migrations.
     */
    public function up(): void
    {
        if (Schema::hasTable('role_has_permissions') === false) {
            Schema::create('role_has_permissions', function (Blueprint $Table) {
                $Table->foreignId('permission_id')->constrained(table: 'permissions', indexName: 'role_has_permissions_FK_permission_id')->onDelete('cascade');
                $Table->foreignId('role_id')->constrained(table: 'roles', indexName: 'role_has_permissions_FK_role_id')->onDelete('cascade');

                $Table->primary(['permission_id', 'role_id'], 'role_has_permissions_permission_id_role_id_primary');

            });

        }
    } // up()

};
