mirror of
https://github.com/openclassify/openclassify.git
synced 2026-04-14 11:12:09 -05:00
43 lines
1.5 KiB
PHP
43 lines
1.5 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('conversations', function (Blueprint $table): void {
|
|
$table->id();
|
|
$table->foreignId('listing_id')->constrained('listings')->cascadeOnDelete();
|
|
$table->foreignId('seller_id')->constrained('users')->cascadeOnDelete();
|
|
$table->foreignId('buyer_id')->constrained('users')->cascadeOnDelete();
|
|
$table->timestamp('last_message_at')->nullable();
|
|
$table->timestamps();
|
|
|
|
$table->unique(['listing_id', 'buyer_id']);
|
|
$table->index(['seller_id', 'last_message_at']);
|
|
$table->index(['buyer_id', 'last_message_at']);
|
|
});
|
|
|
|
Schema::create('conversation_messages', function (Blueprint $table): void {
|
|
$table->id();
|
|
$table->foreignId('conversation_id')->constrained('conversations')->cascadeOnDelete();
|
|
$table->foreignId('sender_id')->constrained('users')->cascadeOnDelete();
|
|
$table->text('body');
|
|
$table->timestamp('read_at')->nullable();
|
|
$table->timestamps();
|
|
|
|
$table->index(['conversation_id', 'created_at']);
|
|
$table->index(['conversation_id', 'read_at']);
|
|
});
|
|
}
|
|
|
|
public function down(): void
|
|
{
|
|
Schema::dropIfExists('conversation_messages');
|
|
Schema::dropIfExists('conversations');
|
|
}
|
|
};
|