Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rake task to correct title fields within application document #2938

Merged
merged 1 commit into from
May 23, 2024

Conversation

Lubosky
Copy link
Contributor

@Lubosky Lubosky commented May 22, 2024

📝 A short description of the changes

Added rake task to correct titles for 'press book contact' and 'head of organisation' for 24/25 award year applications to use a whitelisted value where the match can be identified (uppercase/lowercase title, titles having trailing spaces or having a comma)

To run the task use bundle exec rake form_answers:backfill_whitelisted_titles

To get the incorrect titles run the following from Rails console:

require "csv"

query = %{
  SELECT
    form_answers.id,
    form_answers.urn,
    form_answers.document ->> 'head_of_business_title' AS head_of_business_title,
    form_answers.document ->> 'press_contact_details_title' AS press_contact_details_title
  FROM
    form_answers
  WHERE
    form_answers.award_year_id = 19
    AND(form_answers.document ->> 'head_of_business_title' IS NOT NULL
      OR form_answers.document ->> 'press_contact_details_title' IS NOT NULL)
    AND(form_answers.document ->> 'head_of_business_title' NOT IN('Mr', 'Mrs', 'Miss', 'Ms', 'Mx', 'Dr', 'Professor', 'Reverend', 'Sir', 'Baron', 'Baroness', 'Dame', 'Lady', 'Lord')
      OR form_answers.document ->> 'press_contact_details_title' NOT IN('Mr', 'Mrs', 'Miss', 'Ms', 'Mx', 'Dr', 'Professor', 'Reverend', 'Sir', 'Baron', 'Baroness', 'Dame', 'Lady', 'Lord'))
}.squish

result = ActiveRecord::Base.connection.execute(query)

headers = %w(id urn head_of_business_title press_contact_details_title)
file = Rails.root.join("tmp", "output.csv")

CSV.open(file, "w", write_headers: true, headers: headers) do |csv|
  result.to_a.each do |row| 
    csv << [row["id"], row["urn"], row["head_of_business_title"], row["press_contact_details_title"]] 
  end
end

🔗 Link to the relevant story (or stories)

Asana card here: https://app.asana.com/0/1200504523179345/1207364230758592/f

:shipit: Deployment implications

None

✅ Checklist

  • Features that cannot go live are behind a feature flag/env var or specify deploy date and open PR as draft
  • I have checked that commit messages make sense and explain the reasoning for each change
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • I have squashed any unnecessary or part-finished commits

🖼️ Screenshots (if appropriate - no PII/Prod data):

…tails_title` for form answers within current year
@dreamfall dreamfall merged commit 05bf737 into main May 23, 2024
12 checks passed
@dreamfall dreamfall deleted the backfill-user-titles-from-whitelist branch May 23, 2024 06:53
@TheDancingClown TheDancingClown mentioned this pull request May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants