rubyforgood / rubyforgood/awbw

Backfill contact_us_fyi communications as incoming, then drop the dual-condition checks

Open
#2,242 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

database cleanup
Dominant language
Ruby
Stars
15
Forks
26
Avg merge
12h 42m
Merged PRs (30d)
242

Description

Context

In #2239 we extended the "needs response" concept from contact_us_fyi notifications to all incoming communications. Because existing contact_us_fyi rows are stored as direction: "outgoing", the code currently has to check both conditions:

  • Notification#requires_response?kind == "contact_us_fyi" || incoming?
  • Notification.responded_status scope — where(kind: "contact_us_fyi").or(where(direction: "incoming")), and the "na" branch has to exclude both.

A contact_us_fyi is conceptually an incoming contact (the person reached out to us), so it should simply carry direction: "incoming". Once it does, the kind == "contact_us_fyi" half of every check is redundant and can go.

Work

  1. Create new contact_us_fyi notifications as incoming. Update wherever they're generated (contact-form flow / NotificationServices) so direction: "incoming" is set on creation. Do this first — otherwise removing the OR breaks newly-created rows.
  2. Backfill existing rows — a reversible data migration: Notification.where(kind: "contact_us_fyi", direction: "outgoing").update_all(direction: "incoming") (guard the down).
  3. Simplify the code once every contact_us_fyi is incoming:
    • requires_response?incoming?
    • responded_status → key off direction: "incoming" only:
      • "yes"where(direction: "incoming", responded: true)
      • "no"where(direction: "incoming", responded: false)
      • "na"where.not(direction: "incoming")
  4. Update specs in spec/models/notification_spec.rb (the .responded_status and #requires_response? groups) to reflect the single-condition logic.

Notes

  • Sanity-check that no contact_us_fyi should legitimately be outgoing before backfilling.
  • Files: app/models/notification.rb, plus the contact-form/notification-creation path.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with app/models/notification.rb, the contact-form/NotificationServices creation path, and the .responded_status and #requires_response? specs in spec/models/notification_spec.rb. Add the reversible backfill migration after confirming contact_us_fyi rows should be incoming, update creation and conditions, then run the notification specs and verify the migration’s down path is guarded.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
backend, databases
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.