简体   繁体   English

如何更改新Rails应用程序的数据库数据

[英]How can I change my database data for new Rails App

I used rails to create next version of my application. 我使用Rails创建了我的应用程序的下一个版本。 My old app was using php and mysql. 我的旧应用使用的是php和mysql。 Also in new application I changed the database schema. 同样在新应用程序中,我更改了数据库架构。 So right now I have data with old schema and I want to migrate this data to rails application. 因此,现在我有具有旧架构的数据,并且想要将此数据迁移到Rails应用程序。 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. 在这里这里有一些关于如何在一个Rails应用程序中连接到两个数据库的帮助。 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. 然后,您可以编写一个脚本以与RailsRunner一起运行,该脚本将从旧数据库中加载一个模型并将其转储到新数据库或rake任务中。

You might want to try writing a rake task inside your rails app so you can load your rails environment. 您可能想尝试在Rails应用程序中编写一个rake任务,以便可以加载Rails环境。 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. 然后,您可以从外部源(您的​​原始数据库或该数据库的序列化版本)中读取所需的值,然后将新Rails应用程序中的相应模型创建并保存到新数据库中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM