How can I change my database data for new Rails App
I used rails to create next version of my application. My old app was using php and mysql. Also in new application I changed the database schem开发者_如何学编程a. So right now I have data with old schema and I want to migrate this data to rails application. What is the best way to re generate this data in proper way. Also I have a lot of connections and I changed the way they work
You have to define some temporary models to work with the old database, along with models for the new database schema. By connecting to two databases, read from one and write to other, you can migrate the data from old database to new database. Here and here is some help on how to connect to two databases in one rails application. Then you can write a script to run with rails runner which will load one model from old database and dump it into new database or a rake task which would do that.
You might want to try writing a rake task inside your rails app so you can load your rails environment. Then you can read the values you want from an external source (your original database or a serialized version of it) and create and save the corresponding models from your new rails app into the new database.
精彩评论