1 Reply Latest reply on Nov 14, 2012 2:59 PM by Hector Meza

    Seeding a Rhom Database

    Alicia Wilkerson

      I know how to seed the database, but I only want to seed it once and a while.  I have a list of files that represent tables.  I want to seed them right now only if the tables don't exist.


      How can I check to see if the table exists or not? 


      Where is the best place to seed the tables?  I'm assuming app initialization.


      I'm new at this so any help ya'll can give would be awesome.


      Thanks in advance.

        • Re: Seeding a Rhom Database
          Hector Meza

          Alicia, where to seeding the data base depends on the application needs.  On Startup would be the logical location,

          /app/application.rb file  The following is an example of seeding two models (tables) from one JSON file.  checking if it is empty is the first part.  (Ticket and Event are the two Models)



          #Seed the database with initial data

              tickets = Ticket.find(:all)   

              if tickets.empty?

                 fileName = File.join(Rho::RhoApplication::get_base_app_path(), '/public/VenueTickets.txt')lines = File.read(fileName)

                 jsonContent = Rho::JSON.parse(lines)

                jsonContent.each {


                 Ticket.create("Tknbr" => json['Tknbr'], "ID" => json['ID'], "Event" => json['Event'], "Seat" => json[ 'Seat'], "Section" => json['Section'], "Price" => json['Price'])

                  Event.create("ID" => json['ID'], "Event" => json['Event'], "Image" => json['Image'])





          #The catalog has been loaded already there is nothing to do




          Hope this helps.