开发者

Merging development data into production data

We've deployed an application last week. The problem is that we have some development data that we'd like to migrate to production, but the production databas开发者_JS百科e is already in use. So just importing and exporting SQL will pose the problem that the IDs won't match anymore.

Now, I've thought about eager loading all data into base objects, but there's no such thing as one base object. There are four objects with only has_many associations and a lot of objects with multiple belongs_to associations.

Is there any other method of exporting and importing that we could use to achieve what we want?


One way might be to dump the dev data to yaml (this plugin does that and there are probably others that will do the trick), and then use db/seeds.rb to write a script loading its contents and using rails models to recreate them on the production db with rake db:seed

rake db:seed won't hose your data (it just loads db/seeds.rb, see the source here and here), but be sure to backup your data before anything :)

I'd suggest playing with a sandbox app and db clone before going ahead and running this on production.


Export the development data as CSV, yaml, XML, or whatever format you want to use for this. Then you have a choice of what to do:

If only importing the data once then you can use a migration to load the data from the specified files. Be sure to include the files with the migration when you check it in to source control.

Load the data using the console (script/console production) and entering the commands manually. This might be a nicer way since you can examine the data that's going in and adjust as necessary.

If you're going to be doing this more then once then write a rake task that when given a filename or other identifier load the data into the database.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜