39 lines
1.3 KiB
PHP
39 lines
1.3 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
|
|
{
|
|
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');
|
|
}
|
|
};
|