cirandas.net

ref: master

plugins/organization_ratings/db/migrate/20151203121430_destroy_rejected_reports.rb


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
class DestroyRejectedReports < ActiveRecord::Migration
  def up
    comments = []
    select_all("SELECT data FROM tasks WHERE type = 'CreateOrganizationRatingComment' AND status = 2").each do |task|
      settings = YAML.load(task['data'])
      comments << settings[:organization_rating_comment_id]
    end
    if !comments.empty?
      execute("DELETE FROM comments WHERE id IN (#{comments.join(',')})")
    end
  end

  def down
    say "This migration can't be reverted"
  end
end