Skip to content

Commit

Permalink
Fixes #20551 - Use fake content view version class in migration
Browse files Browse the repository at this point in the history
  • Loading branch information
ehelms committed Aug 24, 2017
1 parent 016c499 commit 5d91e04
Showing 1 changed file with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
class MoveContentViewVersionDescriptionToHistories < ActiveRecord::Migration
class Katello::ContentViewVersion < ApplicationRecord
has_many :history, :class_name => "Katello::CVHistory", :inverse_of => :content_view_version,
class FakeContentViewVersion < ApplicationRecord
self.table_name = 'katello_content_view_versions'
has_many :history, :class_name => "CVHistory", :inverse_of => :content_view_version,
:dependent => :destroy, :foreign_key => :katello_content_view_version_id
end

class Katello::CVHistory < ApplicationRecord
class CVHistory < ApplicationRecord
self.table_name = 'katello_content_view_histories'
belongs_to :content_view_version, :class_name => "Katello::ContentViewVersion", :foreign_key => :katello_content_view_version_id, :inverse_of => :history
belongs_to :content_view_version, :class_name => "FakeContentViewVersion", :foreign_key => :katello_content_view_version_id, :inverse_of => :history
SUCCESSFUL = 'successful'.freeze
scope :successful, -> { where(:status => SUCCESSFUL) }

Expand All @@ -19,14 +20,14 @@ class Katello::CVHistory < ApplicationRecord
end

def up
Katello::ContentViewVersion.find_each do |version|
FakeContentViewVersion.find_each do |version|
publish_history = version.history.publish.successful.first
unless publish_history
publish_history = Katello::CVHistory.create!(action: Katello::CVHistory.actions[:publish],
katello_content_view_version_id: version.id,
status: 'successful',
user: ''
)
publish_history = CVHistory.create!(action: CVHistory.actions[:publish],
katello_content_view_version_id: version.id,
status: 'successful',
user: ''
)
end

publish_history.update_attributes!(notes: version[:description])
Expand Down

0 comments on commit 5d91e04

Please sign in to comment.