inhaus-plugin-chat/database/migrations/2026_10_21_000001_create_chat_tables.php
Friederich Loheide 2844452002 Nachrichten-Plugin 1.0.0: Direktnachrichten, Gruppen, Anhänge, GIFs, Emojis
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-27 16:34:53 +00:00

91 lines
4.1 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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('chat_conversations', function (Blueprint $table) {
$table->id();
$table->string('type', 10); // direct | group
$table->string('name', 100)->nullable();
// Direktnachrichten: „kleinere-ID:größere-ID“ – je Paar genau ein Gespräch
$table->string('direct_key', 50)->nullable()->unique();
$table->foreignId('created_by')->nullable()->constrained('users')->nullOnDelete();
$table->unsignedBigInteger('last_message_id')->nullable();
$table->timestamp('last_message_at')->nullable()->index();
$table->timestamps();
});
Schema::create('chat_participants', function (Blueprint $table) {
$table->foreignId('conversation_id')->constrained('chat_conversations')->cascadeOnDelete();
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
$table->string('role', 10)->default('member'); // member | admin
$table->unsignedBigInteger('last_read_message_id')->nullable();
$table->unsignedBigInteger('notified_message_id')->nullable();
$table->boolean('muted')->default(false);
$table->timestamp('joined_at')->nullable();
$table->timestamp('left_at')->nullable();
$table->primary(['conversation_id', 'user_id']);
$table->index(['user_id', 'left_at']);
});
Schema::create('chat_messages', function (Blueprint $table) {
$table->id();
$table->foreignId('conversation_id')->constrained('chat_conversations')->cascadeOnDelete();
$table->foreignId('user_id')->nullable()->constrained()->nullOnDelete();
$table->string('kind', 10)->default('text'); // text | gif | system
$table->text('body')->nullable();
$table->string('gif_url', 500)->nullable();
$table->foreignId('reply_to_id')->nullable()->constrained('chat_messages')->nullOnDelete();
$table->timestamp('edited_at')->nullable();
$table->timestamp('deleted_at')->nullable();
// updated_at: auch bei Reaktionen – so holt die Abfrage geänderte Nachrichten nach
$table->timestamps();
$table->index(['conversation_id', 'id']);
$table->index(['conversation_id', 'updated_at']);
});
Schema::create('chat_attachments', function (Blueprint $table) {
$table->id();
$table->foreignId('message_id')->constrained('chat_messages')->cascadeOnDelete();
$table->string('path', 300);
$table->string('name', 200);
$table->string('mime', 100);
$table->unsignedBigInteger('size');
$table->unsignedInteger('width')->nullable();
$table->unsignedInteger('height')->nullable();
});
Schema::create('chat_reactions', function (Blueprint $table) {
$table->foreignId('message_id')->constrained('chat_messages')->cascadeOnDelete();
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
$table->string('emoji', 16);
$table->primary(['message_id', 'user_id', 'emoji']);
});
// Eigene GIF-Sammlung (von der Administration hochgeladen)
Schema::create('chat_gifs', function (Blueprint $table) {
$table->id();
$table->string('path', 300);
$table->string('title', 100);
$table->string('tags', 300)->nullable();
$table->unsignedInteger('width')->nullable();
$table->unsignedInteger('height')->nullable();
$table->timestamps();
});
}
public function down(): void
{
foreach (['chat_gifs', 'chat_reactions', 'chat_attachments', 'chat_messages', 'chat_participants', 'chat_conversations'] as $table) {
Schema::dropIfExists($table);
}
}
};