<commit_before>namespace :after_party do
  desc 'Deployment task: update_calendar_ids_on_new_columns'
  task update_calendar_ids_on_new_columns: :environment do
    puts "Running deploy task 'update_calendar_ids_on_new_columns'"

    # Put your task implementation HERE.
    ActiveRecord::Base.transaction do

      SchoolGroup.all.each do |school_group|
        next unless school_group.default_calendar_area
        calendar_area_name = school_group.default_calendar_area.title
        calendar = Calendar.where("title like ?", "%#{calendar_area_name}%").first
        school_group.update!(default_template_calendar_id: calendar.id)
      end

      highlands_calendar = Calendar.find_by(title: 'Highland')

      if highlands_calendar.present? && (highlands_school_group = SchoolGroup.find_by(name: 'Highlands'))
        highlands_school_group.update(default_template_calendar_id: highlands_calendar.id)
      end

      SchoolOnboarding.all.each do |school_onboarding|
        calendar_area = school_onboarding.calendar_area || school_onboarding.school_group.default_calendar_area

        calendar_area_name = calendar_area.title
        calendar = Calendar.where("title like ?", "%#{calendar_area_name}%").first

        school_onboarding.update!(template_calendar_id: calendar.id)
      end

      Scoreboard.all.each do |scoreboard|
        calendar_area_name = scoreboard.calendar_area.title
        calendar = Calendar.where("title like ?", "%#{calendar_area_name}%").first

        scoreboard.update!(academic_year_calendar_id: calendar.id)
      end
    end



    # Update task as completed.  If you remove the line below, the task will
    # run with every deploy (or every time you call after_party:run).
    AfterParty::TaskRecord.create version: AfterParty::TaskRecorder.new(__FILE__).timestamp
  end
end<commit_msg>Use DB relationship rather than titles<commit_after>namespace :after_party do
  desc 'Deployment task: update_calendar_ids_on_new_columns'
  task update_calendar_ids_on_new_columns: :environment do
    puts "Running deploy task 'update_calendar_ids_on_new_columns'"

    # Put your task implementation HERE.
    ActiveRecord::Base.transaction do

      SchoolGroup.all.each do |school_group|
        next unless school_group.default_calendar_area
        calendar = school_group.default_calendar_area.calendars.where(template: true).first
        school_group.update!(default_template_calendar_id: calendar.id) if calendar.present?
      end

      SchoolOnboarding.all.each do |school_onboarding|
        calendar_area = school_onboarding.calendar_area || school_onboarding.school_group.default_calendar_area

        calendar = calendar_area.calendars.where(template: true).first
        school_onboarding.update!(template_calendar_id: calendar.id) if calendar.present?
      end

      Scoreboard.all.each do |scoreboard|
        calendar = scoreboard.calendar_area.calendars.where(template: true).first
        scoreboard.update!(academic_year_calendar_id: calendar.id) if calendar.present?
      end
    end

    # Update task as completed.  If you remove the line below, the task will
    # run with every deploy (or every time you call after_party:run).
    AfterParty::TaskRecord.create version: AfterParty::TaskRecorder.new(__FILE__).timestamp
  end
end
{'fraction_non_alphanumeric': 0.07769347496206373, 'fraction_numerical': 0.0, 'mean_word_length': 4.158059467918623, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6543476', 'n_tokens_mistral': 950, 'n_tokens_neox': 913, 'n_words': 200}