# Migrations and indexes on failure - db permanently polluted

**URL:** <https://www.ruby-forum.com/t/migrations-and-indexes-on-failure-db-permanently-polluted/141805>\
**Category:** Rails\
**Created:** [June 30, 2008, 6:36pm UTC](https://www.ruby-forum.com/t/migrations-and-indexes-on-failure-db-permanently-polluted/141805 "2008-06-30T18:36:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![djconcepcion](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/57b2e6/32.png) [@djconcepcion](https://www.ruby-forum.com/u/djconcepcion)\
**Post date:** [June 30, 2008, 6:36pm UTC](https://www.ruby-forum.com/t/migrations-and-indexes-on-failure-db-permanently-polluted/141805/1 "2008-06-30T18:36:24Z")

</div>

It’s unclear to me whether or not migrations are currently (rails 2.0.2)  
fully transactional.  
At least in the case of indexes, they don’t appear to be.  
If the second index create fails below:

class CreateIndexes \< ActiveRecord::Migration  
def self.up  
add\_index :ontable, :onacolumn  
add\_index :anothertable, :onanothercolumn  
end

def self.down  
remove\_index :ontable, :onacolumn  
remove\_index :anothertable, :onanothercolumn  
end

it appears migrations are now permanently stuck (can’t move forward,  
can’t rollback), since it will now fail on all forward migrations since  
the first index is already created, and rollback can’t occur since the  
db never actually rolled fully forward to update the schema version.

Am I missing something (other than manual repair/cleanup of incomplete  
indexes) that would fix this?

In truth, my primary goal was to use mysql foreign keys (constraints +  
index), but I was waiting until that’s integrated more.

---

<div class="post-metadata">

**Author:** ![djconcepcion](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/57b2e6/32.png) [@djconcepcion](https://www.ruby-forum.com/u/djconcepcion)\
**Post date:** [June 30, 2008, 6:57pm UTC](https://www.ruby-forum.com/t/migrations-and-indexes-on-failure-db-permanently-polluted/141805/2 "2008-06-30T18:57:03Z")

</div>

On 30 Jun 2008, at 17:36, DJ Cole wrote:

> It’s unclear to me whether or not migrations are currently (rails  
> 2.0.2)  
> fully transactional.

They are not in any way transactional (with mysql at least, they can’t  
be, because things like alter table implicitly commit the current  
transaction)

> def self.down  
> Am I missing something (other than manual repair/cleanup of incomplete  
> indexes) that would fix this?

nope.

Fred

---

<div class="post-metadata">

**Author:** ![djconcepcion](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/57b2e6/32.png) [@djconcepcion](https://www.ruby-forum.com/u/djconcepcion)\
**Post date:** [June 30, 2008, 7:40pm UTC](https://www.ruby-forum.com/t/migrations-and-indexes-on-failure-db-permanently-polluted/141805/3 "2008-06-30T19:40:22Z")

</div>

Thank you. I was hoping there was rails (not nec. db - db support would  
be something like forced create, similar to create\_table) support for  
this, but I suppose one could break up the above into individual  
migrations, then slowly increment forward (or back) as necessary.
