From dd4a7d354e52d86123bbadf099506313ef278b40 Mon Sep 17 00:00:00 2001 From: Liam Morley Date: Thu, 14 Oct 2021 12:04:05 -0400 Subject: [PATCH] Add temporary rake task to record duplicate school names and slugs in CSV format --- lib/tasks/produce_csv.rake | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 lib/tasks/produce_csv.rake diff --git a/lib/tasks/produce_csv.rake b/lib/tasks/produce_csv.rake new file mode 100644 index 00000000..cac5ff8a --- /dev/null +++ b/lib/tasks/produce_csv.rake @@ -0,0 +1,23 @@ +require 'csv' + +namespace :dupes do + task record_csv: :environment do + csv_string = CSV.generate do |csv| + csv << [ 'District Name', 'School Name', 'School Slug', 'Creation Time', 'Updated Time' ] + + School.all.order(:district_id, :name, :created_at).each do |school| + schools = School.where name: school.name, district: school.district + if schools.length > 1 + csv << [school.district.name, school.name, school.slug, school.created_at.to_date, school.updated_at.to_date] + end + end + end + + puts csv_string + end +end + +# produce CSV file that displays: + # | district_name | school_name | school_slug | created_at | updated_at | + # | Dist1 | Jefferson High | jefferson-high | created_at | updated_at | + # | Dist1 | Jefferson High | lincoln-high | created_at | updated_at |