This commit is contained in:
38
database/migrations/2026_02_21_000008_create_chat_tables.php
Normal file
38
database/migrations/2026_02_21_000008_create_chat_tables.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?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->foreignId('user_id')->nullable()->constrained()->nullOnDelete();
|
||||
$table->string('visitor_token')->unique();
|
||||
$table->string('status')->default('open');
|
||||
$table->timestamp('last_message_at')->nullable()->index();
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
Schema::create('chat_messages', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('chat_conversation_id')->constrained('chat_conversations')->cascadeOnDelete();
|
||||
$table->string('sender', 20);
|
||||
$table->text('body');
|
||||
$table->boolean('is_read')->default(false);
|
||||
$table->timestamps();
|
||||
|
||||
$table->index(['chat_conversation_id', 'created_at']);
|
||||
$table->index(['chat_conversation_id', 'sender', 'is_read']);
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('chat_messages');
|
||||
Schema::dropIfExists('chat_conversations');
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user