Sha256: 13b06fcc30dc184a219419ded709ca07df45db5151602e9e242f95bcc5917845
Contents?: true
Size: 754 Bytes
Versions: 32
Compression:
Stored size: 754 Bytes
Contents
class AddAppstatsResultsLatestFlag < ActiveRecord::Migration def self.up add_column :appstats_results, :is_latest, :boolean add_index :appstats_results, :is_latest ActiveRecord::Base.connection.update('update appstats_results set is_latest = false') all = ActiveRecord::Base.connection.select_all("select concat(id,' ',max(updated_at)) as id_and_date from appstats_results group by query") return if all.empty? ids = all.each.collect { |e| e["id_and_date"].split[0] }.compact ActiveRecord::Base.connection.update("update appstats_results set is_latest = '1' where id in (#{ids.join(',')})") end def self.down remove_index :appstats_results, :is_latest remove_column :appstats_results, :is_latest end end
Version data entries
32 entries across 32 versions & 1 rubygems