Commit 53f73ac3069e88199d3a0dc208b82bff7bde034c

Authored by Rodrigo Souto
1 parent 45c0df82

article-followers: fast migration to move followers from settings to table

db/migrate/20151105175041_create_article_followers.rb 0 → 100644
@@ -0,0 +1,12 @@ @@ -0,0 +1,12 @@
  1 +class CreateArticleFollowers < ActiveRecord::Migration
  2 + def self.up
  3 + execute("CREATE TABLE article_followers AS (SELECT profiles.id AS person_id, t.id AS article_id, clock_timestamp() AS since FROM (SELECT articles.id, regexp_split_to_table(replace(replace(substring(articles.setting FROM ':followers:[^:]*'), ':followers:', ''), '- ', ''), '\n') AS follower FROM articles) t INNER JOIN users ON users.email = follower INNER JOIN profiles ON users.id = profiles.user_id WHERE follower != '');")
  4 + add_index :article_followers, :person_id
  5 + add_index :article_followers, :article_id
  6 + add_index :article_followers, [:person_id, :article_id], :unique => true
  7 + end
  8 +
  9 + def self.down
  10 + drop_table :article_followers
  11 + end
  12 +end