Sha256: c00b93c81c06bc153ae5f23ed9eba8187a77ca0939f3357f16d5f3e80b3b57bd

Contents?: true

Size: 1.34 KB

Versions: 17

Compression:

Stored size: 1.34 KB

Contents

class AddAuthoredAtToCommits < ActiveRecord::Migration
  def up
    add_column :commits, :authored_at, :timestamp

    Commit.reset_column_information
    Project.find_each do |project|
      project.repo.refresh! # i.e. git remote update
    end

    missing_commits = []

    pbar = ProgressBar.new("commits", Commit.count)
    Project.unscoped do
      Project.find_each do |project|
        project.commits.each do |commit|

          begin
            native_commit = project.repo.native_commit(commit.sha)
            unless native_commit
              commit.delete
              missing_commits << commit
              next
            end
            commit.update_column :authored_at, native_commit.authored_at
          rescue Houston::Adapters::VersionControl::CommitNotFound
            commit.delete
            missing_commits << commit
          end

          pbar.inc
        end
      end
    end
    pbar.finish


    change_column_null :commits, :authored_at, false


    puts "", "", ""
    Project.unscoped do
      missing_commits.each do |commit|
        puts "#{commit.project.slug.ljust(12)} #{commit.sha} #{commit.release_id.to_s.rjust(5)} #{commit.message}"
      end
    end
    puts "", "", "#{missing_commits.length} commits were not found in the repo and were destroyed"
  end

  def down
    remove_column :commits, :authored_at
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

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