<?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_reviews', function (Blueprint $table) {
            $table->ulid('id')->primary();
            $table->foreignUlid('meal_post_id')->constrained('meal_posts')->cascadeOnDelete();
            $table->unsignedTinyInteger('rating');
            $table->text('comment')->nullable();
            $table->foreignUlid('user_id')->nullable()->constrained('users')->nullOnDelete();
            $table->timestamps();
            $table->unique(['meal_post_id', 'user_id']);

        });
    }

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