# Testing Migrations

**URL:** <https://www.ruby-forum.com/t/testing-migrations/79083>\
**Category:** Rails\
**Created:** [March 9, 2006, 5:43pm UTC](https://www.ruby-forum.com/t/testing-migrations/79083 "2006-03-09T17:43:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![olbrich](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/5f9b8f/32.png) [@olbrich](https://www.ruby-forum.com/u/olbrich)\
**Post date:** [March 9, 2006, 5:43pm UTC](https://www.ruby-forum.com/t/testing-migrations/79083/1 "2006-03-09T17:43:18Z")

</div>

Is there some standard way to test migrations?

It seems to me that an additional safeguard for migrations would be to  
test and see if applying the migrations to the test database allows one  
to reconstruct the structure of the development database.

If you can’t, then there is an error in your migrations, most likely  
because someone hand-modified the database without generating a  
migration for it.

The biggest problem with writing unit tests for this is that (AFAIK)  
there is no simple way to apply migrations to the test database instead  
of the development one.

Is there a simple switch or something in rake that will make it use the  
test database?

\_Kevin

---

<div class="post-metadata">

**Author:** ![olbrich](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/5f9b8f/32.png) [@olbrich](https://www.ruby-forum.com/u/olbrich)\
**Post date:** [March 9, 2006, 6:10pm UTC](https://www.ruby-forum.com/t/testing-migrations/79083/2 "2006-03-09T18:10:51Z")

</div>

rake migrate RAILS\_ENV=test

Duane J.  
(canadaduane)  
[http://blog.inquirylabs.com/](http://blog.inquirylabs.com/)

---

<div class="post-metadata">

**Author:** ![olbrich](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/5f9b8f/32.png) [@olbrich](https://www.ruby-forum.com/u/olbrich)\
**Post date:** [March 9, 2006, 6:20pm UTC](https://www.ruby-forum.com/t/testing-migrations/79083/3 "2006-03-09T18:20:16Z")

</div>

Somehow that makes perfect sense! Thanks!

\_Kevin

---

<div class="post-metadata">

**Author:** ![olbrich](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/5f9b8f/32.png) [@olbrich](https://www.ruby-forum.com/u/olbrich)\
**Post date:** [March 9, 2006, 6:29pm UTC](https://www.ruby-forum.com/t/testing-migrations/79083/4 "2006-03-09T18:29:24Z")

</div>

On 9 Mar 2006 16:42:40 -0000, Kevin O.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> The biggest problem with writing unit tests for this is that (AFAIK)  
> there is no simple way to apply migrations to the test database instead  
> of the development one.
> 
> Is there a simple switch or something in rake that will make it use the  
> test database?

I have a script that:

- removes the development and test database
- creates the development and test database
- performs the migrations on the development database
- loads my test fixtures into the development database
- and runs all unit and functional tests

So, if there’s a mistake in the migrations, it shows up when the  
script runs (i.e. migration fails or the tests fail). And it’s easy  
to fix the problem and do it again.

---

<div class="post-metadata">

**Author:** ![olbrich](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/5f9b8f/32.png) [@olbrich](https://www.ruby-forum.com/u/olbrich)\
**Post date:** [March 9, 2006, 7:15pm UTC](https://www.ruby-forum.com/t/testing-migrations/79083/5 "2006-03-09T19:15:30Z")

</div>

On Mar 9, 2006, at 9:27 AM, Joe Van D. wrote:

> - removes the development and test database
> - creates the development and test database
> - performs the migrations on the development database
> - loads my test fixtures into the development database
> - and runs all unit and functional tests

+1

–  
– Tom M.
