feat: KPIs con totales absolutos, backfill ads y ventas en cruce canal
Comparativas WoW/MoM/YoY muestran prev/Δ además del %; sync ads admite histórico desde 2025; tabla ads↔CRM añade cierres, ventas y ROAS. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
22
sql/leads_status_timing.sql
Normal file
22
sql/leads_status_timing.sql
Normal file
@@ -0,0 +1,22 @@
|
||||
-- CRM date correctness: preserve lead birth vs status change timing.
|
||||
-- Run in Supabase SQL editor (service role / dashboard).
|
||||
|
||||
alter table public.leads
|
||||
add column if not exists updated_at timestamptz;
|
||||
|
||||
alter table public.leads
|
||||
add column if not exists status_changed_at timestamptz;
|
||||
|
||||
comment on column public.leads.created_at is
|
||||
'When the contact entered Clientify / first seen (alta).';
|
||||
comment on column public.leads.updated_at is
|
||||
'Last webhook/sync touch.';
|
||||
comment on column public.leads.status_changed_at is
|
||||
'When status last changed (e.g. → cliente). Use this for “ventas en el periodo”.';
|
||||
|
||||
-- Backfill: unknown status timing → treat as created_at (best effort).
|
||||
update public.leads
|
||||
set
|
||||
updated_at = coalesce(updated_at, created_at, now()),
|
||||
status_changed_at = coalesce(status_changed_at, created_at, now())
|
||||
where updated_at is null or status_changed_at is null;
|
||||
Reference in New Issue
Block a user