docbrown/lib/data_update_scripts/20200723070918_update_articles_cached_entities.rb
Michael Kohl 26ee8f194c
Rubocop: Move from OpenStruct to Struct in Organization (#9431)
* Move from OpenStruct to Struct in Organization

* Add data update script

* Introduce Articles::CachedEntity model

* Update data update script for new model

* Fix comment

* Update jbuilder
2020-07-30 21:04:05 +07:00

17 lines
620 B
Ruby

module DataUpdateScripts
class UpdateArticlesCachedEntities
def run
Article.where.not(cached_user: nil).or(Article.where.not(cached_organization: nil)).find_each do |article|
if article.cached_organization.present?
old_cached_org = article.cached_organization
article.update(cached_organization: Articles::CachedEntity.from_object(old_cached_org))
end
if article.cached_user.present?
old_cached_user = article.cached_user
article.update(cached_user: Articles::CachedEntity.from_object(old_cached_user))
end
end
end
end
end