realtimex-crm 0.17.0 → 0.17.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "realtimex-crm",
3
- "version": "0.17.0",
3
+ "version": "0.17.1",
4
4
  "description": "RealTimeX CRM - A full-featured CRM built with React, shadcn-admin-kit, and Supabase. Fork of Atomic CRM with RealTimeX App SDK integration.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -0,0 +1,73 @@
1
+ -- Fix contacts_summary view to include email_fts and phone_fts columns for search functionality
2
+ -- The previous migration used c.* which doesn't include computed columns
3
+
4
+ DROP VIEW IF EXISTS contacts_summary CASCADE;
5
+
6
+ CREATE VIEW contacts_summary
7
+ WITH (security_invoker=on)
8
+ AS
9
+ SELECT
10
+ -- Explicit contact columns
11
+ c.id,
12
+ c.first_name,
13
+ c.last_name,
14
+ c.gender,
15
+ c.title,
16
+ c.email_jsonb,
17
+ c.phone_jsonb,
18
+ c.background,
19
+ c.avatar,
20
+ c.first_seen,
21
+ c.last_seen,
22
+ c.has_newsletter,
23
+ c.status,
24
+ c.tags,
25
+ c.company_id,
26
+ c.sales_id,
27
+ c.linkedin_url,
28
+ c.internal_heartbeat_score,
29
+ c.internal_heartbeat_status,
30
+ c.internal_heartbeat_updated_at,
31
+ c.external_heartbeat_status,
32
+ c.external_heartbeat_checked_at,
33
+ c.email_validation_status,
34
+ c.email_last_bounced_at,
35
+ c.linkedin_profile_status,
36
+ c.employment_verified_at,
37
+
38
+ -- Computed full-text search columns
39
+ jsonb_path_query_array(c.email_jsonb, '$[*].email')::text as email_fts,
40
+ jsonb_path_query_array(c.phone_jsonb, '$[*].number')::text as phone_fts,
41
+
42
+ -- Company relationship
43
+ comp.name as company_name,
44
+
45
+ -- Task and note aggregations
46
+ COUNT(DISTINCT t.id) as nb_tasks,
47
+ COUNT(DISTINCT cn.id) as nb_notes,
48
+ COUNT(DISTINCT t.id) FILTER (WHERE t.done_date IS NULL) as nb_open_tasks,
49
+
50
+ -- Task completion metrics
51
+ COUNT(DISTINCT t.id) FILTER (WHERE t.done_date IS NOT NULL) as nb_completed_tasks,
52
+ CASE
53
+ WHEN COUNT(DISTINCT t.id) > 0
54
+ THEN ROUND(COUNT(DISTINCT t.id) FILTER (WHERE t.done_date IS NOT NULL)::numeric / COUNT(DISTINCT t.id), 2)
55
+ ELSE 0
56
+ END as task_completion_rate,
57
+
58
+ -- Activity timestamps
59
+ MAX(cn.date) as last_note_date,
60
+ MAX(t.due_date) as last_task_activity,
61
+
62
+ -- Computed engagement indicator (days since last activity)
63
+ LEAST(
64
+ COALESCE(EXTRACT(EPOCH FROM (now() - c.last_seen))/86400, 999999),
65
+ COALESCE(EXTRACT(EPOCH FROM (now() - MAX(cn.date)))/86400, 999999),
66
+ COALESCE(EXTRACT(EPOCH FROM (now() - MAX(t.due_date)))/86400, 999999)
67
+ )::integer as days_since_last_activity
68
+
69
+ FROM contacts c
70
+ LEFT JOIN "contactNotes" cn ON c.id = cn.contact_id
71
+ LEFT JOIN tasks t ON c.id = t.contact_id
72
+ LEFT JOIN companies comp ON c.company_id = comp.id
73
+ GROUP BY c.id, comp.name;