diff --git a/db/migrate/20151105175041_create_article_followers.rb b/db/migrate/20151105175041_create_article_followers.rb index 9c9f97a..f4a913f 100644 --- a/db/migrate/20151105175041_create_article_followers.rb +++ b/db/migrate/20151105175041_create_article_followers.rb @@ -1,6 +1,7 @@ class CreateArticleFollowers < ActiveRecord::Migration def self.up 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 != '');") + add_timestamps :article_followers add_index :article_followers, :person_id add_index :article_followers, :article_id add_index :article_followers, [:person_id, :article_id], :unique => true diff --git a/db/migrate/20151210230319_add_followers_count_to_article.rb b/db/migrate/20151210230319_add_followers_count_to_article.rb index 2b3b4a1..5c57e1b 100644 --- a/db/migrate/20151210230319_add_followers_count_to_article.rb +++ b/db/migrate/20151210230319_add_followers_count_to_article.rb @@ -1,13 +1,10 @@ class AddFollowersCountToArticle < ActiveRecord::Migration - - def self.up - add_column :articles, :followers_count, :integer, :default => 0 - - execute "update articles set followers_count = (select count(*) from article_followers where article_followers.article_id = articles.id)" - end - - def self.down - remove_column :articles, :followers_count - end - + def self.up + add_column :articles, :followers_count, :integer, :default => 0 + execute "update articles set followers_count = (select count(*) from article_followers where article_followers.article_id = articles.id)" + end + + def self.down + remove_column :articles, :followers_count + end end diff --git a/db/schema.rb b/db/schema.rb index c28a240..22faafb 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -51,12 +51,10 @@ ActiveRecord::Schema.define(version: 20160202142247) do 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 add_index "action_tracker_notifications", ["profile_id"], name: "index_action_tracker_notifications_on_profile_id", using: :btree - create_table "article_followers", force: :cascade do |t| - t.integer "person_id", null: false - t.integer "article_id", null: false + create_table "article_followers", id: false, force: :cascade do |t| + t.integer "person_id" + t.integer "article_id" t.datetime "since" - t.datetime "created_at" - t.datetime "updated_at" end 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 t.integer "spam_comments_count", default: 0 t.integer "author_id" t.integer "created_by_id" - t.integer "followers_count" end 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 create_table "tasks", force: :cascade do |t| t.text "data" t.integer "status" - t.date "end_date" + t.datetime "end_date" t.integer "requestor_id" t.integer "target_id" t.string "code", limit: 40 -- libgit2 0.21.2