generated from DFE-Digital/govuk-rails-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CPDNPQ-1216 Update list of independent schools offering govt.-funded …
…EY provision
- Loading branch information
1 parent
1eda61a
commit fcbd434
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
require "csv" | ||
|
||
namespace :update_eyl_funding_eligible_schools_list do | ||
desc "Make schools funding eligible for NPQEYL courses" | ||
task :update, %i[file_name] => :environment do |_t, args| | ||
file_name = args.file_name | ||
previous_file = "lib/eyl_funding_eligible_schools/2022-11-30/eligible-schools.csv" | ||
|
||
raise "File not found: #{file_name}" unless File.exist?(file_name) | ||
raise "File not found: #{previous_file}" unless File.exist?(previous_file) | ||
|
||
Rails.logger.info("Fetching previous schools from CSV file: #{previous_file}") | ||
|
||
previous_school_urns = CSV.parse(File.read(previous_file), headers: true).map { |row| row["gias_urn"] } | ||
|
||
Rails.logger.info("Fetched Records: #{previous_school_urns.count}") | ||
|
||
Rails.logger.info("Updating schools from CSV file: #{file_name}") | ||
|
||
updated_current_records = [] | ||
|
||
CSV.foreach(file_name, headers: true) do |row| | ||
gias_urn = row["gias_urn"] | ||
school = School.find_by(urn: gias_urn) | ||
|
||
if school.nil? | ||
# need to put logic to create new school | ||
else | ||
school&.update!(eyl_funding_eligible: true, establishment_status_code: 1, establishment_status_name: "Open") | ||
updated_current_records << school.urn | ||
end | ||
end | ||
|
||
Rails.logger.info("Update finished") | ||
|
||
Rails.logger.info("Updated Records: #{updated_current_records.count}") | ||
|
||
closed_school_urns = previous_school_urns - updated_current_records | ||
|
||
School.transaction do | ||
School.where(urn: closed_school_urns).update_all(establishment_status_code: 2, establishment_status_name: "Closed") | ||
end | ||
end | ||
end |