Skip to content

Commit bbf921d

Browse files
committed
feat: Add indices to foreign key columns
1 parent 0655e31 commit bbf921d

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/database/migrations/2019_12_08_100000_create_analytics_table.php

+4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ public function up()
3131
->references('id')
3232
->on(ServerAnalytics::getAnalyticsDataTable());
3333
$table->morphs('relation');
34+
35+
$table->index('analytics_id');
3436
});
3537

3638
Schema::create(ServerAnalytics::getAnalyticsMetaTable(), function (Blueprint $table) {
@@ -41,6 +43,8 @@ public function up()
4143
->on(ServerAnalytics::getAnalyticsDataTable());
4244
$table->string('key');
4345
$table->text('value')->nullable();
46+
47+
$table->index(['analytics_id', 'key', 'value']);
4448
});
4549
}
4650

src/database/migrations/2020_04_06_100000_add_user_id_to_analytics_table.php

+2
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ public function up()
1414
Schema::table(ServerAnalytics::getAnalyticsDataTable(), function (Blueprint $table) {
1515
$table->unsignedBigInteger('user_id')->nullable()->after('id');
1616
$table->foreign('user_id')->references('id')->on('users');
17+
$table->index('user_id');
1718
});
1819
}
1920

2021
public function down()
2122
{
2223
Schema::table(ServerAnalytics::getAnalyticsDataTable(), function (Blueprint $table) {
24+
$table->dropIndex('user_id');
2325
$table->dropForeign(['user_id']);
2426
$table->dropColumn('user_id');
2527
});

0 commit comments

Comments
 (0)