I'm now working on a legacy Ruby on Rails project. I found the previous owner of this project exported data from Sqlite3 data tables to separate .yml files. Now I want to import these data from .yml files to their corresponding data tables, but didn't figure out how. The problem can be describe as:
我现在正在研究遗留的Ruby on Rails项目。我发现此项目的前任所有者将数据从Sqlite3数据表导出到单独的.yml文件。现在我想将这些数据从.yml文件导入到相应的数据表中,但是没有弄清楚如何。问题可以描述为:
-
Under the 'db' folder of Ruby on Rails 3 project root folder, there is a 'backup' folder that stores all the .yml files.
在Ruby on Rails 3项目根文件夹的“db”文件夹下,有一个“备份”文件夹,用于存储所有.yml文件。
(Rails 3 root folder)=>db=>backup=>(all the *.yml files)
(Rails 3根文件夹)=> db => backup =>(所有* .yml文件)
-
Each .yml file corresponds to a data table in the database. For example, suppose I have a 'users' table, then I have a 'users.yml' file that stores several user data as the seeds.
每个.yml文件对应于数据库中的数据表。例如,假设我有一个'users'表,那么我有一个'users.yml'文件,它存储了几个用户数据作为种子。
-
The .yml file content is like:
.yml文件内容如下:
name: user1
name:user1
title: SE1
标题:SE1
location: loc1
location:loc1
name: user2
name:user2
title: SE2
标题:SE2
location: loc2
位置:loc2
If there anyone can help on this issue? Thanks in advance!
如果有人可以帮助解决这个问题?提前致谢!
1 个解决方案
#1
1
Most likely he used yaml_db gem. You can use
他很可能使用了yaml_db gem。您可以使用
gem install yaml_db
rake db:data:load_dir dir='backup'
to load your data if that is the case.
在这种情况下加载您的数据。
#1
1
Most likely he used yaml_db gem. You can use
他很可能使用了yaml_db gem。您可以使用
gem install yaml_db
rake db:data:load_dir dir='backup'
to load your data if that is the case.
在这种情况下加载您的数据。