Sha256: 7507c6d47f10481cf088e7ebaed2eb12313273c7dffb0030e046b2923842d0c3

Contents?: true

Size: 508 Bytes

Versions: 69

Compression:

Stored size: 508 Bytes

Contents

class RemoveArfReportsWithoutPolicy < ActiveRecord::Migration[4.2]
  def up
    if User.unscoped.find_by(:login => User::ANONYMOUS_ADMIN)
      User.as_anonymous_admin do
        delete_reports
      end
    else
      delete_reports
    end
  end

  def delete_reports
    ids_to_keep = ForemanOpenscap::ArfReport.unscoped.all.joins(:policy_arf_report).pluck(:id)
    ForemanOpenscap::ArfReport.unscoped.where.not(:id => ids_to_keep).find_in_batches do |batch|
      batch.map(&:destroy!)
    end
  end
end

Version data entries

69 entries across 69 versions & 1 rubygems

Version Path
foreman_openscap-10.0.2 db/migrate/20171011134112_remove_arf_reports_without_policy.rb
foreman_openscap-10.0.1 db/migrate/20171011134112_remove_arf_reports_without_policy.rb
foreman_openscap-10.0.0 db/migrate/20171011134112_remove_arf_reports_without_policy.rb
foreman_openscap-9.0.4 db/migrate/20171011134112_remove_arf_reports_without_policy.rb
foreman_openscap-9.0.3 db/migrate/20171011134112_remove_arf_reports_without_policy.rb
foreman_openscap-9.0.2 db/migrate/20171011134112_remove_arf_reports_without_policy.rb
foreman_openscap-9.0.1 db/migrate/20171011134112_remove_arf_reports_without_policy.rb
foreman_openscap-9.0.0 db/migrate/20171011134112_remove_arf_reports_without_policy.rb
foreman_openscap-8.0.0 db/migrate/20171011134112_remove_arf_reports_without_policy.rb
foreman_openscap-7.1.1 db/migrate/20171011134112_remove_arf_reports_without_policy.rb
foreman_openscap-7.1.0 db/migrate/20171011134112_remove_arf_reports_without_policy.rb
foreman_openscap-7.0.0 db/migrate/20171011134112_remove_arf_reports_without_policy.rb
foreman_openscap-6.0.0 db/migrate/20171011134112_remove_arf_reports_without_policy.rb
foreman_openscap-5.2.3 db/migrate/20171011134112_remove_arf_reports_without_policy.rb
foreman_openscap-5.2.2 db/migrate/20171011134112_remove_arf_reports_without_policy.rb
foreman_openscap-5.1.1 db/migrate/20171011134112_remove_arf_reports_without_policy.rb
foreman_openscap-5.2.1 db/migrate/20171011134112_remove_arf_reports_without_policy.rb
foreman_openscap-5.2.0 db/migrate/20171011134112_remove_arf_reports_without_policy.rb
foreman_openscap-5.1.0 db/migrate/20171011134112_remove_arf_reports_without_policy.rb
foreman_openscap-5.0.0 db/migrate/20171011134112_remove_arf_reports_without_policy.rb