# ActiveRecord migrations in a single transaction?

**URL:** <https://www.ruby-forum.com/t/activerecord-migrations-in-a-single-transaction/73345>\
**Category:** Rails\
**Created:** [October 24, 2006, 12:35am UTC](https://www.ruby-forum.com/t/activerecord-migrations-in-a-single-transaction/73345 "2006-10-24T00:35:22Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![stubbsuk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e56c9b/32.png) [@stubbsuk](https://www.ruby-forum.com/u/stubbsuk)\
**Post date:** [October 24, 2006, 12:35am UTC](https://www.ruby-forum.com/t/activerecord-migrations-in-a-single-transaction/73345/1 "2006-10-24T00:35:22Z")

</div>

Is it possible to make Migrations occur in a single transaction, so  
that if the rake fails, it doesn’t leave the database in a broken  
state, with half the changes made, and the other half incomplete?

Obviously, this depends on the database itself supporting transactions,  
but I’m using Postgres.

---

<div class="post-metadata">

**Author:** ![stubbsuk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e56c9b/32.png) [@stubbsuk](https://www.ruby-forum.com/u/stubbsuk)\
**Post date:** [October 24, 2006, 2:15am UTC](https://www.ruby-forum.com/t/activerecord-migrations-in-a-single-transaction/73345/2 "2006-10-24T02:15:42Z")

</div>

Stuart G. wrote:

> Is it possible to make Migrations occur in a single transaction, so  
> that if the rake fails, it doesn’t leave the database in a broken  
> state, with half the changes made, and the other half incomplete?
> 
> Obviously, this depends on the database itself supporting transactions,  
> but I’m using Postgres.
> 
> >

I wrap my migrations in a transaction using postgresql, and it seems to  
work fine.

–  
Jim M., [http://blog.wolfman.com](http://blog.wolfman.com)

---

<div class="post-metadata">

**Author:** ![stubbsuk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e56c9b/32.png) [@stubbsuk](https://www.ruby-forum.com/u/stubbsuk)\
**Post date:** [October 24, 2006, 2:19am UTC](https://www.ruby-forum.com/t/activerecord-migrations-in-a-single-transaction/73345/3 "2006-10-24T02:19:43Z")

</div>

Me too.

But you need a database backend that will transact DDL changes. Not  
all do. Postgres for sure does, and now I don’t have any half-made  
transactions anymore.

I can give you more details if needed.

Bye,

Guy.

On 10/23/06, Jim M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > >
> 
> I wrap my migrations in a transaction using postgresql, and it seems to work fine.
> 
> –  
> Jim M., [http://blog.wolfman.com](http://blog.wolfman.com)
> 
> >

–  
Family management on rails: [http://www.famundo.com](http://www.famundo.com) - coming soon!  
My development related blog: [http://devblog.famundo.com](http://devblog.famundo.com)

---

<div class="post-metadata">

**Author:** ![stubbsuk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e56c9b/32.png) [@stubbsuk](https://www.ruby-forum.com/u/stubbsuk)\
**Post date:** [October 25, 2006, 2:07pm UTC](https://www.ruby-forum.com/t/activerecord-migrations-in-a-single-transaction/73345/4 "2006-10-25T14:07:15Z")

</div>

Stuart G. wrote:

> Is it possible to make Migrations occur in a single transaction, so that if  
> the rake fails, it doesn’t leave the database in a broken state, with half  
> the changes made, and the other half incomplete?
> 
> Obviously, this depends on the database itself supporting transactions, but  
> I’m using Postgres.

The easiest way for you is to use transactional\_migrations plugin. Thus  
you  
won’t need to put explicit BEGIN and COMMIT DDL statements in  
migrations.

[http://www.redhillconsulting.com.au/rails\_plugins.html#transactional\_migrations](http://www.redhillconsulting.com.au/rails_plugins.html#transactional_migrations)

–  
Sava C.

---

<div class="post-metadata">

**Author:** ![stubbsuk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e56c9b/32.png) [@stubbsuk](https://www.ruby-forum.com/u/stubbsuk)\
**Post date:** [November 7, 2006, 10:53am UTC](https://www.ruby-forum.com/t/activerecord-migrations-in-a-single-transaction/73345/5 "2006-11-07T10:53:21Z")

</div>

Hello:  
You wrote in another thread, now outdated, about a way for getting  
decimal support for ActiveRecord, in version 1.1.6.  
Is there a way of having that code?  
Thanks in advance.

---

<div class="post-metadata">

**Author:** ![stubbsuk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e56c9b/32.png) [@stubbsuk](https://www.ruby-forum.com/u/stubbsuk)\
**Post date:** [November 8, 2006, 12:48am UTC](https://www.ruby-forum.com/t/activerecord-migrations-in-a-single-transaction/73345/6 "2006-11-08T00:48:54Z")

</div>

Thanks Sava, this is what I went for in the end …
