Commit 53f73ac3069e88199d3a0dc208b82bff7bde034c
1 parent
45c0df82
Exists in
staging
and in
32 other branches
article-followers: fast migration to move followers from settings to table
Showing
1 changed file
with
12 additions
and
0 deletions
Show diff stats
... | ... | @@ -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 | ... | ... |