Skip to content

Commit

Permalink
add seed for prod
Browse files Browse the repository at this point in the history
  • Loading branch information
adrienpoly committed Jan 28, 2024
1 parent a9c7400 commit afe9f12
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion db/seeds.rb
Original file line number Diff line number Diff line change
@@ -1 +1,21 @@
puts "To seed the database, run 'rails db:fixtures:load'"
if Rails.env.development?
puts "deleting all users in develoment environment only"
User.destroy_all
end

puts "Seeding users"

fixture_file_path = Rails.root.join("test", "fixtures", "users.yml")

fixture_content = File.read(fixture_file_path)

interpolated_users = YAML.load(ERB.new(fixture_content).result(binding))

interpolated_users.each do |key, user|
User.find_or_initialize_by(email: user["email"]) do |u|
u.update!(user)
end
puts "Seeded user #{user["email"]}"
end

puts "Seeding users completed"

0 comments on commit afe9f12

Please sign in to comment.