From 0500d7c93f06235f974578efdcf15904dbd5650f Mon Sep 17 00:00:00 2001 From: rebuilt Date: Wed, 14 Dec 2022 14:13:36 -0800 Subject: [PATCH] Add a way to delete non-lowell schools and districts --- lib/tasks/data.rake | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/tasks/data.rake b/lib/tasks/data.rake index c603afdc..1465bb14 100644 --- a/lib/tasks/data.rake +++ b/lib/tasks/data.rake @@ -69,6 +69,16 @@ namespace :data do Rails.cache.clear end + desc 'delete non-lowell schools and districts' + task delete_non_lowell: :environment do + schools = School.all.reject { |s| s.district.name == 'Lowell' } + Respondent.where(school: schools).delete_all + Survey.where(school: schools).delete_all + schools.each { |school| school.delete } + districts = District.all.reject { |district| district.name == 'Lowell' } + districts.each { |district| district.delete } + end + task load_survey_responses_21_22: :environment do Dir.glob(Rails.root.join('data', 'survey_responses', '*2021-22*.csv')).each do |filepath| puts "=====================> Loading data from csv at path: #{filepath}"