Skip to content

Commit 2f1a70b

Browse files
committed
better indexes
1 parent 844fb02 commit 2f1a70b

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

database/migrations/create_conversations_table.php.stub

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
use Illuminate\Database\Migrations\Migration;
46
use Illuminate\Database\Schema\Blueprint;
57
use Illuminate\Support\Facades\Schema;
@@ -16,11 +18,13 @@ return new class extends Migration
1618
$table->nullableMorphs('conversationable');
1719

1820
$table->foreignId('latest_message_id')->nullable();
19-
$table->datetime('messaged_at')->nullable()->index();
21+
$table->datetime('messaged_at')->nullable();
2022

2123
$table->json('metadata')->nullable();
2224

2325
$table->timestamps();
26+
27+
$table->index(['latest_message_id', 'messaged_at']);
2428
});
2529
}
2630

database/migrations/create_message_reads_table.php.stub

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
use Illuminate\Database\Migrations\Migration;
46
use Illuminate\Database\Schema\Blueprint;
57
use Illuminate\Support\Facades\Schema;

database/migrations/create_messages_table.php.stub

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
use Illuminate\Database\Migrations\Migration;
46
use Illuminate\Database\Schema\Blueprint;
57
use Illuminate\Support\Facades\Schema;
@@ -30,6 +32,8 @@ return new class extends Migration
3032

3133
$table->softDeletes();
3234
$table->timestamps();
35+
36+
$table->index(['conversation_id', 'deleted_at']);
3337
});
3438
}
3539

0 commit comments

Comments
 (0)