Files
tehnobox/database/migrations/2026_02_21_000008_create_chat_tables.php
ssww23 93a655235a
Some checks failed
Deploy / deploy (push) Has been cancelled
Initial commit
2026-03-10 00:55:37 +03:00

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');
}
};