私は以下のようなRakeスクリプトを持っていますが、データベースを削除したり、すべての移行を実行したり、データベースを再シードしたり、サンプルデータを追加しますか?レールはサンプルデータを追加するための推奨方法
namespace :db do
desc 'Fill database with sample data'
task populate: :environment do
purge_database
create_researchers
create_organisations
add_survey_groups_to_organisations
add_members_to_survey_groups
create_survey_responses_for_members
end
end
def purge_database
puts 'about to drop and recreate database'
system('rake db:drop')
puts 'database dropped'
system('rake db:create')
system('rake db:migrate')
system('rake db:seed')
puts 'Database recreated...'
end
def create_researchers
10.times do
researcher = User.new
researcher.email = Faker::Internet.email
researcher.save!
end
end
これはテスト環境用ですか? –
これは開発環境用です – Lee