Commit 800571034f45576b654b171f33994313b08fcca7

Authored by Larissa Reis
1 parent 788d99fe

Fixes migration to create all friendship groups

db/migrate/20160608123748_create_profile_followers_table.rb
@@ -18,14 +18,15 @@ class CreateProfileFollowersTable < ActiveRecord::Migration @@ -18,14 +18,15 @@ class CreateProfileFollowersTable < ActiveRecord::Migration
18 add_index :circles, [:person_id, :name], :name => "circles_composite_key_index", :unique => true 18 add_index :circles, [:person_id, :name], :name => "circles_composite_key_index", :unique => true
19 19
20 #insert one category for each friend group a person has 20 #insert one category for each friend group a person has
21 - execute("INSERT INTO circles(name, person_id, profile_type) SELECT DISTINCT (CASE WHEN (f.group IS NULL OR f.group = '') THEN 'friendships' ELSE f.group END), f.person_id, 'Person' FROM friendships as f") 21 + execute("INSERT INTO circles(name, person_id, profile_type) SELECT DISTINCT 'friendships', f.person_id, 'Person' FROM friendships as f WHERE f.group IS NULL OR f.group = ''")
  22 + execute("INSERT INTO circles(name, person_id, profile_type) SELECT DISTINCT regexp_split_to_table(f.group, ', '), f.person_id, 'Person' FROM friendships as f WHERE f.group IS NOT NULL AND f.group <> ''")
22 #insert 'memberships' category if a person is in a community as any role 23 #insert 'memberships' category if a person is in a community as any role
23 execute("INSERT INTO circles(name, person_id, profile_type) SELECT DISTINCT 'memberships', ra.accessor_id, 'Community' FROM role_assignments as ra JOIN profiles ON ra.resource_id = profiles.id WHERE ra.resource_type = 'Profile' AND profiles.type = 'Community'") 24 execute("INSERT INTO circles(name, person_id, profile_type) SELECT DISTINCT 'memberships', ra.accessor_id, 'Community' FROM role_assignments as ra JOIN profiles ON ra.resource_id = profiles.id WHERE ra.resource_type = 'Profile' AND profiles.type = 'Community'")
24 #insert 'favorites' category if a person has any favorited enterprise 25 #insert 'favorites' category if a person has any favorited enterprise
25 execute("INSERT INTO circles(name, person_id, profile_type) SELECT DISTINCT 'favorites', person_id, 'Enterprise' FROM favorite_enterprise_people") 26 execute("INSERT INTO circles(name, person_id, profile_type) SELECT DISTINCT 'favorites', person_id, 'Enterprise' FROM favorite_enterprise_people")
26 27
27 #insert a follower entry for each friend, with the category the same as the friendship group or equals 'friendships' 28 #insert a follower entry for each friend, with the category the same as the friendship group or equals 'friendships'
28 - execute("INSERT INTO profiles_circles(profile_id, circle_id) SELECT DISTINCT f.friend_id, c.id FROM friendships as f JOIN circles as c ON f.person_id = c.person_id WHERE c.name = f.group OR c.name = 'friendships'") 29 + execute("INSERT INTO profiles_circles(profile_id, circle_id) SELECT DISTINCT f.friend_id, c.id FROM friendships as f JOIN circles as c ON f.person_id = c.person_id WHERE c.name = ANY(regexp_split_to_array(f.group, ', ')) OR c.name = 'friendships'")
29 #insert a follower entry for each favorited enterprise, with the category 'favorites' 30 #insert a follower entry for each favorited enterprise, with the category 'favorites'
30 execute("INSERT INTO profiles_circles(profile_id, circle_id) SELECT DISTINCT f.enterprise_id, c.id FROM favorite_enterprise_people AS f JOIN circles as c ON f.person_id = c.person_id WHERE c.name = 'favorites' ") 31 execute("INSERT INTO profiles_circles(profile_id, circle_id) SELECT DISTINCT f.enterprise_id, c.id FROM favorite_enterprise_people AS f JOIN circles as c ON f.person_id = c.person_id WHERE c.name = 'favorites' ")
31 #insert a follower entry for each community a person participates with any role 32 #insert a follower entry for each community a person participates with any role