<?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
    {
        Schema::create('stories_tag_relation', function (Blueprint $table) {
            $table->foreignId('story_id')->constrained('stories')->cascadeOnDelete();
            $table->foreignId('tag_id')->constrained('stories_tags')->cascadeOnDelete();
            $table->primary(['story_id', 'tag_id']);

            $table->index('story_id');
            $table->index('tag_id');
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('stories_tag_relation');
    }
};
