title: When part of migration fails, why doesn't it "undo"?
body: <p>Say I have this migration:</p>
  
  <pre><code>class MigrateStuff &lt; ActiveRecord::Migration
    def up
      add_column :contacts, :receive_newsletter, :boolean, :default =&gt; false
      add_index :contacts, :receive_newsletter
  
      for t in SomeOtherThing.all
        #... do stuff in here
      end
    end
  
    def down
      #...
    end
  end
  </code></pre>
  
  <p>So I add a column and index. Then I work some data into the new column. What happens if some portion in my <code>for</code> loop fails? The column/index is not removed. I tried adding this to a transaction:</p>
  
  <pre><code>class MoveEmailRecipientsToContacts &lt; ActiveRecord::Migration
    def up
      Volunteer.transaction do
        add_column :contacts, :receive_newsletter, :boolean, :default =&gt; false
        add_index :contacts, :receive_newsletter
  
        for t in SomeOtherThing.all
          #... do stuff in here
        end
      end
    end
  
    def down
      #...
    end
  end
  </code></pre>
  
  <p>So an exception occurs in the <code>for</code> block, doesn't this cause the transaction to roll-back? But the column and index remains!</p>
  
  <p>What's the proper way to handle this?</p>