Testing Migrations


#1

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


#2

rake migrate RAILS_ENV=test

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


#3

Somehow that makes perfect sense! Thanks!

_Kevin


#4

On 9 Mar 2006 16:42:40 -0000, Kevin O.
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.


#5

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.