Commit 550663e9d3dd8403a73715de0de9546e73d52454
1 parent
9fc96fa9
Exists in
staging
and in
42 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,14 +636,8 @@ class Article < ActiveRecord::Base | ||
| 636 | author_id = self.created_by_id | 636 | author_id = self.created_by_id |
| 637 | end | 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 | def author_name(version_number = nil) | 642 | def author_name(version_number = nil) |
| 649 | person = author(version_number) | 643 | person = author(version_number) |
| @@ -0,0 +1,17 @@ | @@ -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,7 +11,7 @@ | ||
| 11 | # | 11 | # |
| 12 | # It's strongly recommended to check this file into your version control system. | 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 | create_table "abuse_reports", :force => true do |t| | 16 | create_table "abuse_reports", :force => true do |t| |
| 17 | t.integer "reporter_id" | 17 | t.integer "reporter_id" |
| @@ -95,6 +95,7 @@ ActiveRecord::Schema.define(:version => 20140408172149) do | @@ -95,6 +95,7 @@ ActiveRecord::Schema.define(:version => 20140408172149) do | ||
| 95 | t.integer "license_id" | 95 | t.integer "license_id" |
| 96 | t.integer "image_id" | 96 | t.integer "image_id" |
| 97 | t.integer "position" | 97 | t.integer "position" |
| 98 | + t.integer "created_by_id" | ||
| 98 | end | 99 | end |
| 99 | 100 | ||
| 100 | add_index "article_versions", ["article_id"], :name => "index_article_versions_on_article_id" | 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,6 +141,7 @@ ActiveRecord::Schema.define(:version => 20140408172149) do | ||
| 140 | t.integer "license_id" | 141 | t.integer "license_id" |
| 141 | t.integer "image_id" | 142 | t.integer "image_id" |
| 142 | t.integer "position" | 143 | t.integer "position" |
| 144 | + t.integer "created_by_id" | ||
| 143 | end | 145 | end |
| 144 | 146 | ||
| 145 | add_index "articles", ["comments_count"], :name => "index_articles_on_comments_count" | 147 | add_index "articles", ["comments_count"], :name => "index_articles_on_comments_count" |