2018-12-01 18:42:36 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-03-24 20:40:10 +00:00
|
|
|
require 'csv'
|
2018-12-01 18:42:36 +00:00
|
|
|
|
2019-06-23 15:59:44 +00:00
|
|
|
federal_subjects_filename = Rails.root.join 'config', 'federal_subjects.csv'
|
2019-08-04 21:11:44 +00:00
|
|
|
contact_networks_filename = Rails.root.join 'config', 'contact_networks.csv'
|
2019-03-24 20:40:10 +00:00
|
|
|
|
2019-07-22 09:14:14 +00:00
|
|
|
CSV.foreach(
|
|
|
|
federal_subjects_filename,
|
|
|
|
col_sep: '|',
|
|
|
|
) do |(id, english_name, native_name, number, timezone, centre)|
|
2019-07-19 21:59:07 +00:00
|
|
|
id = Integer(id.strip)
|
2019-03-24 20:40:10 +00:00
|
|
|
english_name.strip!
|
2019-07-19 21:59:07 +00:00
|
|
|
native_name.strip!
|
2019-07-19 22:52:14 +00:00
|
|
|
number = Integer(number.strip.sub(/\A0*/, ''))
|
2019-07-20 02:40:56 +00:00
|
|
|
timezone.strip!
|
2019-07-22 09:14:14 +00:00
|
|
|
centre.strip!
|
2018-12-01 18:42:36 +00:00
|
|
|
|
2019-07-19 21:59:07 +00:00
|
|
|
FederalSubject.where(id: id).first_or_create! do |new_federal_subject|
|
|
|
|
new_federal_subject.english_name = english_name
|
2019-06-23 15:59:44 +00:00
|
|
|
new_federal_subject.native_name = native_name
|
2019-07-19 22:52:14 +00:00
|
|
|
new_federal_subject.number = number
|
2019-07-20 02:40:56 +00:00
|
|
|
new_federal_subject.timezone = timezone
|
2019-07-22 09:14:14 +00:00
|
|
|
new_federal_subject.centre = centre
|
2019-04-27 12:40:12 +00:00
|
|
|
end
|
2018-12-01 18:42:36 +00:00
|
|
|
end
|
2018-12-04 01:57:16 +00:00
|
|
|
|
2019-08-04 21:11:44 +00:00
|
|
|
CSV.foreach(
|
|
|
|
contact_networks_filename,
|
|
|
|
col_sep: '|',
|
|
|
|
) do |(id, nickname, public_name)|
|
|
|
|
id = Integer(id.strip)
|
|
|
|
nickname.strip!
|
|
|
|
public_name.strip!
|
|
|
|
|
|
|
|
ContactNetwork.where(id: id).first_or_create! do |new_contact_network|
|
|
|
|
new_contact_network.nickname = nickname
|
|
|
|
new_contact_network.public_name = public_name
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-12-09 03:56:06 +00:00
|
|
|
Rails.application.settings(:superuser).tap do |config|
|
2018-12-09 03:07:39 +00:00
|
|
|
User.where(email: config[:email]).first_or_create! do |new_user|
|
|
|
|
new_user.password = config[:password]
|
2018-12-09 02:14:33 +00:00
|
|
|
new_user.confirmed_at = Time.zone.now
|
2019-02-01 23:09:59 +00:00
|
|
|
new_user.account = Account.create!(
|
2019-04-28 13:34:46 +00:00
|
|
|
nickname: config[:nickname],
|
2019-02-01 23:09:59 +00:00
|
|
|
public_name: config[:public_name],
|
2019-04-28 13:34:46 +00:00
|
|
|
biography: config[:biography],
|
2019-02-01 23:09:59 +00:00
|
|
|
)
|
2018-12-09 02:14:33 +00:00
|
|
|
end.account.add_role :superuser
|
|
|
|
end
|