Skip to content

Commit 5a691ae

Browse files
committed
adds created_at index
1 parent e993983 commit 5a691ae

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

database/migrations/2017_01_01_112600_create_favorite_files_table.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
use Illuminate\Database\Schema\Blueprint;
55
use Illuminate\Support\Facades\Schema;
66

7-
return new class extends Migration
8-
{
7+
return new class extends Migration {
98
public function up()
109
{
1110
Schema::create('favorite_files', function (Blueprint $table) {
@@ -21,6 +20,7 @@ public function up()
2120
$table->timestamps();
2221

2322
$table->unique(['user_id', 'file_id']);
23+
$table->index(['created_at']);
2424
});
2525
}
2626

src/Upgrades/CreatedAtIndex.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace LaravelEnso\Files\Upgrades;
4+
5+
use Illuminate\Support\Facades\Schema;
6+
use LaravelEnso\Upgrade\Contracts\BeforeMigration;
7+
use LaravelEnso\Upgrade\Contracts\MigratesTable;
8+
use LaravelEnso\Upgrade\Helpers\Table;
9+
10+
class CreatedAtIndex implements MigratesTable, BeforeMigration
11+
{
12+
public function isMigrated(): bool
13+
{
14+
return Table::hasIndex('files', 'files_created_at_index');
15+
}
16+
17+
public function migrateTable(): void
18+
{
19+
Schema::table('files', fn ($table) => $table->index(['created_at']));
20+
}
21+
}

0 commit comments

Comments
 (0)