# Migrate database to a new one using migrations

**URL:** <https://www.ruby-forum.com/t/migrate-database-to-a-new-one-using-migrations/61140>\
**Category:** Rails\
**Created:** [May 20, 2006, 10:47pm UTC](https://www.ruby-forum.com/t/migrate-database-to-a-new-one-using-migrations/61140 "2006-05-20T22:47:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matias\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8c91f0/32.png) [@Matias\_S](https://www.ruby-forum.com/u/Matias_S)\
**Post date:** [May 20, 2006, 10:47pm UTC](https://www.ruby-forum.com/t/migrate-database-to-a-new-one-using-migrations/61140/1 "2006-05-20T22:47:18Z")

</div>

Hi,

I’ve an applicattion actually in production wich i wrote in php last  
year. Now, I’m working on a new version in Ruby/Rails.

So, can someone tell me how can I generate a migration so that every  
time I run it the “data” from the old db get’s copied to the new one??

Note that \_I’ve already the schema, I want something that automatically  
could copy the field old\_id of the table DB1.\_my\_old\_table to the field  
id of DB2.my\_table.

Thanks.

---

<div class="post-metadata">

**Author:** ![Matias\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8c91f0/32.png) [@Matias\_S](https://www.ruby-forum.com/u/Matias_S)\
**Post date:** [May 20, 2006, 11:15pm UTC](https://www.ruby-forum.com/t/migrate-database-to-a-new-one-using-migrations/61140/2 "2006-05-20T23:15:09Z")

</div>

What I did was save a dump of my MySQL database, edit it using a text  
editor until  
postgresql stopped complaining, and reloaded it into postgresql. Then I  
saved the db from  
postgresql on one machine and tried to restore it to postgresql on  
another, only to find  
that version 8.1.3 somehow differed enough from postgresql 8.1.2 so that  
more hand-editing  
was necessary. I hope you have better luck.

One alternative might be to create an app using SOA to feed one database  
from another. A  
nice exercise in rails/ruby programming. Well within it’s capabilities.

I did use migrations for the schema, though.

Warren S.

---

<div class="post-metadata">

**Author:** ![Matias\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8c91f0/32.png) [@Matias\_S](https://www.ruby-forum.com/u/Matias_S)\
**Post date:** [May 21, 2006, 3:46pm UTC](https://www.ruby-forum.com/t/migrate-database-to-a-new-one-using-migrations/61140/3 "2006-05-21T15:46:52Z")

</div>

Why can’t you just dump the data into an SQL file, and then reload it in  
the second database? Mysql has a “mysqldump” program that can get the  
dump you need. If you’re operating inside the same DB instance, you can  
actually use SELECT INTO statements to achieve the same effect, but you  
have to do one statement for each table.
