Commit c155400b7a863994b43a55b31c98fc87fac2ed1e
1 parent
6adcfdc4
Exists in
master
and in
12 other branches
fix schema and migrations after merge
Showing
3 changed files
with
13 additions
and
18 deletions
Show diff stats
db/migrate/20151105175041_create_article_followers.rb
1 | 1 | class CreateArticleFollowers < ActiveRecord::Migration |
2 | 2 | def self.up |
3 | 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 | 5 | add_index :article_followers, :person_id |
5 | 6 | add_index :article_followers, :article_id |
6 | 7 | add_index :article_followers, [:person_id, :article_id], :unique => true | ... | ... |
db/migrate/20151210230319_add_followers_count_to_article.rb
1 | 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 | 10 | end | ... | ... |
db/schema.rb
... | ... | @@ -51,12 +51,10 @@ ActiveRecord::Schema.define(version: 20160202142247) do |
51 | 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 | 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 | 57 | t.datetime "since" |
58 | - t.datetime "created_at" | |
59 | - t.datetime "updated_at" | |
60 | 58 | end |
61 | 59 | |
62 | 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 | 111 | t.integer "spam_comments_count", default: 0 |
114 | 112 | t.integer "author_id" |
115 | 113 | t.integer "created_by_id" |
116 | - t.integer "followers_count" | |
117 | 114 | end |
118 | 115 | |
119 | 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 | 749 | create_table "tasks", force: :cascade do |t| |
753 | 750 | t.text "data" |
754 | 751 | t.integer "status" |
755 | - t.date "end_date" | |
752 | + t.datetime "end_date" | |
756 | 753 | t.integer "requestor_id" |
757 | 754 | t.integer "target_id" |
758 | 755 | t.string "code", limit: 40 | ... | ... |