简体   繁体   中英

How to Import YAML data into database in Ruby on Rails 3 project?

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:

  1. Under the 'db' folder of Ruby on Rails 3 project root folder, there is a 'backup' folder that stores all the .yml files.

    (Rails 3 root folder)=>db=>backup=>(all the *.yml files)

  2. 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.

  3. The .yml file content is like:

    name: user1

    title: SE1

    location: loc1

    name: user2

    title: SE2

    location: loc2

If there anyone can help on this issue? Thanks in advance!

Most likely he used yaml_db gem. You can use

gem install yaml_db

rake db:data:load_dir dir='backup'

to load your data if that is the case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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