RoR Database seeding

Lately, I’m researching various RoR methods, technologies, and doing further ready on Agile software development methodologies. Below is a technique I’ve learned for seeding RoR databases.

    Database seeding technique

  1. Define the model and controller (nifty_scaffold is great for building quick, CRUD interfaces)
  2. Add data to the database via the CRUD interface
  3. Use sqlite3 command to extract the new seed data into a flat file.
    In this example, the table contains custom fields for name and description.

       cd [project folder]\db
       sqlite3 development.sqlite3
          .output [TABLE].txt;
          SELECT ID,name,description FROM [TABLE];
  4. Add import code to seeds.rb
    open('db/job_pay_cycles.txt') do |records| do |line|
        id,value,description = line Visit Website.chomp.split("|")
  5. Push the code into revision control (seeds and the new file
  6. Inform other developers.
      Other developers perform the following steps

    1. Other developers retrieve from revision control
    2. rake db:migrate — create the database tables for new models
    3. rake db:seed — to seed the new tables

Leave a Reply

Your email address will not be published. Required fields are marked *