Sha256: f53a5baa9b22de09441482e2c79fc44f5c49d6996c3cb935256260059c48f5fa

Contents?: true

Size: 623 Bytes

Versions: 1

Compression:

Stored size: 623 Bytes

Contents

class AddProjectIdToCommits < ActiveRecord::Migration
  def up
    add_column :commits, :project_id, :integer
    
    Commit.reset_column_information
    Commit.find_each do |commit|
      release = commit.release
      
      if release.nil?
        commit.delete
        Rails.logger.warn "Deleting commit ##{commit.id} (#{commit.attributes.inspect})"
        next
      end
      
      commit.update_column(:project_id, release.project_id)
    end
    
    change_column_null :commits, :project_id, false
    
    add_index :commits, [:project_id]
  end
  
  def down
    remove_column :commits, :project_id
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
houston-core-0.5.0.beta1 db/migrate/20130407220937_add_project_id_to_commits.rb