Skip to content

Commit e26533f

Browse files
committed
Added new index tables to the database
1 parent bf8ff4a commit e26533f

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::table('tasks', function (Blueprint $table) {
15+
//
16+
});
17+
}
18+
19+
/**
20+
* Reverse the migrations.
21+
*/
22+
public function down(): void
23+
{
24+
Schema::table('tasks', function (Blueprint $table) {
25+
//
26+
});
27+
}
28+
};
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::table('tasks', function (Blueprint $table) {
15+
// Add indexes for frequently queried columns (only if they don't exist)
16+
if (!Schema::hasIndex('tasks', 'tasks_assigned_to_index')) {
17+
$table->index('assigned_to');
18+
}
19+
if (!Schema::hasIndex('tasks', 'tasks_deadline_index')) {
20+
$table->index('deadline');
21+
}
22+
if (!Schema::hasIndex('tasks', 'tasks_assigned_to_status_index')) {
23+
$table->index(['assigned_to', 'status']);
24+
}
25+
if (!Schema::hasIndex('tasks', 'tasks_assigned_to_deadline_index')) {
26+
$table->index(['assigned_to', 'deadline']);
27+
}
28+
});
29+
}
30+
31+
/**
32+
* Reverse the migrations.
33+
*/
34+
public function down(): void
35+
{
36+
Schema::table('tasks', function (Blueprint $table) {
37+
$table->dropIndex(['assigned_to']);
38+
$table->dropIndex(['status']);
39+
$table->dropIndex(['deadline']);
40+
$table->dropIndex(['assigned_to', 'status']);
41+
$table->dropIndex(['assigned_to', 'deadline']);
42+
});
43+
}
44+
};

0 commit comments

Comments
 (0)