Sha256: 11480d9e6f817c6918a019d116e4866d0f5351bfa096bfbf2353d04ad6500b55

Contents?: true

Size: 1.13 KB

Versions: 1

Compression:

Stored size: 1.13 KB

Contents

class AddCommitBeforeIdAndCommitAfterIdToReleases < ActiveRecord::Migration
  def up
    add_column :releases, :commit_before_id, :integer
    add_column :releases, :commit_after_id, :integer
    
    pbar = ProgressBar.new("releases", Release.count)
    Release.includes(:project).find_each do |release|
      pbar.inc
      next unless release.project
      
      sha0 = release.read_attribute(:commit0)
      sha1 = release.read_attribute(:commit1)
      commit0 = release.project.commits.find_by_sha sha0
      commit1 = release.project.commits.find_by_sha sha1
      release.update_column :commit_before_id, commit0.id if commit0
      release.update_column :commit_after_id, commit1.id if commit1
    end
    pbar.finish
    
    puts "\e[33;1m#{Release.where(commit_before_id: nil).count}\e[0;33m out of \e[1m#{Release.count}\e[0;33m release don't have a commit_before\e[0m"
    puts "\e[33;1m#{Release.where(commit_after_id: nil).count}\e[0;33m out of \e[1m#{Release.count}\e[0;33m release don't have a commit_after\e[0m"
  end
  
  def down
    remove_column :releases, :commit_before_id
    remove_column :releases, :commit_after_id
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
houston-core-0.5.0.beta1 db/migrate/20140526162645_add_commit_before_id_and_commit_after_id_to_releases.rb