Sha256: 02288b1314cd48d2c6881e8223670313b7795a1e0887608fcc00b41eaf848d66

Contents?: true

Size: 910 Bytes

Versions: 1

Compression:

Stored size: 910 Bytes

Contents

class AddCommitIdToDeploys < ActiveRecord::Migration
  def up
    add_column :deploys, :commit_id, :integer
    
    # Do one `git pull` before starting
    puts "syncing commits"
    pbar = ProgressBar.new("projects", Deploy.count)
    Project.unretired.find_each do |project|
      project.commits.sync!
      pbar.inc
    end
    pbar.finish
    
    pbar = ProgressBar.new("deploys", Deploy.count)
    Deploy.includes(:project).find_each do |deploy|
      pbar.inc
      next unless deploy.project
      
      sha = deploy.read_attribute(:commit)
      commit = deploy.project.commits.find_by_sha(sha)
      deploy.update_column :commit_id, commit.id if commit
    end
    pbar.finish
    
    puts "\e[33;1m#{Deploy.where(commit_id: nil).count}\e[0;33m out of \e[1m#{Deploy.count}\e[0;33m deploys aren't associated with a commit\e[0m"
  end
  
  def down
    remove_column :deploys, :commit_id
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
houston-core-0.5.0.beta1 db/migrate/20140526155845_add_commit_id_to_deploys.rb