game-village-politics-backend/database/migrations/2026_10_31_180000_create_ch...

37 lines
1.3 KiB
PHP

<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
// Chat on a world: one channel for everyone, one per tribe, one per pair of players.
return new class extends Migration
{
public function up(): void
{
Schema::create('chat_messages', function (Blueprint $table) {
$table->id();
$table->foreignId('world_id')->constrained()->cascadeOnDelete();
// world, tribe:<id>, or dm:<lower player id>:<higher player id>
$table->string('channel', 40);
$table->foreignId('player_id')->constrained()->cascadeOnDelete();
$table->text('body');
$table->dateTime('created_at', 3);
$table->index(['world_id', 'channel', 'id']);
});
Schema::create('chat_reads', function (Blueprint $table) {
$table->id();
$table->foreignId('player_id')->constrained()->cascadeOnDelete();
$table->string('channel', 40);
$table->unsignedBigInteger('last_id');
$table->unique(['player_id', 'channel']);
});
}
public function down(): void
{
Schema::dropIfExists('chat_reads');
Schema::dropIfExists('chat_messages');
}
};