# Skipping a data migration for Test environment

**URL:** <https://www.ruby-forum.com/t/skipping-a-data-migration-for-test-environment/91577>\
**Category:** Rails\
**Created:** [April 10, 2007, 5:41pm UTC](https://www.ruby-forum.com/t/skipping-a-data-migration-for-test-environment/91577 "2007-04-10T17:41:29Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jimmyether](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e9a140/32.png) [@jimmyether](https://www.ruby-forum.com/u/jimmyether)\
**Post date:** [April 10, 2007, 5:41pm UTC](https://www.ruby-forum.com/t/skipping-a-data-migration-for-test-environment/91577/1 "2007-04-10T17:41:29Z")

</div>

Hi all,

I’m loading fixture data via migrations into my application using the  
method  
described in the Agile book. This works beautifully for development and  
production environments. The only problem is, I don’t want these  
particular  
migrations to run when I do rake db:migrate RAILS\_ENV=test. For one,  
there  
is no reason to being loading data into the test db. And, more  
problematic  
for me, this causes foreign key constraint errors which abort the rake  
with  
the test db because I’m using Redhillonrails’ foreign\_key\_migrations  
plugin.

Any tips?

Thanks!

Ryan

---

<div class="post-metadata">

**Author:** ![jimmyether](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e9a140/32.png) [@jimmyether](https://www.ruby-forum.com/u/jimmyether)\
**Post date:** [April 10, 2007, 5:52pm UTC](https://www.ruby-forum.com/t/skipping-a-data-migration-for-test-environment/91577/2 "2007-04-10T17:52:29Z")

</div>

def self.up  
unless RAILS\_ENV=“test”  
… migration stuff …  
end  
end

Jason

---

<div class="post-metadata">

**Author:** ![jimmyether](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e9a140/32.png) [@jimmyether](https://www.ruby-forum.com/u/jimmyether)\
**Post date:** [April 10, 2007, 6:19pm UTC](https://www.ruby-forum.com/t/skipping-a-data-migration-for-test-environment/91577/3 "2007-04-10T18:19:36Z")

</div>

Yep, works perfectly. I had tried that but got the syntax wrong  
apparently.  
Thanks Jason!

On 4/10/07, Jason R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> >

–  
Ryan W.  
Lead Developer  
Capocus!

> **[Atlanta video production](https://abra.capoc.us/)**
>
> Your Video Team Capocus! Studios is located in Fayetteville, GA. We produce weekly YouTube Video Series Content, create and launch Digital Courses, produce Podcasts, and develop Evergreen Webinars. YouTube Series ...

Productive Web Publishing

---

<div class="post-metadata">

**Author:** ![jimmyether](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e9a140/32.png) [@jimmyether](https://www.ruby-forum.com/u/jimmyether)\
**Post date:** [April 10, 2007, 11:03pm UTC](https://www.ruby-forum.com/t/skipping-a-data-migration-for-test-environment/91577/4 "2007-04-10T23:03:21Z")

</div>

Actually, I spoke too soon. This code doesn’t actually work. I thought  
it  
did because the argument passed, but it just ignored the migration on  
all  
environments. It seems that rake pulls RAILS\_ENV from the actual setting  
in  
the application, not from the option passed at the command line (rake  
db:migrate RAILS\_ENV=test), which only seems to change the db it’s  
acting  
upon. Someone tell me if I’m wrong.

I also tried this, which also skips the migration on all environments:

unless ENV[‘RAILS\_ENV’] = “test”

# migration stuff

end

and, the following caused _all three_ environments to run the migration.

if ENV[‘RAILS\_ENV’] = “development” || “production”

# migration stuff

end

which I assumed was because the application is set to development. But  
for  
some crazy reason, this runs the migration on all environments as well!:

if ENV[‘RAILS\_ENV’] = “production”

# migration stuff

end

That, just doesn’t make sense. Anyone?

On 4/10/07, Ryan W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > end
> > 
> > > particular migrations to run when I do rake db:migrate RAILS\_ENV=test. For
> 
> Capocus!  
> [http://abra.capoc.us](http://abra.capoc.us)  
> Productive Web Publishing

–  
Ryan W.  
Lead Developer  
Capocus!

> **[Atlanta video production](https://abra.capoc.us/)**
>
> Your Video Team Capocus! Studios is located in Fayetteville, GA. We produce weekly YouTube Video Series Content, create and launch Digital Courses, produce Podcasts, and develop Evergreen Webinars. YouTube Series ...

Productive Web Publishing

---

<div class="post-metadata">

**Author:** ![jimmyether](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e9a140/32.png) [@jimmyether](https://www.ruby-forum.com/u/jimmyether)\
**Post date:** [April 10, 2007, 11:29pm UTC](https://www.ruby-forum.com/t/skipping-a-data-migration-for-test-environment/91577/5 "2007-04-10T23:29:23Z")

</div>

> Hints :

1/ any value not nil or false is true

> 2/ var = value returns value

🙂

> 

Hahaha! Oh man… I was _way_ over analyzing that one. Jeez… thanks  
for  
the Programming 101 kick in the arse Lionel. Step away from coding for a  
month and my mind goes to mush on the basics. 🙂

The winner:

unless ENV[‘RAILS\_ENV’] == “test”

# migration stuff

end

Puuuurfect.

---

<div class="post-metadata">

**Author:** ![jimmyether](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e9a140/32.png) [@jimmyether](https://www.ruby-forum.com/u/jimmyether)\
**Post date:** [April 10, 2007, 11:10pm UTC](https://www.ruby-forum.com/t/skipping-a-data-migration-for-test-environment/91577/6 "2007-04-10T23:10:22Z")

</div>

Ryan W. wrote the following on 10.04.2007 23:02 :

> # migration stuff
> 
> well!:
> 
> if ENV[‘RAILS\_ENV’] = “production”
> 
> # migration stuff
> 
> end
> 
> That, just doesn’t make sense. Anyone?

# I’ve only 2 bytes for you :

Hints :  
1/ any value not nil or false is true  
2/ var = value returns value

🙂

---

<div class="post-metadata">

**Author:** ![jimmyether](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e9a140/32.png) [@jimmyether](https://www.ruby-forum.com/u/jimmyether)\
**Post date:** [April 11, 2007, 4:48am UTC](https://www.ruby-forum.com/t/skipping-a-data-migration-for-test-environment/91577/7 "2007-04-11T04:48:40Z")

</div>

Yeah, I’ll take partial responsibility for that, as I did only put in a  
single ‘=’ in my post. Sorry about that.

Jason
