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

Version Path
appstats-0.25.1 db/migrate/20110318203339_add_appstats_results_latest_flag.rb
appstats-0.25.0 db/migrate/20110318203339_add_appstats_results_latest_flag.rb
appstats-0.24.0 db/migrate/20110318203339_add_appstats_results_latest_flag.rb
appstats-0.23.5 db/migrations/20110318203339_add_appstats_results_latest_flag.rb
appstats-0.23.4 db/migrations/20110318203339_add_appstats_results_latest_flag.rb
appstats-0.23.3 db/migrations/20110318203339_add_appstats_results_latest_flag.rb
appstats-0.23.2 db/migrations/20110318203339_add_appstats_results_latest_flag.rb
appstats-0.23.1 db/migrations/20110318203339_add_appstats_results_latest_flag.rb
appstats-0.23.0 db/migrations/20110318203339_add_appstats_results_latest_flag.rb
appstats-0.22.6 db/migrations/20110318203339_add_appstats_results_latest_flag.rb
appstats-0.22.2 db/migrations/20110318203339_add_appstats_results_latest_flag.rb
appstats-0.22.1 db/migrations/20110318203339_add_appstats_results_latest_flag.rb
appstats-0.22.0 db/migrations/20110318203339_add_appstats_results_latest_flag.rb
appstats-0.21.3 db/migrations/20110318203339_add_appstats_results_latest_flag.rb
appstats-0.21.2 db/migrations/20110318203339_add_appstats_results_latest_flag.rb
appstats-0.21.1 db/migrations/20110318203339_add_appstats_results_latest_flag.rb
appstats-0.20.12 db/migrations/20110318203339_add_appstats_results_latest_flag.rb
appstats-0.20.11 db/migrations/20110318203339_add_appstats_results_latest_flag.rb
appstats-0.20.10 db/migrations/20110318203339_add_appstats_results_latest_flag.rb
appstats-0.20.9 db/migrations/20110318203339_add_appstats_results_latest_flag.rb