feat(analytics): add customer daily metrics data foundation
Some checks failed
Frontend Lint & Test / test (push) Has been cancelled
Publish Chatwoot EE docker images / build (linux/amd64, ubuntu-latest) (push) Has been cancelled
Publish Chatwoot EE docker images / build (linux/arm64, ubuntu-22.04-arm) (push) Has been cancelled
Publish Chatwoot EE docker images / merge (push) Has been cancelled
Publish Chatwoot CE docker images / build (linux/amd64, ubuntu-latest) (push) Has been cancelled
Publish Chatwoot CE docker images / build (linux/arm64, ubuntu-22.04-arm) (push) Has been cancelled
Publish Chatwoot CE docker images / merge (push) Has been cancelled
Run Chatwoot CE spec / security-scan (push) Has been cancelled
Run Chatwoot CE spec / lint-frontend (push) Has been cancelled
Run Chatwoot CE spec / frontend-tests (push) Has been cancelled
Run Chatwoot CE spec / lint-backend (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (0, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (1, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (10, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (11, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (12, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (13, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (14, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (15, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (2, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (3, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (4, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (5, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (6, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (7, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (8, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (9, 16) (push) Has been cancelled
Some checks failed
Frontend Lint & Test / test (push) Has been cancelled
Publish Chatwoot EE docker images / build (linux/amd64, ubuntu-latest) (push) Has been cancelled
Publish Chatwoot EE docker images / build (linux/arm64, ubuntu-22.04-arm) (push) Has been cancelled
Publish Chatwoot EE docker images / merge (push) Has been cancelled
Publish Chatwoot CE docker images / build (linux/amd64, ubuntu-latest) (push) Has been cancelled
Publish Chatwoot CE docker images / build (linux/arm64, ubuntu-22.04-arm) (push) Has been cancelled
Publish Chatwoot CE docker images / merge (push) Has been cancelled
Run Chatwoot CE spec / security-scan (push) Has been cancelled
Run Chatwoot CE spec / lint-frontend (push) Has been cancelled
Run Chatwoot CE spec / frontend-tests (push) Has been cancelled
Run Chatwoot CE spec / lint-backend (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (0, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (1, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (10, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (11, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (12, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (13, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (14, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (15, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (2, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (3, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (4, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (5, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (6, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (7, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (8, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (9, 16) (push) Has been cancelled
Add the migration + model for per-customer-per-day conversation analytics
(M2 phase 1b). Complements the per-account ConversationDailyMetric with a
per-contact/day view so reports can drill into individual customers and see
per-agent attribution, while the per-account table keeps the aggregate totals.
- customer_daily_metrics: unique (account_id, contact_id, date); message/
conversation/resolved/unresolved counts, avg session duration, top tags,
deal outcome breakdown, and agent_ids (jsonb).
- CustomerDailyMetric: belongs_to :account + :contact (Contact convention),
validations, JSONB getters defaulting to []/{}.
Approved by independent five-key pre-commit review deleg_434fc544
(passed=true, blocking arrays empty).
This commit is contained in:
25
db/migrate/20260819000001_create_customer_daily_metrics.rb
Normal file
25
db/migrate/20260819000001_create_customer_daily_metrics.rb
Normal file
@@ -0,0 +1,25 @@
|
||||
class CreateCustomerDailyMetrics < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
create_table :customer_daily_metrics do |t|
|
||||
t.bigint :account_id, null: false
|
||||
t.bigint :contact_id, null: false
|
||||
t.date :date, null: false
|
||||
t.string :timezone
|
||||
t.integer :message_count, default: 0, null: false
|
||||
t.integer :conversation_count, default: 0, null: false
|
||||
t.integer :resolved_count, default: 0, null: false
|
||||
t.integer :unresolved_count, default: 0, null: false
|
||||
t.float :avg_session_duration_seconds, default: 0.0, null: false
|
||||
t.jsonb :top_tags, default: [], null: false
|
||||
t.jsonb :deal_outcomes, default: {}, null: false
|
||||
t.jsonb :agent_ids, default: [], null: false
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :customer_daily_metrics, [:account_id, :contact_id, :date], unique: true,
|
||||
name: 'index_cdm_customer_on_account_contact_date'
|
||||
add_index :customer_daily_metrics, :contact_id
|
||||
add_index :customer_daily_metrics, :account_id
|
||||
add_index :customer_daily_metrics, :date
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user