aboutsummaryrefslogtreecommitdiff
path: root/db/seeds.rb
diff options
context:
space:
mode:
Diffstat (limited to 'db/seeds.rb')
-rw-r--r--db/seeds.rb22
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