1
0
Fork 0

Seed scripts

This commit is contained in:
Alex Kotov 2019-10-21 15:51:15 +05:00
parent c2abf356f4
commit a82e1703d8
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
3 changed files with 17 additions and 0 deletions

1
db/data/scripts.csv Normal file
View file

@ -0,0 +1 @@
hello | Поприветствовать |
1 hello Поприветствовать

1
db/scripts/hello.rb Normal file
View file

@ -0,0 +1 @@
# frozen_string_literal: true

View file

@ -79,6 +79,21 @@ do |(org_unit_kind, codename, name)|
end
end
csv_foreach :scripts \
do |(codename, name)|
codename.strip!
name.strip!
source_code = File.read(
File.expand_path(File.join('scripts', "#{codename}.rb"), __dir__),
)
Script.where(codename: codename).first_or_create!(
name: name,
source_code: source_code,
)
end
Rails.application.settings(:superuser).tap do |config|
user = User.where(email: config[:email]).first_or_create! do |new_user|
new_user.password = config[:password]