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:
- is there way d:s:l include data-insertion migrations?
- should not using migrations @ insert data way?
- 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?
- any other options? :)
try rake task. example:
- create file /lib/tasks/bootstrap.rake
- 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
- then, when you're setting app first time, can rake db:migrate or rake db:schema:load, , rake bootstrap:all.
Comments
Post a Comment