Eric Goodwin

Gitty Migrations Get Even Simpler
08/03/31

Most of the time when you commit a migration, you'll want to run that migration against the code base you have when you check that migration is. To make this simpler to do, all you have to do is call use_git and gitty migrations with automatically find that revision for you.

Here's an updated example on how to use gitty migrations

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class ResetAllAccountTypes < ActiveRecord::Migration
  
  use_git
  # or 
  # use_git :revision => "42ca6c6de8cbd6591dcada7437c97"
  # or
  # use_git :revision => "v2.0"
   
  def self.up
    add_column :user, :account, :integer, :null => false
    User.find(:all).each do |user|
      user.account = case user.account_type
        when "Free" : Account::Types::Free
        when "Paid" : Account::Types::Paid
        else Account::Types::Unknown
      end
    end
    remove_column :user, :account_type
  end

  def self.down
    ...
  end
end

Download it from GitHub

0 comments

Comments

Have your say

A name is required. You may use HTML in your comments.




About

Eric Goodwin is a web developer living in Victoria BC, Canada. You can contact him at eric@ericgoodwin.com

Open Source

Projects

Elsewhere

Archives