File: /var/www/console.fixgini.com/database/migrations/2024_09_09_132802_create_conversations_table.php
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('conversations', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('user_one_id'); // The first user in the conversation
$table->unsignedBigInteger('user_two_id'); // The second user in the conversation (or it could be a group)
// Foreign keys
$table->foreign('user_one_id')->references('id')->on('users')->onDelete('cascade');
$table->foreign('user_two_id')->references('id')->on('users')->onDelete('cascade');
// Ensure that the same pair of users cannot have multiple conversations
$table->unique(['user_one_id', 'user_two_id']);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('conversations');
}
};