# Managing migrations for separate databases

**URL:** <https://www.ruby-forum.com/t/managing-migrations-for-separate-databases/110996>\
**Category:** Rails\
**Created:** [August 1, 2007, 8:00pm UTC](https://www.ruby-forum.com/t/managing-migrations-for-separate-databases/110996 "2007-08-01T20:00:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [August 1, 2007, 8:00pm UTC](https://www.ruby-forum.com/t/managing-migrations-for-separate-databases/110996/1 "2007-08-01T20:00:10Z")

</div>

All,

I am working on an app. that deals with one legacy database about 95% of  
the time, and another smaller database only rarely.

However, I find myself needing to add tables to this smaller database,  
and would like to use migrations.

I understand that I can pass a RAILS\_ENV to the rake db:migrate task  
which will handle doing the work in the correct database.

But I’m wondering how to manage the migration files themselves. Can I  
create a subdir of RAILS\_ROOT/db and have that used for the migrations  
for this other database? Or do I have to override/modify the db:migrate  
task to allow it to look in other places for the migration files?

Thanks,  
Wes

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [August 15, 2007, 8:14pm UTC](https://www.ruby-forum.com/t/managing-migrations-for-separate-databases/110996/2 "2007-08-15T20:14:27Z")

</div>

A somewhat lame fix although it works:

I added a custom task into a .rake file under lib/tasks, called  
migrate\_archive which is basically a copy of the db:migrate task found  
under the standard Rails installation tasks.

This custom task looks in a subdirectory of db/migrate  
(db/migrate/archive) for an alternative set of migrations.

Obviously, to get these to take effect in another DB requires a rake  
command like

“rake db:migrate\_archive RAILS\_ENV=”

A better solution which I may implement later would be to make the  
alternative location completely dynamic to allow for N sets of different  
migrations for different DBs.

Wes
