Sha256: c5f2ef236e8eca477162e8320cca86b8bc6a96a9b3b9287a4e39f9e66512eb1f

Contents?: true

Size: 890 Bytes

Versions: 17

Compression:

Stored size: 890 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

17 entries across 17 versions & 1 rubygems

Version Path
houston-core-0.8.0.pre db/migrate/20140526155845_add_commit_id_to_deploys.rb
houston-core-0.7.0 db/migrate/20140526155845_add_commit_id_to_deploys.rb
houston-core-0.7.0.beta4 db/migrate/20140526155845_add_commit_id_to_deploys.rb
houston-core-0.7.0.beta3 db/migrate/20140526155845_add_commit_id_to_deploys.rb
houston-core-0.7.0.beta2 db/migrate/20140526155845_add_commit_id_to_deploys.rb
houston-core-0.7.0.beta db/migrate/20140526155845_add_commit_id_to_deploys.rb
houston-core-0.6.3 db/migrate/20140526155845_add_commit_id_to_deploys.rb
houston-core-0.6.2 db/migrate/20140526155845_add_commit_id_to_deploys.rb
houston-core-0.6.1 db/migrate/20140526155845_add_commit_id_to_deploys.rb
houston-core-0.6.0 db/migrate/20140526155845_add_commit_id_to_deploys.rb
houston-core-0.5.6 db/migrate/20140526155845_add_commit_id_to_deploys.rb
houston-core-0.5.5 db/migrate/20140526155845_add_commit_id_to_deploys.rb
houston-core-0.5.4 db/migrate/20140526155845_add_commit_id_to_deploys.rb
houston-core-0.5.3 db/migrate/20140526155845_add_commit_id_to_deploys.rb
houston-core-0.5.2 db/migrate/20140526155845_add_commit_id_to_deploys.rb
houston-core-0.5.1 db/migrate/20140526155845_add_commit_id_to_deploys.rb
houston-core-0.5.0 db/migrate/20140526155845_add_commit_id_to_deploys.rb