php/database/migrations/2024_01_01_000005_create_posts_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

31 lines
973 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('posts', function (Blueprint $table) {
$table->id();
$table->foreignId('community_id')->constrained()->onDelete('cascade');
$table->foreignId('user_id')->constrained()->onDelete('cascade');
$table->string('title');
$table->text('content')->nullable();
$table->string('url')->nullable();
$table->enum('type', ['text', 'link', 'image'])->default('text');
$table->integer('votes')->default(0);
$table->timestamps();
$table->index(['community_id', 'created_at']);
$table->index(['user_id', 'created_at']);
});
}
public function down(): void
{
Schema::dropIfExists('posts');
}
};