apps/product-analytics: a standalone Node 22 service (hono, pg, fflate, jose)
that speaks the public SDK capture protocol (/e/, /i/v0/e/, /batch/,
/capture/, /engage/, /groups/, /flags/?v=2, /decide/, /array/:token/config)
over JSON, gzip, base64 and form data, stores into Postgres (monthly
partitions, RLS on pa.project_id plus a bound project_id), resolves people
with identify/alias/merge semantics ported from the upstream persons code
(MIT, cbb1e9253027), applies the console caps (byte copy, drift-tested),
meters scribase.analytics.events behind RAILYARD_LIVE, drops IPs, runs
privacy deletions as visible jobs and trims to each plan's window.
Hand-offs created now (empty on purpose):
- src/routes.ts mounts src/insights/routes.ts -> A2
- src/routes.ts mounts src/{replay,heatmaps,surveys,experiments,exports}/routes.ts -> A3
- src/remote-config/sections.ts (replay, heatmaps, surveys providers) -> A3
- src/flags/variants.ts (returns null) -> A3
- src/replay/gdpr.ts and src/surveys/gdpr.ts privacy hooks -> A3
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
32 lines
1.3 KiB
SQL
32 lines
1.3 KiB
SQL
-- Ingest bookkeeping: receipts (a retried batch is stored once), monthly
|
|
-- usage per project (the product's own count), and the first stored event.
|
|
|
|
create table if not exists pa.ingest_receipts (
|
|
project_id uuid not null,
|
|
uuid uuid not null,
|
|
received_at timestamptz not null default now(),
|
|
primary key (project_id, uuid)
|
|
);
|
|
create index if not exists ingest_receipts_received_idx on pa.ingest_receipts (received_at);
|
|
|
|
create table if not exists pa.usage_monthly (
|
|
project_id uuid not null,
|
|
org_id uuid not null,
|
|
month date not null check (extract(day from month) = 1),
|
|
received bigint not null default 0 check (received >= 0),
|
|
stored bigint not null default 0 check (stored >= 0),
|
|
capped bigint not null default 0 check (capped >= 0),
|
|
dropped bigint not null default 0 check (dropped >= 0),
|
|
primary key (project_id, month)
|
|
);
|
|
create index if not exists usage_monthly_org_idx on pa.usage_monthly (org_id, month);
|
|
|
|
create table if not exists pa.project_firsts (
|
|
project_id uuid primary key,
|
|
org_id uuid not null,
|
|
event_uuid uuid not null,
|
|
event text not null,
|
|
at timestamptz not null
|
|
);
|
|
create index if not exists project_firsts_org_idx on pa.project_firsts (org_id);
|