From 61b0c6094fecb88bea063b83ab113b175d10d75e Mon Sep 17 00:00:00 2001 From: Tareq Hasan Date: Sun, 16 Aug 2020 12:01:11 +0800 Subject: [PATCH] Added index on short_url and user_id MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The clicks and URLs table doesn’t have necessary index on short_url, which is required for a faster DB query. --- ...0_08_16_035000_add_index_to_urls_table.php | 34 +++++++++++++++++++ ...08_16_035242_add_index_to_clicks_table.php | 32 +++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 database/migrations/2020_08_16_035000_add_index_to_urls_table.php create mode 100644 database/migrations/2020_08_16_035242_add_index_to_clicks_table.php diff --git a/database/migrations/2020_08_16_035000_add_index_to_urls_table.php b/database/migrations/2020_08_16_035000_add_index_to_urls_table.php new file mode 100644 index 00000000..5e855e38 --- /dev/null +++ b/database/migrations/2020_08_16_035000_add_index_to_urls_table.php @@ -0,0 +1,34 @@ +index('short_url'); + $table->index('user_id'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('urls', function (Blueprint $table) { + $table->dropIndex('short_url'); + $table->dropIndex('user_id'); + }); + } +} diff --git a/database/migrations/2020_08_16_035242_add_index_to_clicks_table.php b/database/migrations/2020_08_16_035242_add_index_to_clicks_table.php new file mode 100644 index 00000000..fa0c33ec --- /dev/null +++ b/database/migrations/2020_08_16_035242_add_index_to_clicks_table.php @@ -0,0 +1,32 @@ +index('short_url'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('clicks', function (Blueprint $table) { + $table->dropIndex('short_url'); + }); + } +}