# Using rails to migrate between databases

**URL:** <https://www.ruby-forum.com/t/using-rails-to-migrate-between-databases/86051>\
**Category:** Rails\
**Created:** [February 19, 2007, 1:15pm UTC](https://www.ruby-forum.com/t/using-rails-to-migrate-between-databases/86051 "2007-02-19T13:15:33Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![nyxx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/13edae/32.png) [@nyxx](https://www.ruby-forum.com/u/nyxx)\
**Post date:** [February 19, 2007, 1:15pm UTC](https://www.ruby-forum.com/t/using-rails-to-migrate-between-databases/86051/1 "2007-02-19T13:15:33Z")

</div>

Hey people,

I have the following question to present to you all. I need some basic  
information about how to use rails to migrate the dataset of my project  
between two types of database systems.

First, the live data now exists in MSSQL and also uses a very poorly  
designed database scheme.

Next, the data needs to be migrated to MySQL, also using a completely  
re-designed schema, where tables have transformed and sometimes even  
dropped.

How (in very general lines) woudl I accomplish this using ruby on rails?  
I’m not really looking for any detailed examples or anything, just a  
place to start.

Thanks in advance,

danny

---

<div class="post-metadata">

**Author:** ![nyxx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/13edae/32.png) [@nyxx](https://www.ruby-forum.com/u/nyxx)\
**Post date:** [February 19, 2007, 1:29pm UTC](https://www.ruby-forum.com/t/using-rails-to-migrate-between-databases/86051/2 "2007-02-19T13:29:36Z")

</div>

Assuming your application is running in rails already, you can run  
‘rake db\_schema\_dump’. This will create db/schema.rb, which you can  
then modify before importing into your MySQL database by running ‘rake  
db:migrate’. If you’re not already running Ruby on Rails, you could  
always set up a new rails application and point it to your current  
MSSQL database (instructions here:  
[http://wiki.rubyonrails.org/rails/pages/HowtoConnectToMicrosoftSQLServer](http://wiki.rubyonrails.org/rails/pages/HowtoConnectToMicrosoftSQLServer)).

Good luck.

On Feb 19, 7:15 am, Daniel Owen van Dommelen \<rails-mailing-

---

<div class="post-metadata">

**Author:** ![nyxx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/13edae/32.png) [@nyxx](https://www.ruby-forum.com/u/nyxx)\
**Post date:** [February 19, 2007, 1:32pm UTC](https://www.ruby-forum.com/t/using-rails-to-migrate-between-databases/86051/3 "2007-02-19T13:32:55Z")

</div>

Theron Parlin wrote:

> Assuming your application is running in rails already, you can run  
> ‘rake db\_schema\_dump’. This will create db/schema.rb, which you can  
> then modify before importing into your MySQL database by running ‘rake  
> db:migrate’. If you’re not already running Ruby on Rails, you could  
> always set up a new rails application and point it to your current  
> MSSQL database (instructions here:  
> [http://wiki.rubyonrails.org/rails/pages/HowtoConnectToMicrosoftSQLServer](http://wiki.rubyonrails.org/rails/pages/HowtoConnectToMicrosoftSQLServer)).
> 
> Good luck.
> 
> On Feb 19, 7:15 am, Daniel Owen van Dommelen \<rails-mailing-

I do not think this is an option for me since I’m working with an  
enormous database.

There was a hint I got from the person who’s managing this project and  
it was somewhat in the line of using SQL queries to get the data into  
the code and then using this data I have to create the models to support  
the new database layout.

any thoughts on that?

Thanks!

---

<div class="post-metadata">

**Author:** ![nyxx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/13edae/32.png) [@nyxx](https://www.ruby-forum.com/u/nyxx)\
**Post date:** [February 19, 2007, 1:34pm UTC](https://www.ruby-forum.com/t/using-rails-to-migrate-between-databases/86051/4 "2007-02-19T13:34:30Z")

</div>

by the way, the old database scheme is not following the rails  
conventions…

---

<div class="post-metadata">

**Author:** ![nyxx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/13edae/32.png) [@nyxx](https://www.ruby-forum.com/u/nyxx)\
**Post date:** [February 19, 2007, 1:47pm UTC](https://www.ruby-forum.com/t/using-rails-to-migrate-between-databases/86051/5 "2007-02-19T13:47:37Z")

</div>

Do schemas differ a lot structuraly? Are relations more or less  
preserved structuraly at least?

– fxn

---

<div class="post-metadata">

**Author:** ![nyxx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/13edae/32.png) [@nyxx](https://www.ruby-forum.com/u/nyxx)\
**Post date:** [February 19, 2007, 1:59pm UTC](https://www.ruby-forum.com/t/using-rails-to-migrate-between-databases/86051/6 "2007-02-19T13:59:28Z")

</div>

Xavier N. wrote:

> Do schemas differ a lot structuraly? Are relations more or less  
> preserved structuraly at least?
> 
> – fxn

no the schema are pretty much complete different, also relations have  
been totally redesigned. The old schema has been done by a student who  
created it as his internship project, but has really dropped the ball  
back then. This is also one of the reasons I had to complete redo the  
database, about a year later now.

I might have found my information though. I’m diving into DBI module,  
and it thusfar is proving to be the thing I was looking for… If anyone  
is interested follow this link:

[http://www.kitebird.com/articles/ruby-dbi.html](http://www.kitebird.com/articles/ruby-dbi.html)

thanks for the attention people!

---

<div class="post-metadata">

**Author:** ![nyxx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/13edae/32.png) [@nyxx](https://www.ruby-forum.com/u/nyxx)\
**Post date:** [February 19, 2007, 10:27pm UTC](https://www.ruby-forum.com/t/using-rails-to-migrate-between-databases/86051/7 "2007-02-19T22:27:57Z")

</div>

Daniel,

You might be able to use ActiveWarehouse ETL to extract from the old  
system, transform the data as necessary and load into the new system -  
that’s what it was designed for (although primarily for data  
warehouses but there is nothing that locks it into that).

More info: [http://activewarehouse.rubyforge.org/etl](http://activewarehouse.rubyforge.org/etl)

V/r  
Anthony

On 2/19/07, Daniel Owen van Dommelen [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> back then. This is also one of the reasons I had to complete redo the
> 
> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

–  
Cell: 808 782-5046  
Current Location: Melbourne, FL
