<?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('post_targets', function (Blueprint $table) {
            $table->id();
            $table->foreignId('post_id')->constrained()->cascadeOnDelete();
            $table->string('target_type', 32);   // artwork | collection
            $table->unsignedBigInteger('target_id');
            $table->timestamp('created_at')->useCurrent();

            $table->index('post_id');
            $table->index(['target_type', 'target_id']);
            $table->unique(['post_id', 'target_type', 'target_id']);
        });
    }

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