refactor: make member_email_deliveries a typed log - #2832
Merged
Conversation
mroderick
force-pushed
the
refactor/type-member-email-deliveries
branch
from
August 31, 2026 11:09
d322e0e to
0507893
Compare
Rows recorded which member received an email but not which email it was, and the chaser's "already emailed" exclusion only works because it is the sole writer of the table. Type each row with the mailer action that sent it (email_type; 'chaser' for all existing rows), enforce one row per (member, email_type) with a unique index, and scope the chaser's exclusion to its own rows so its behavior is unchanged regardless of what else gets logged. Log writes are replay-tolerant: a retried delivery job no longer raises after the email has already gone out.
mroderick
force-pushed
the
refactor/type-member-email-deliveries
branch
from
August 31, 2026 11:21
0507893 to
89b9986
Compare
mroderick
marked this pull request as ready for review
August 31, 2026 12:00
KimberleyCook
approved these changes
Aug 31, 2026
olleolleolle
approved these changes
Aug 31, 2026
|
|
||
| it 'logs one row per member even if the delivery is performed twice' do | ||
| expect do | ||
| described_class.with(member: member).chaser.deliver_now |
Collaborator
There was a problem hiding this comment.
Suggested change
| described_class.with(member: member).chaser.deliver_now | |
| described_class.with(member:).chaser.deliver_now |
Co-authored-by: Olle Jonsson <olle.jonsson@gmail.com>
Co-authored-by: Olle Jonsson <olle.jonsson@gmail.com>
Co-authored-by: Olle Jonsson <olle.jonsson@gmail.com>
Co-authored-by: Olle Jonsson <olle.jonsson@gmail.com>
Co-authored-by: Olle Jonsson <olle.jonsson@gmail.com>
7 tasks
Co-authored-by: Olle Jonsson <olle.jonsson@gmail.com>
Collaborator
Author
|
Thank you for your review @olleolleolle. I've created #2833 to enforce the use of the shorthand style, so you don't need to suggest it on every review going forwards. |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
member_email_deliveriesrecords which member received an email but not which email it was, and the three-month chaser's "already emailed" exclusion only works because it is the sole writer of the table — any other mailer action that starts logging would silently change chaser behavior.Change
email_typecolumn, populated with the mailer action that sent the email (email_type: action_namein theEmailDeliveryconcern). The migration backfills existing rows with'chaser'(all 439 are chasers) and then drops the column default, so every writer must set the type explicitly(member_id, email_type)— a member can only ever have one chaser row, enforced by Postgres rather than by query convention. Built:concurrentlyin its own migration so the column DDL stays atomic and reversibleemail_type: 'chaser'rows only — identical behavior today (it is the only writer), and immune to whatever else gets logged laterfind_or_create_by!so a retried delivery job can't raise on the unique index after the email has already gone out (acreate!would fail the job and cause a re-delivery loop); content columns are written on first creation onlyNo behavior change for anything that exists today: the only logging mailer action is the chaser, and its eligibility outcome is identical under scoped vs blanket exclusion.
Testing
email_type, and a new spec proves a replayed delivery logs only one rowBuilt on #2829 + #2830 (both merged).