Dispatch
The relation between a subscriber and a message: when a message is sent, it's dispatched to all subscribers. It's called Email in Postmark.
Columns
| Column | Type | Notes |
|---|---|---|
subscriber_id | bigint | required |
message_id | bigint | required |
sender_id | bigint | required |
postmark_message_id | string | ID of the email in Postmark, used to match webhooks |
postmark_message_stream_id | string | |
sent_at | timestamp | backs sent |
delivered_at | timestamp | backs delivered, set by the Delivery webhook |
opened_at | timestamp | backs opened, set by the Open webhook |
clicked_at | timestamp | backs clicked |
suppressed_at | timestamp | see Suppressible |
suppression_reason | integer | enum, see Suppressible |
Unique index on [subscriber_id, message_id].
Included concerns
Associations
belongs_to :subscriber→ Subscriberbelongs_to :message, counter_cache: :dispatches_count→ Messagebelongs_to :sender→ Senderhas_one :list, through: :message→ Listhas_one :subscription: the subscriber's subscription to the message's list
Validations
messageuniqueness per subscriber ("should be dispatched once per subscriber")
Timestamp booleans
sent, delivered, opened and clicked are backed by their *_at column through time_for_a_boolean, e.g. opened?, opened! (sets opened_at without saving) and opened = false.