Seed categories/subcategories based on their ID instead of their name

This commit is contained in:
Liam Morley 2021-11-04 16:34:22 -04:00
parent 4ee2345ba1
commit 556ff45117
2 changed files with 16 additions and 17 deletions

View file

@ -24,21 +24,20 @@ class Seeder
def seed_sqm_framework csv_file
CSV.parse(File.read(csv_file), headers: true) do |row|
category_name = row['Category'].strip
category = SqmCategory.find_or_create_by!(name: category_name)
category_id = row['Category ID'].strip
category = SqmCategory.find_or_create_by!(category_id: category_id)
category_slugs = {
'Teachers & Leadership' => 'teachers-and-leadership',
'School Culture' => 'school-culture',
'Resources' => 'resources',
'Academic Learning' => 'academic-learning',
'Community & Wellbeing' => 'community-and-wellbeing',
'1' => 'teachers-and-leadership',
'2' => 'school-culture',
'3' => 'resources',
'4' => 'academic-learning',
'5' => 'community-and-wellbeing',
}
category.update! description: row['Category Description'].strip, slug: category_slugs[category_name], sort_index: category_slugs.keys.index(category_name)
category.update! name: row['Category'].strip, description: row['Category Description'].strip, slug: category_slugs[category_id], sort_index: category_slugs.keys.index(category_id)
subcategory_name = row['Subcategory'].strip
subcategory = Subcategory.find_or_create_by! name: subcategory_name, sqm_category: category
subcategory.update! description: row['Subcategory Description'].strip
subcategory_id = row['Subcategory ID'].strip
subcategory = Subcategory.find_or_create_by! subcategory_id: subcategory_id, sqm_category: category
subcategory.update! name: row['Subcategory'].strip, description: row['Subcategory Description'].strip
measure_id = row['Measure ID'].strip
measure_name = row['Measures'].try(:strip)