Initialer Laravel Commit für BetiX
This commit is contained in:
69
database/migrations/2026_01_01_000004_create_chat_tables.php
Normal file
69
database/migrations/2026_01_01_000004_create_chat_tables.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?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');
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user