forked from fixin.me/fixin.me
Generate a random 12-character alphanumeric password instead of the hardcoded 'admin' (5 chars) which fails Devise's minimum length requirement of 8 characters. The generated password is printed to stdout so the operator knows what to use. Fixes #71
36 lines
1.4 KiB
Ruby
36 lines
1.4 KiB
Ruby
# This file should contain all the record creation needed to seed the database
|
|
# with its default values. The data can then be loaded with the
|
|
# bin/rails db:seed
|
|
# command (or created alongside the database with db:setup).
|
|
# Seeding process should be idempotent.
|
|
#
|
|
# Admin account setup
|
|
# -------------------
|
|
# The preferred way to create the first admin account is through the web setup
|
|
# wizard, which is shown automatically on the first visit when no admin exists.
|
|
# The wizard also lets you configure runtime options (e.g. skip e-mail
|
|
# confirmation) and seed the default units without using the command line.
|
|
#
|
|
# The block below provides an alternative CLI path for headless / automated
|
|
# deployments. It is skipped when an admin account already exists (e.g. after
|
|
# the web wizard has run).
|
|
|
|
User.transaction do
|
|
break if User.find_by status: :admin
|
|
|
|
password = SecureRandom.alphanumeric(12)
|
|
User.create! email: Rails.configuration.admin, password: password, status: :admin do |user|
|
|
user.skip_confirmation!
|
|
print "Creating #{user.status} account '#{user.email}' with password '#{password}'..."
|
|
end
|
|
puts "done."
|
|
|
|
rescue ActiveRecord::RecordInvalid => exception
|
|
puts "failed. #{exception.message}"
|
|
end
|
|
|
|
# Formulas will be deleted as dependent on Quantities
|
|
#[Source, Quantity, Unit].each { |model| model.defaults.delete_all }
|
|
|
|
require_relative 'seeds/units.rb'
|