Commit c155400b7a863994b43a55b31c98fc87fac2ed1e

Authored by Rodrigo Souto
1 parent 6adcfdc4

fix schema and migrations after merge

db/migrate/20151105175041_create_article_followers.rb
1 class CreateArticleFollowers < ActiveRecord::Migration 1 class CreateArticleFollowers < ActiveRecord::Migration
2 def self.up 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 != '');") 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_timestamps :article_followers
4 add_index :article_followers, :person_id 5 add_index :article_followers, :person_id
5 add_index :article_followers, :article_id 6 add_index :article_followers, :article_id
6 add_index :article_followers, [:person_id, :article_id], :unique => true 7 add_index :article_followers, [:person_id, :article_id], :unique => true
db/migrate/20151210230319_add_followers_count_to_article.rb
1 class AddFollowersCountToArticle < ActiveRecord::Migration 1 class AddFollowersCountToArticle < ActiveRecord::Migration
2 -  
3 - def self.up  
4 - add_column :articles, :followers_count, :integer, :default => 0  
5 -  
6 - execute "update articles set followers_count = (select count(*) from article_followers where article_followers.article_id = articles.id)"  
7 - end  
8 -  
9 - def self.down  
10 - remove_column :articles, :followers_count  
11 - end  
12 - 2 + def self.up
  3 + add_column :articles, :followers_count, :integer, :default => 0
  4 + execute "update articles set followers_count = (select count(*) from article_followers where article_followers.article_id = articles.id)"
  5 + end
  6 +
  7 + def self.down
  8 + remove_column :articles, :followers_count
  9 + end
13 end 10 end
@@ -51,12 +51,10 @@ ActiveRecord::Schema.define(version: 20160202142247) do @@ -51,12 +51,10 @@ ActiveRecord::Schema.define(version: 20160202142247) do
51 add_index "action_tracker_notifications", ["profile_id", "action_tracker_id"], name: "index_action_tracker_notif_on_prof_id_act_tracker_id", unique: true, using: :btree 51 add_index "action_tracker_notifications", ["profile_id", "action_tracker_id"], name: "index_action_tracker_notif_on_prof_id_act_tracker_id", unique: true, using: :btree
52 add_index "action_tracker_notifications", ["profile_id"], name: "index_action_tracker_notifications_on_profile_id", using: :btree 52 add_index "action_tracker_notifications", ["profile_id"], name: "index_action_tracker_notifications_on_profile_id", using: :btree
53 53
54 - create_table "article_followers", force: :cascade do |t|  
55 - t.integer "person_id", null: false  
56 - t.integer "article_id", null: false 54 + create_table "article_followers", id: false, force: :cascade do |t|
  55 + t.integer "person_id"
  56 + t.integer "article_id"
57 t.datetime "since" 57 t.datetime "since"
58 - t.datetime "created_at"  
59 - t.datetime "updated_at"  
60 end 58 end
61 59
62 add_index "article_followers", ["article_id"], name: "index_article_followers_on_article_id", using: :btree 60 add_index "article_followers", ["article_id"], name: "index_article_followers_on_article_id", using: :btree
@@ -113,7 +111,6 @@ ActiveRecord::Schema.define(version: 20160202142247) do @@ -113,7 +111,6 @@ ActiveRecord::Schema.define(version: 20160202142247) do
113 t.integer "spam_comments_count", default: 0 111 t.integer "spam_comments_count", default: 0
114 t.integer "author_id" 112 t.integer "author_id"
115 t.integer "created_by_id" 113 t.integer "created_by_id"
116 - t.integer "followers_count"  
117 end 114 end
118 115
119 add_index "article_versions", ["article_id"], name: "index_article_versions_on_article_id", using: :btree 116 add_index "article_versions", ["article_id"], name: "index_article_versions_on_article_id", using: :btree
@@ -752,7 +749,7 @@ ActiveRecord::Schema.define(version: 20160202142247) do @@ -752,7 +749,7 @@ ActiveRecord::Schema.define(version: 20160202142247) do
752 create_table "tasks", force: :cascade do |t| 749 create_table "tasks", force: :cascade do |t|
753 t.text "data" 750 t.text "data"
754 t.integer "status" 751 t.integer "status"
755 - t.date "end_date" 752 + t.datetime "end_date"
756 t.integer "requestor_id" 753 t.integer "requestor_id"
757 t.integer "target_id" 754 t.integer "target_id"
758 t.string "code", limit: 40 755 t.string "code", limit: 40