You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Replace UserAlert's theft_alert_id and user_phone_id with alertable (#4032)
`user_alerts` had a column per referenced type, and the upcoming
`b_param` kind would have added a fifth. `theft_alert_id` and
`user_phone_id` become a polymorphic `alertable` pair. `bike_id` and
`organization_id` stay — `unassigned_bike_org` and
`theft_alert_without_photo` each carry two references, and `bike` is
read as a `Bike` in `create_notification?`, `email_subject` and the
admin filter.
- **Reads fall back to the legacy columns**, so this ships ahead of the
backfill. `for_alertable` matches the polymorphic pair *or* the old
column — without it `update_phone_waiting_confirmation` would duplicate
the 119k un-backfilled phone alerts rather than find them.
`Backfills::UserAlertAlertableJob` copies them across; run it from the
console, nothing schedules it. A follow-up drops the columns and the
fallback with them.
- **The backfill also deletes the duplicate phone alerts it would
otherwise strand.** The 2,015 duplicate `(user_id, kind, user_phone_id)`
groups in prod predate the uniqueness validation and are inert while
`alertable_id` is blank — but backfilling arms the validation, and the
survivor stops being able to save. It keeps the lowest id of each group,
which is the row `find_or_build_by` already returns.
- **The uniqueness validation keys off `UNIQ_KINDS`** instead of
applying to whatever sits in the alertable slot, because
`theft_alert_without_photo` duplicates are deliberate —
`update_theft_alert_without_photo` scopes its finder to `active`, so a
theft alert that loses its photo a second time gets a second alert.
That's what most of prod's 122 duplicate `(user_id, kind,
theft_alert_id)` groups are, and enforcing uniqueness would silently
kill the re-alert.
- **The admin table's Object column renders through
`admin_path_for_object`**, so `b_param` will link itself with no further
change.
0 commit comments