Schema — RelatoriosRS
Banco: Insights (Supabase self-hosted)
- - Container:
deploy-vps-db-1 - - Database:
postgres - - Schema:
insights
Tabelas Existentes
insights.conversations ✅
| Coluna | Tipo | Descrição |
| -------- | ------ | ----------- |
| id | UUID | PK |
| chatwoot_id | INTEGER | ID da conversa no Chatwoot |
| chatwoot_account_id | INTEGER | Account (sempre 1) |
| chatwoot_inbox_id | INTEGER | Inbox |
| status | TEXT | 'open' ou 'resolved' |
| contact_name | TEXT | Nome do contato |
| contact_phone | TEXT | Telefone |
| contact_email | TEXT | |
| message_count | INTEGER | Total de mensagens |
| first_response_at | TIMESTAMP | Primeira resposta do agente |
| created_at | TIMESTAMP | Criação da conversa |
| last_activity_at | TIMESTAMP | Última atividade |
| assignee_id | UUID | Agente (ref: insights.agents.id) |
| assignee_chatwoot_id | INTEGER | ID do agente no Chatwoot |
| labels | TEXT | Labels |
| inbox_name | TEXT | Nome do inbox |
| Coluna | Tipo | |
| -------- | ------ | |
| id | UUID | |
| chatwoot_id | INTEGER | |
| name | TEXT | |
| TEXT | ||
| Coluna | Tipo | Notas |
| -------- | ------ | ------- |
| id | INTEGER | PK |
| conversation_id | INTEGER | FK → conversations.id |
| account_id | INTEGER | |
| inbox_id | INTEGER | |
| message_type | INTEGER | 0=incoming, 1=outgoing, 2=activity |
| content | TEXT | Texto da mensagem |
| content_type | INTEGER | 0=text |
| created_at | TIMESTAMP | |
| sender_type | VARCHAR | 'User' ou 'Contact' |
| sender_id | BIGINT | |
| source_id | TEXT | |
| Coluna | Tipo | |
| -------- | ------ | |
| id | INTEGER | |
| name | TEXT | |
| phone_number | TEXT | |
| TEXT | ||
| Coluna | Tipo | |
| -------- | ------ | |
| id | INTEGER | |
| name | TEXT | |
| TEXT | ||
| Valor | Tipo | Descrição |
| ------- | ------ | ----------- |
| 0 | incoming | Mensagem do cliente |
| 1 | outgoing | Mensagem do agente |
| 2 | activity | Evento do sistema (conversa criada, status mudado, etc.) |
Queries Úteis
`sql
-- Contar mensagens por tipo para um agente
SELECT m.message_type, COUNT(*)
FROM messages m
JOIN conversations c ON c.chatwoot_id = m.conversation_id
WHERE c.assignee_chatwoot_id = 11
GROUP BY m.message_type;
-- Texto das últimas 5 mensagens de uma conversa
SELECT m.content, m.sender_name, m.created_at
FROM insights.messages m
WHERE m.conversation_id = 'uuid-da-conversa'
ORDER BY m.created_at DESC
LIMIT 5;
-- Conversas sem mensagens capturadas
SELECT c.id FROM insights.conversations c
LEFT JOIN insights.messages m ON m.conversation_id = c.id
WHERE m.id IS NULL;
`
Atualizado: 2026-06-26