Files
BetiX/database/migrations/2026_01_01_000004_create_chat_tables.php
Dolo 0280278978
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (8.4) (push) Has been cancelled
tests / ci (8.5) (push) Has been cancelled
Initialer Laravel Commit für BetiX
2026-04-04 18:01:50 +02:00

70 lines
2.9 KiB
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
{
// ---------------------------------------------------------------
// CHAT MESSAGES
// ---------------------------------------------------------------
Schema::create('chat_messages', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
$table->foreignId('reply_to_id')->nullable()->constrained('chat_messages')->nullOnDelete();
$table->text('message'); // Stored encrypted
$table->boolean('is_deleted')->default(false);
$table->unsignedBigInteger('deleted_by')->nullable(); // user_id of moderator/admin
$table->timestamps();
$table->index(['created_at']);
$table->index('reply_to_id');
$table->index(['user_id', 'created_at']);
});
// ---------------------------------------------------------------
// CHAT MESSAGE REACTIONS
// ---------------------------------------------------------------
Schema::create('chat_message_reactions', function (Blueprint $table) {
$table->id();
$table->foreignId('message_id')->constrained('chat_messages')->cascadeOnDelete();
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
$table->string('emoji', 16);
$table->timestamps();
$table->unique(['message_id', 'user_id', 'emoji'], 'uniq_reaction');
$table->index(['message_id', 'user_id']);
});
// ---------------------------------------------------------------
// CHAT MESSAGE REPORTS
// ---------------------------------------------------------------
Schema::create('chat_message_reports', function (Blueprint $table) {
$table->id();
$table->foreignId('reporter_id')->constrained('users')->cascadeOnDelete();
$table->string('message_id');
$table->text('message_text');
$table->unsignedBigInteger('sender_id')->nullable();
$table->string('sender_username')->nullable();
$table->string('reason')->nullable();
$table->json('context_messages')->nullable(); // Previous messages for context
$table->enum('status', ['pending', 'reviewed', 'dismissed'])->default('pending');
$table->text('admin_note')->nullable();
$table->timestamps();
$table->index('reporter_id');
$table->index('status');
});
}
public function down(): void
{
Schema::dropIfExists('chat_message_reports');
Schema::dropIfExists('chat_message_reactions');
Schema::dropIfExists('chat_messages');
}
};