Commit b5b2ec6b1b853cf259de8801372d4ef962456f7c
1 parent
b4fb4f6e
Exists in
master
and in
2 other branches
rails_apps_composer: set up database
Showing
3 changed files
with
22 additions
and
0 deletions
Show diff stats
@@ -0,0 +1,8 @@ | @@ -0,0 +1,8 @@ | ||
1 | +class CreateAdminService | ||
2 | + def call | ||
3 | + user = User.find_or_create_by!(email: Rails.application.secrets.admin_email) do |user| | ||
4 | + user.password = Rails.application.secrets.admin_password | ||
5 | + user.password_confirmation = Rails.application.secrets.admin_password | ||
6 | + end | ||
7 | + end | ||
8 | +end |
config/secrets.yml
@@ -11,6 +11,12 @@ | @@ -11,6 +11,12 @@ | ||
11 | # if you're sharing your code publicly. | 11 | # if you're sharing your code publicly. |
12 | 12 | ||
13 | development: | 13 | development: |
14 | + admin_name: First User | ||
15 | + admin_email: user@example.com | ||
16 | + admin_password: changeme | ||
17 | + email_provider_username: <%= ENV["GMAIL_USERNAME"] %> | ||
18 | + email_provider_password: <%= ENV["GMAIL_PASSWORD"] %> | ||
19 | + domain_name: example.com | ||
14 | secret_key_base: 59f3123227a531056f058c06f4c0ac40c072d8b23855c29ee6f4c8cf75176f0ef51cb18e2f41b52246fba93f360a7a2831fd910be24c8a527fb3253f72a54d4c | 20 | secret_key_base: 59f3123227a531056f058c06f4c0ac40c072d8b23855c29ee6f4c8cf75176f0ef51cb18e2f41b52246fba93f360a7a2831fd910be24c8a527fb3253f72a54d4c |
15 | 21 | ||
16 | test: | 22 | test: |
@@ -19,4 +25,10 @@ test: | @@ -19,4 +25,10 @@ test: | ||
19 | # Do not keep production secrets in the repository, | 25 | # Do not keep production secrets in the repository, |
20 | # instead read values from the environment. | 26 | # instead read values from the environment. |
21 | production: | 27 | production: |
28 | + admin_name: <%= ENV["ADMIN_NAME"] %> | ||
29 | + admin_email: <%= ENV["ADMIN_EMAIL"] %> | ||
30 | + admin_password: <%= ENV["ADMIN_PASSWORD"] %> | ||
31 | + email_provider_username: <%= ENV["GMAIL_USERNAME"] %> | ||
32 | + email_provider_password: <%= ENV["GMAIL_PASSWORD"] %> | ||
33 | + domain_name: <%= ENV["DOMAIN_NAME"] %> | ||
22 | secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> | 34 | secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> |
db/seeds.rb
@@ -5,3 +5,5 @@ | @@ -5,3 +5,5 @@ | ||
5 | # | 5 | # |
6 | # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) | 6 | # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) |
7 | # Mayor.create(name: 'Emanuel', city: cities.first) | 7 | # Mayor.create(name: 'Emanuel', city: cities.first) |
8 | +user = CreateAdminService.new.call | ||
9 | +puts 'CREATED ADMIN USER: ' << user.email |