Commit 550663e9d3dd8403a73715de0de9546e73d52454
1 parent
9fc96fa9
Exists in
master
and in
29 other branches
Added migration to include created_by on articles
the migration also fills in the attribute for all the existent articles updated db/schema (ActionItem3097)
Showing
3 changed files
with
22 additions
and
9 deletions
Show diff stats
app/models/article.rb
... | ... | @@ -636,14 +636,8 @@ class Article < ActiveRecord::Base |
636 | 636 | author_id = self.created_by_id |
637 | 637 | end |
638 | 638 | |
639 | - begin | |
640 | - @author = Person.find(author_id) if !@author || @author.id != author_id | |
641 | - rescue | |
642 | - @author = nil | |
643 | - end | |
644 | - | |
645 | - @author | |
646 | - end | |
639 | + environment.people.find_by_id(author_id) | |
640 | + end | |
647 | 641 | |
648 | 642 | def author_name(version_number = nil) |
649 | 643 | person = author(version_number) | ... | ... |
... | ... | @@ -0,0 +1,17 @@ |
1 | +class AddCreatedByToArticle < ActiveRecord::Migration | |
2 | + def self.up | |
3 | + add_column :articles, :created_by_id, :integer | |
4 | + add_column :article_versions, :created_by_id, :integer | |
5 | + | |
6 | + execute("UPDATE article_versions SET created_by_id = last_changed_by_id") | |
7 | + | |
8 | + execute("UPDATE articles SET created_by_id = article_versions.created_by_id | |
9 | +FROM article_versions WHERE article_versions.article_id = articles.id AND | |
10 | +article_versions.version = 1") | |
11 | + end | |
12 | + | |
13 | + def self.down | |
14 | + remove_column :articles, :created_by_id | |
15 | + remove_column :article_versions, :created_by_id | |
16 | + end | |
17 | +end | ... | ... |
db/schema.rb
... | ... | @@ -11,7 +11,7 @@ |
11 | 11 | # |
12 | 12 | # It's strongly recommended to check this file into your version control system. |
13 | 13 | |
14 | -ActiveRecord::Schema.define(:version => 20140408172149) do | |
14 | +ActiveRecord::Schema.define(:version => 20140415125414) do | |
15 | 15 | |
16 | 16 | create_table "abuse_reports", :force => true do |t| |
17 | 17 | t.integer "reporter_id" |
... | ... | @@ -95,6 +95,7 @@ ActiveRecord::Schema.define(:version => 20140408172149) do |
95 | 95 | t.integer "license_id" |
96 | 96 | t.integer "image_id" |
97 | 97 | t.integer "position" |
98 | + t.integer "created_by_id" | |
98 | 99 | end |
99 | 100 | |
100 | 101 | add_index "article_versions", ["article_id"], :name => "index_article_versions_on_article_id" |
... | ... | @@ -140,6 +141,7 @@ ActiveRecord::Schema.define(:version => 20140408172149) do |
140 | 141 | t.integer "license_id" |
141 | 142 | t.integer "image_id" |
142 | 143 | t.integer "position" |
144 | + t.integer "created_by_id" | |
143 | 145 | end |
144 | 146 | |
145 | 147 | add_index "articles", ["comments_count"], :name => "index_articles_on_comments_count" | ... | ... |