diff options
author | hellekin <hellekin@cepheide.org> | 2020-10-08 22:10:41 +0200 |
---|---|---|
committer | hellekin <hellekin@cepheide.org> | 2020-10-08 22:11:03 +0200 |
commit | 31850c6ca118b7828dbaa3ad1a87dab4287718f5 (patch) | |
tree | 7c0055b939a27eb2f38f42ca17ec671aeac4c221 /db/seeds.rb | |
parent | 0ab4ac71cdfe8b7dcf768ca0b68c8ef53040f1a2 (diff) | |
download | incommon-map-31850c6ca118b7828dbaa3ad1a87dab4287718f5.tar.gz |
Add categories, sections, and import data
Diffstat (limited to 'db/seeds.rb')
-rw-r--r-- | db/seeds.rb | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/db/seeds.rb b/db/seeds.rb index 8a4c670..ea9fc25 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -26,3 +26,25 @@ Taxonomy.find_or_create_by( uuid: '2519915f-d19c-4281-b758-f5ddb889d7fa', agent_id: dewey.id ) + +# Create French categories and sections +if Category.count == 0 + dewey_taxo = Taxonomy.first + cats = JSON.parse(IO.read('doc/import/categories-fr.json')) + cats.each do |cat| + c = Category.create(name: cat['name'], dewey_id: cat['id'], taxonomy_id: dewey_taxo.id, color: cat['color']) + cat['sections'].each do |sec| + Section.create(name: sec['name'], category_id: c.id, dewey_id: sec['id'], color: sec['color']) + end + end + # Now that we have all we need, update resources_sections... + Resource.all.each do |res| + sec_ids = res.feature['properties']['categories'] + next if sec_ids.empty? + sec_ids.each do |id| + s = Section.find_by(dewey_id: id) + res.sections << s if s.present? + res.save + end + end +end |