DHH will probably hate my example, but...
AWDR talks about the difficulties and dangers of using complex migrations--complex being defined as "doing more than one thing". Not being satisfied with the alternatives, I have come up with a system, which people might want to consider for best practice. Example:
class CreateUsers < ActiveRecord::Migration def self.up
create_table :users do |t| t.column :username, :string, :null => false t.column :salt, :string t.column :pw, :string, :null => false t.column :expires, :datetime, :null => false t.column :perm0, :int, :default => 0, :null => false end
begin add_index(:users, :username, :unique => true) User.send(:reset_root, 'Hownowbrowncow') rescue Exception => e down rescue STDERR.puts "Nested exception executing CreateUsers.down:\n#{$!}" raise e end end
def self.down drop_table :users end end