Sha256: f8a68a57c2fedc3a6b9b98fdcb101c94bf877b9405e9edc98704a86e6507261f

Contents?: true

Size: 1.56 KB

Versions: 16

Compression:

Stored size: 1.56 KB

Contents

class MoveContentViewVersionDescriptionToHistories < ActiveRecord::Migration
  class Katello::ContentViewVersion < ActiveRecord::Base
    has_many :history, :class_name => "Katello::CVHistory", :inverse_of => :content_view_version,
                       :dependent => :destroy, :foreign_key => :katello_content_view_version_id
  end

  class Katello::CVHistory < ActiveRecord::Base
    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
    SUCCESSFUL = 'successful'.freeze
    scope :successful, -> { where(:status => SUCCESSFUL) }

    enum action: {
      publish: 1,
      promotion: 2,
      removal: 3,
      export: 4
    }
  end

  def up
    Katello::ContentViewVersion.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: ''
                                                    )
      end

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

    remove_column :katello_content_view_versions, :description, :text
  end

  def down
    add_column :katello_content_view_versions, :description, :text
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
katello-3.4.4 db/migrate/20161014133811_move_content_view_version_description_to_histories.rb
katello-3.4.2 db/migrate/20161014133811_move_content_view_version_description_to_histories.rb
katello-3.4.1 db/migrate/20161014133811_move_content_view_version_description_to_histories.rb
katello-3.4.0.2 db/migrate/20161014133811_move_content_view_version_description_to_histories.rb
katello-3.4.0.1 db/migrate/20161014133811_move_content_view_version_description_to_histories.rb
katello-3.3.2 db/migrate/20161014133811_move_content_view_version_description_to_histories.rb
katello-3.4.0 db/migrate/20161014133811_move_content_view_version_description_to_histories.rb
katello-3.4.0.rc2 db/migrate/20161014133811_move_content_view_version_description_to_histories.rb
katello-3.4.0.rc1 db/migrate/20161014133811_move_content_view_version_description_to_histories.rb
katello-3.3.1.1 db/migrate/20161014133811_move_content_view_version_description_to_histories.rb
katello-3.3.1 db/migrate/20161014133811_move_content_view_version_description_to_histories.rb
katello-3.3.0.1 db/migrate/20161014133811_move_content_view_version_description_to_histories.rb
katello-3.3.0 db/migrate/20161014133811_move_content_view_version_description_to_histories.rb
katello-3.3.0.rc2 db/migrate/20161014133811_move_content_view_version_description_to_histories.rb
katello-3.3.0.rc1.1 db/migrate/20161014133811_move_content_view_version_description_to_histories.rb
katello-3.3.0.rc1 db/migrate/20161014133811_move_content_view_version_description_to_histories.rb