How (and whether) to populate rails application with initial data -


i've got rails application users have log in. therefore in order application usable, there must 1 initial user in system first person log in (they can create subsequent users). i've used migration add special user database.

after asking this question, seems should using db:schema:load, rather running migrations, set fresh databases on new development machines. unfortunately, doesn't seem include migrations insert data, set tables, keys etc.

my question is, what's best way handle situation:

  1. is there way d:s:l include data-insertion migrations?
  2. should not using migrations @ insert data way?
  3. should not pre-populating database data @ all? should update application code handles case there no users gracefully, , lets initial user account created live within application?
  4. any other options? :)

try rake task. example:

  1. create file /lib/tasks/bootstrap.rake
  2. in file, add task create default user:
     namespace :bootstrap       desc "add default user"       task :default_user => :environment         user.create( :name => 'default', :password => 'password' )       end        desc "create default comment"       task :default_comment => :environment         comment.create( :title => 'title', :body => 'first post!' )       end        desc "run bootstrapping tasks"       task :all => [:default_user, :default_comment]     end 
  1. then, when you're setting app first time, can rake db:migrate or rake db:schema:load, , rake bootstrap:all.

Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -