Moves Captain conversation outcomes from one row per conversation to one row per **engagement episode**: a new row each time demand for Captain (re)starts - first eligible message, a reopen after resolution, or (reserved) explicit assignment. Each episode has its own demand anchor, window, and trigger, so returning customers count as new demand and later cycles can't overwrite an earlier episode's handoff reason, resolution, or CSAT. Also adds `conversation_outcomes` associations on Account, Inbox, Conversation, and Captain::Assistant. ## Why this wasn't in #15233 The episode design came out of reviewing the wiring PR: per-conversation grain couldn't answer per-cycle questions without a patch per field. The table is unreleased with no writers, so changing the grain now is a pure schema swap - and landing it first means the tracker gets reviewed against the final model. ## What changed - Adds `episode_trigger`, `started_at`, `ended_at` - Drops `reopen_count` and `last_reopened_at` - reopens are episode rows now - Uniqueness moves from `(account, assistant, conversation)` to per-boundary `(account, conversation, started_at)` - Two partial unique indexes: one open episode per conversation, one initial episode per stream - Model: trigger enum, `started_at` uniqueness validation, `chronological`/`covering` scopes
13 lines
418 B
Ruby
13 lines
418 B
Ruby
FactoryBot.define do
|
|
factory :conversation_outcome do
|
|
account { create(:account) }
|
|
started_at { Time.current }
|
|
|
|
after(:build) do |outcome|
|
|
outcome.assistant ||= create(:captain_assistant, account: outcome.account)
|
|
outcome.inbox ||= create(:inbox, account: outcome.account)
|
|
outcome.conversation ||= create(:conversation, account: outcome.account, inbox: outcome.inbox)
|
|
end
|
|
end
|
|
end
|