Sha256: 4defafe8e3ad87f3d927cbf2fb43665dcbd94fa481320ebdfdb121620f0d5058

Contents?: true

Size: 1.11 KB

Versions: 17

Compression:

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

17 entries across 17 versions & 1 rubygems

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