From 192e8f688aa2f287e1e194cf5676cd572da3db29 Mon Sep 17 00:00:00 2001 From: Ben Date: Fri, 30 Aug 2024 13:56:38 +1200 Subject: [PATCH] chore: seed users --- README.md | 3 ++- db/seeds.rb | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f509e125..5e7b2a81 100644 --- a/README.md +++ b/README.md @@ -38,9 +38,10 @@ bin/rails secret # OTP encryption keys can be generated with: openssl rand -base64 10 | base64 -# Create the database and run the migrations +# Create the database, run the migrations and seed data (users) bin/rails db:create bin/rails db:migrate +bin/rails db:seed # To run the application you can do: bin/dev diff --git a/db/seeds.rb b/db/seeds.rb index 1effc8d7..e11f4ad9 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -11,3 +11,25 @@ # puts "Processing #{file.split('/').last}" # require file # end + +# Seed users +users = [{ + email: 'harvester@localhost', + username: 'harvester', + role: :harvester +}, { + email: 'admin@localhost', + username: 'admin', + role: :admin +}] + +users.each do |user| + User.find_or_create_by!(email: user[:email]) do |u| + u.username = user[:username] + u.password = 'password' + u.password_confirmation = 'password' + u.role = user[:role] + u.otp_required_for_login = false + u.enforce_two_factor = false + end +end