diff options
author | Chaoyi Zha <summermontreal@gmail.com> | 2017-02-04 07:12:47 +0300 |
---|---|---|
committer | Chaoyi Zha <summermontreal@gmail.com> | 2017-02-04 07:12:47 +0300 |
commit | 9e7b992d92aa1a9ef70ec260ac991cb5c9b5b8d6 (patch) | |
tree | d37ef463ed2e0d29923901d3530517b61ad0a306 /database | |
parent | 88a4afea0725fcc3b4a05cda9b217b13bf41df71 (diff) |
Add indexes to link table and use cr32 hashes to increase speed of lookups
Diffstat (limited to 'database')
-rw-r--r-- | database/migrations/2017_02_04_025727_add_link_table_indexes.php | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/database/migrations/2017_02_04_025727_add_link_table_indexes.php b/database/migrations/2017_02_04_025727_add_link_table_indexes.php new file mode 100644 index 0000000..8db19b7 --- /dev/null +++ b/database/migrations/2017_02_04_025727_add_link_table_indexes.php @@ -0,0 +1,36 @@ +<?php + +use Illuminate\Database\Schema\Blueprint; +use Illuminate\Database\Migrations\Migration; + +class AddLinkTableIndexes extends Migration +{ + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::table('links', function (Blueprint $table) + { + // Add long_url hashes + $table->unique('short_url'); + $table->string('long_url_hash', 10)->nullable(); + $table->index('long_url_hash', 'links_long_url_index'); + }); + + DB::query("UPDATE links SET long_url_hash = crc32(long_url)"); + } + + public function down() + { + Schema::table('links', function (Blueprint $table) + { + $table->longtext('long_url')->change(); + $table->dropUnique('links_short_url_unique'); + $table->dropIndex('links_long_url_index'); + $table->dropColumn('long_url_hash'); + }); + } +} |