<?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('project_updates', function (Blueprint $table) {
            $table->id();
            $table->foreignId('project_id')->constrained()->cascadeOnDelete();
            $table->foreignId('posted_by')->constrained('users');
            $table->string('title');
            $table->text('body');
            $table->string('image_path')->nullable();
            $table->boolean('is_pinned')->default(false);
            $table->timestamps();

            $table->index(['project_id', 'is_pinned']);
        });
    }

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