feat/smarter-mrr
safe37de5d2 · incrementalpre-PRreviewed 2026-08-10 19:05 UTC0H · 0M · 2L · 2I- Purpose
- Bring Smarter (Energía Real) off-platform MRR into the main analytics dashboard as a first-class product, replacing event-based per-tile tracking with warehouse-driven rows in the interactive master pivot.
- Goal
- Smarter MRR visible in the master pivot as producto='Smarter Billing'; FX written to Supabase plan metadata so HogQL can read it; stale event-based tiles and their Terraform resources removed.
- Sub-goals
- SG-1: Smarter as UNION ALL product row in pivot SQL (reports × USD/report × FX from custom-smarter plan metadata)
- SG-2: smarter-mrr-refresh.ts simplified to FX-only write; PostHog event emission removed
- SG-3: seed-smarter-rate.ts stores rate fields as STRINGS and preserves FX on re-seed via jsonb_set ON CONFLICT
- SG-4: 8 dead insight resources + 2 layout tiles removed from both dashboards.tf and insights.tf (no orphans)
- SG-5: New mrr_tendencia_producto + mrr_tendencia_plan trend-line insights replace removed time-series tiles
- SG-6: posthog-api-insights.md registry updated to document the pivot script as SOT
- What
- posthog-mrr-pivot.mjs gains a Smarter Billing UNION row; smarter-mrr-refresh.ts stripped of PostHog events (FX-only write); seed preserves refreshed FX; 8 Terraform insight resources + their dashboard tiles removed.
- Why
- Previous approach emitted per-org PostHog events shown in separate tiles — fragmented MRR view, diverged from the D3 warehouse-SOT model. Consolidating into the pivot gives Smarter the same product axis with interactive group-by.
- Areas
- scripts/posthog-mrr-pivot.mjs+20−1infra/posthog/insights.tf+21−1infra/posthog/dashboards.tf+2−0packages/database/src/seed-smarter-rate.ts+114−0scripts/billing/smarter-mrr-refresh.ts+116−0
- Blast
- 5 files (+273/−3) in this window; whole branch 14 files +629/−2; no migrations, no API surface changes
Findings · 4
correctness2
ensureVariables fetches only page 1 of insight variables
scripts/posthog-mrr-pivot.mjs:78
GET /insight_variables/?page=1 — if the project exceeds 100 variables the .find() will miss existing ones and create duplicates instead of reusing them.
CROSS JOIN smarter_rate silently produces 0 Smarter rows if plan is unseeded
scripts/posthog-mrr-pivot.mjs:136
If custom-smarter plan is absent, Smarter disappears from the pivot without error. A LEFT JOIN with COALESCE defaults would make the pivot self-healing.
improvement2
upsert() matches insight by substring — fragile if naming drifts
scripts/posthog-mrr-pivot.mjs:183
i.name.includes('pivote maestro') would match any insight with that substring. Exact match (i.name === TABLE_NAME) before falling back would be safer.
Month columns baked in UTC — edge case on month boundaries in MX timezone
scripts/posthog-mrr-pivot.mjs:51
monthColumns() uses Date.UTC(); a run at 23:00 UTC on month-end could label columns off by one for a MX-timezone team.