<?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::create('article_related', function (Blueprint $table) {
            $table->unsignedBigInteger('article_id');
            $table->unsignedBigInteger('related_article_id');
            $table->integer('position')->nullable();
            $table->primary(['article_id', 'related_article_id'], 'PK_article_related');

            $table->foreign('article_id')->references('id')
                ->on('articles')->onDelete('CASCADE')->onUpdate('CASCADE');
            $table->foreign('related_article_id')->references('id')
                ->on('articles')->onDelete('CASCADE')->onUpdate('CASCADE');
        });
    }

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