# Unit tests rolling back my migrations

**URL:** <https://www.ruby-forum.com/t/unit-tests-rolling-back-my-migrations/113887>\
**Category:** Rails\
**Created:** [September 5, 2007, 10:38pm UTC](https://www.ruby-forum.com/t/unit-tests-rolling-back-my-migrations/113887 "2007-09-05T22:38:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![janovetz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/53a042/32.png) [@janovetz](https://www.ruby-forum.com/u/janovetz)\
**Post date:** [September 5, 2007, 10:38pm UTC](https://www.ruby-forum.com/t/unit-tests-rolling-back-my-migrations/113887/1 "2007-09-05T22:38:26Z")

</div>

Hey folks–

I’m currently on tag/rel\_1-2-3 and have a problem I haven’t encountered  
before. I’ve got about 55 total migrations in my database. With this  
most recent one, I migrate the test database:

rake RAILS\_ENV=test db:migrate

Then I run the unit tests:

rake test:units

Several fail, even though they succeed when run individually. Upon  
inspection, I realized that my ‘schema\_info’ has gone back to its  
previous value. Any idea why this would be happening?

Jake

---

<div class="post-metadata">

**Author:** ![janovetz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/53a042/32.png) [@janovetz](https://www.ruby-forum.com/u/janovetz)\
**Post date:** [September 6, 2007, 12:40am UTC](https://www.ruby-forum.com/t/unit-tests-rolling-back-my-migrations/113887/2 "2007-09-06T00:40:39Z")

</div>

Ok… So I just ran my migration on RAILS\_ENV=development and now “rake  
test:units” succeeds and does not rollback my test database.

Is there some linkage here that shouldn’t be there? I tried this  
because I noticed a DEPRECATION warning that came up in  
'environments/development.rb" and I couldn’t figure out why rake  
test:units was running my development environment.

It still, of course, uses the test database.

A little confused,  
Jake

Jake J. wrote:

> Hey folks–
> 
> I’m currently on tag/rel\_1-2-3 and have a problem I haven’t encountered  
> before. I’ve got about 55 total migrations in my database. With this  
> most recent one, I migrate the test database:
> 
> rake RAILS\_ENV=test db:migrate
> 
> Then I run the unit tests:
> 
> rake test:units
> 
> Several fail, even though they succeed when run individually. Upon  
> inspection, I realized that my ‘schema\_info’ has gone back to its  
> previous value. Any idea why this would be happening?
> 
> Jake

---

<div class="post-metadata">

**Author:** ![janovetz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/53a042/32.png) [@janovetz](https://www.ruby-forum.com/u/janovetz)\
**Post date:** [September 6, 2007, 10:29pm UTC](https://www.ruby-forum.com/t/unit-tests-rolling-back-my-migrations/113887/3 "2007-09-06T22:29:14Z")

</div>

On 9/5/07, Jake J. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Ok… So I just ran my migration on RAILS\_ENV=development and now “rake  
> test:units” succeeds and does not rollback my test database.
> 
> Is there some linkage here that shouldn’t be there? I tried this  
> because I noticed a DEPRECATION warning that came up in  
> 'environments/development.rb" and I couldn’t figure out why rake  
> test:units was running my development environment.
> 
> It still, of course, uses the test database.

rake test:units calls db:test:prepare, which clones your development  
schema to your test schema. That’s what’s wiping out your migrations.

You should not run migrations on the test environment. Run them on the  
development environment before running your tests. Also, if you use  
autotest (which rocks by the way), you need to run rake  
db:test:prepare manually after the migration.

---

<div class="post-metadata">

**Author:** ![janovetz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/53a042/32.png) [@janovetz](https://www.ruby-forum.com/u/janovetz)\
**Post date:** [September 6, 2007, 10:37pm UTC](https://www.ruby-forum.com/t/unit-tests-rolling-back-my-migrations/113887/4 "2007-09-06T22:37:55Z")

</div>

Bob S. wrote:

> On 9/5/07, Jake J. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > Ok… So I just ran my migration on RAILS\_ENV=development and now “rake  
> > test:units” succeeds and does not rollback my test database.
> > 
> > Is there some linkage here that shouldn’t be there? I tried this  
> > because I noticed a DEPRECATION warning that came up in  
> > 'environments/development.rb" and I couldn’t figure out why rake  
> > test:units was running my development environment.
> > 
> > It still, of course, uses the test database.
> 
> rake test:units calls db:test:prepare, which clones your development  
> schema to your test schema. That’s what’s wiping out your migrations.
> 
> You should not run migrations on the test environment. Run them on the  
> development environment before running your tests. Also, if you use  
> autotest (which rocks by the way), you need to run rake  
> db:test:prepare manually after the migration.

Ah. I see. Thanks for that explanation.

I occasionally run the migration on test first while I’m still testing  
the migration to avoid messing up the development database. (since  
MySQL doesn’t support transactional migrations – if a migration fails,  
I have to fiddle with it by hand to get things back)

Jake
