php/database/migrations/2024_01_01_000006_create_comments_table.php
m1ngsama 34f73d3207 Add database migrations for forum functionality
Created migrations for communities, posts, comments, votes, and user karma tracking.
2025-11-24 10:30:00 +08:00

29 lines
899 B
PHP

<?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('comments', function (Blueprint $table) {
$table->id();
$table->foreignId('post_id')->constrained()->onDelete('cascade');
$table->foreignId('user_id')->constrained()->onDelete('cascade');
$table->foreignId('parent_id')->nullable()->constrained('comments')->onDelete('cascade');
$table->text('content');
$table->integer('votes')->default(0);
$table->timestamps();
$table->index(['post_id', 'created_at']);
$table->index(['parent_id', 'created_at']);
});
}
public function down(): void
{
Schema::dropIfExists('comments');
}
};