Skip to content

Instantly share code, notes, and snippets.

@jasonm
Created October 1, 2012 09:08
Show Gist options
  • Save jasonm/3810464 to your computer and use it in GitHub Desktop.
Save jasonm/3810464 to your computer and use it in GitHub Desktop.
# bash or zsh function
# change self.up to up, self.down to down for Rails 3.1+
rails_migration() {
filename="db/migrate/`date +%Y%m%d%H%M%S`_$1.rb"
classname=$(ruby -e "puts '$1'.split('_').map{|e| e.capitalize}.join")
touch $filename
echo "class $classname < ActiveRecord::Migration" >> $filename
echo " def self.up" >> $filename
echo " end" >> $filename
echo "" >> $filename
echo " def self.down" >> $filename
echo " end" >> $filename
echo "end" >> $filename
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment