← all branches

feat/smarter-mrr

safe
37de5d2 · incrementalpre-PRreviewed 2026-08-10 19:05 UTC0H · 0M · 2L · 2I
The branch
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
The changes (whole branch)
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+201infra/posthog/insights.tf+211infra/posthog/dashboards.tf+20packages/database/src/seed-smarter-rate.ts+1140scripts/billing/smarter-mrr-refresh.ts+1160
Blast
5 files (+273/−3) in this window; whole branch 14 files +629/−2; no migrations, no API surface changes
analytics-only no-migration iac-cleanup script-managed-insight
typecheck· posthog-mrr-pivot.mjs is plain JS — no typecheck applicabletests· No automated tests for the pivot script (consistent with posthog-annotate.mjs pattern)terraform-completeness· All 8 resources removed from layout are also removed from insights.tf — no orphans

Findings · 4

correctness2

low

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.

info

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

low

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.

info

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.

History · 4 commits

  1. 37de5d2safeincremental0H · 0M · 2L2026-08-10 19:05current
  2. af89f54needs attentionincremental1H · 2M · 9L2026-08-10 17:36
  3. a4fbc2bneeds attentionincremental7H · 11M · 5L2026-08-08 00:42
  4. 4d95793needs attentionfull0H · 0M · 4L2026-08-07 19:28