1
0
Fork 0

Reorder seeds

This commit is contained in:
Alex Kotov 2019-10-01 03:37:59 +05:00
parent ceb465da22
commit 84d36e3aca
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08

View file

@ -6,9 +6,9 @@ seeds_dirname = Rails.root.join 'config', 'seeds'
federal_subjects_filename = seeds_dirname.join 'federal_subjects.csv' federal_subjects_filename = seeds_dirname.join 'federal_subjects.csv'
contact_networks_filename = seeds_dirname.join 'contact_networks.csv' contact_networks_filename = seeds_dirname.join 'contact_networks.csv'
org_unit_kinds_filename = seeds_dirname.join 'org_unit_kinds.csv'
relation_statuses_filename = seeds_dirname.join 'relation_statuses.csv' relation_statuses_filename = seeds_dirname.join 'relation_statuses.csv'
relation_transitions_filename = seeds_dirname.join 'relation_transitions.csv' relation_transitions_filename = seeds_dirname.join 'relation_transitions.csv'
org_unit_kinds_filename = seeds_dirname.join 'org_unit_kinds.csv'
CSV.foreach( CSV.foreach(
federal_subjects_filename, federal_subjects_filename,
@ -41,6 +41,25 @@ CSV.foreach contact_networks_filename, col_sep: '|' do |(id, codename, name)|
end end
end end
CSV.foreach(
org_unit_kinds_filename,
col_sep: '|',
) do |(codename, parent, short_name, name)|
codename.strip!
parent = parent.strip.presence
short_name.strip!
name.strip!
next if OrgUnitKind.find_by codename: codename
OrgUnitKind.create!(
codename: codename,
short_name: short_name,
name: name,
parent_kind: parent.nil? ? nil : OrgUnitKind.find_by!(codename: parent),
)
end
CSV.foreach relation_statuses_filename, col_sep: '|' do |(codename, name)| CSV.foreach relation_statuses_filename, col_sep: '|' do |(codename, name)|
codename.strip! codename.strip!
name.strip! name.strip!
@ -67,25 +86,6 @@ CSV.foreach relation_transitions_filename, col_sep: '|' do |(from, to, name)|
end end
end end
CSV.foreach(
org_unit_kinds_filename,
col_sep: '|',
) do |(codename, parent, short_name, name)|
codename.strip!
parent = parent.strip.presence
short_name.strip!
name.strip!
next if OrgUnitKind.find_by codename: codename
OrgUnitKind.create!(
codename: codename,
short_name: short_name,
name: name,
parent_kind: parent.nil? ? nil : OrgUnitKind.find_by!(codename: parent),
)
end
Rails.application.settings(:superuser).tap do |config| Rails.application.settings(:superuser).tap do |config|
user = User.where(email: config[:email]).first_or_create! do |new_user| user = User.where(email: config[:email]).first_or_create! do |new_user|
new_user.password = config[:password] new_user.password = config[:password]