a better way to initialize database ONCE when rail server starts

Posted by Hadi on Stack Overflow See other posts from Stack Overflow or by Hadi
Published on 2010-06-07T03:22:02Z Indexed on 2010/06/07 3:32 UTC
Read the original article Hit count: 335

i would like to initialize database the first time the server is started, that involve calling a class method. Given the class name is: Product

At first i put an .rb file config\initializers\init.rb as it gets automatically called. Everything works ok, until the database is deleted, and i am trying to do rake db:migrate. rake db:migrate fails saying that cannot find 'product' table.

inside init.rb = Product.populate_db

The solution i came up is:

  1. I took out init.rb
  2. do rake db:migrate
  3. put back init.rb
  4. run the server.

My rails application is mainly for reporting and the data is seeded from other application, so i have to do the above step everyday

Is there a better way to do the initialization?

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about initialization