Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/cydrobolt/polr.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChaoyi Zha <summermontreal@gmail.com>2017-02-11 00:50:46 +0300
committerChaoyi Zha <summermontreal@gmail.com>2017-02-11 02:05:34 +0300
commit5c2ff762de493132c6f8ce19ec74a8e467895751 (patch)
treeee3f111f0b7fb9de7c0f64cfd321552466240537 /database
parentc228791f952ab5826457f6574db04fc2b85759ce (diff)
Use ORM with chunking to add crc32 hases to old links
Diffstat (limited to 'database')
-rw-r--r--database/migrations/2017_02_04_025727_add_link_table_indexes.php17
1 files changed, 15 insertions, 2 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
index db54208..4b6dc2a 100644
--- a/database/migrations/2017_02_04_025727_add_link_table_indexes.php
+++ b/database/migrations/2017_02_04_025727_add_link_table_indexes.php
@@ -20,14 +20,27 @@ class AddLinkTableIndexes extends Migration
$table->index('long_url_hash', 'links_long_url_index');
});
- DB::statement("UPDATE links SET long_url_hash = crc32(long_url);");
+ // MySQL only statement
+ // DB::statement("UPDATE links SET long_url_hash = crc32(long_url);");
+
+ DB::table('links')->select(['id', 'long_url_hash', 'long_url'])
+ ->chunk(100, function($links) {
+ foreach ($links as $link) {
+ DB::table('links')
+ ->where('id', $link->id)
+ ->update([
+ 'long_url_hash' => sprintf('%u', crc32($link->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');