Skip to content

Commit

Permalink
feat: Add indices to foreign key columns
Browse files Browse the repository at this point in the history
  • Loading branch information
owenconti committed May 5, 2022
1 parent 0655e31 commit bbf921d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public function up()
->references('id')
->on(ServerAnalytics::getAnalyticsDataTable());
$table->morphs('relation');

$table->index('analytics_id');
});

Schema::create(ServerAnalytics::getAnalyticsMetaTable(), function (Blueprint $table) {
Expand All @@ -41,6 +43,8 @@ public function up()
->on(ServerAnalytics::getAnalyticsDataTable());
$table->string('key');
$table->text('value')->nullable();

$table->index(['analytics_id', 'key', 'value']);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ public function up()
Schema::table(ServerAnalytics::getAnalyticsDataTable(), function (Blueprint $table) {
$table->unsignedBigInteger('user_id')->nullable()->after('id');
$table->foreign('user_id')->references('id')->on('users');
$table->index('user_id');
});
}

public function down()
{
Schema::table(ServerAnalytics::getAnalyticsDataTable(), function (Blueprint $table) {
$table->dropIndex('user_id');
$table->dropForeign(['user_id']);
$table->dropColumn('user_id');
});
Expand Down

0 comments on commit bbf921d

Please sign in to comment.