Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rake db:schema:dump doesn't provide data migration info - is there an automated way to get this?

rake db:schema:dump

This command gives you the schema of a legacy database and you can build a migration for that database off the generated schema.

But if that database had data in it, it would be nice if there was a rake command to retrieve the data in a migration file generated by Rails.

Perhaps I'm dreaming - it's probably asking too much to think that Rails could look at the data in the legacy database and construct a migration for you from the existing data - something like this:

class LoadDefaultData < ActiveRecord::Migration
  def self.up
    bopeep = User.find_by_username 'bopeep'
    BlogPost.create(:title => 'test', :content => 'test', :author_id => bopeep.id, :status => 'ok')
  end

  def self.down
  end
end

Or is there a way?

like image 423
pez_dispenser Avatar asked Dec 13 '25 04:12

pez_dispenser


1 Answers

Tobias Lütke needed to migrate a database from one architecture to another but needed to copy the data across intact. To ensure that the format would be architecture agnostic, he's created a plugin that dumps the data to YAML and then reloads it back into the database at the other end. It's a simple rake task, and Tobi gives quick and easy instructions.

http://blog.leetsoft.com/2006/5/29/easy-migration-between-databases

This may help.

You may also like to look at YamlDB plugin http://opensource.heroku.com/ which can back up from one db type and restore to another. Here are some instructions

like image 179
Corban Brook Avatar answered Dec 14 '25 20:12

Corban Brook



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!