caelum0x b25099d68c feat(product-analytics): capture service with people, groups, caps, privacy jobs and retention (A1)
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>
2026-09-30 03:20:31 +03:00

33 lines
1.4 KiB
SQL

-- People: a person row, its distinct ids, and merge overrides.
-- Merges never rewrite stored events: queries read
-- coalesce(o.new_person_id, e.person_id) through pa.person_overrides.
create table if not exists pa.persons (
id uuid primary key default gen_random_uuid(),
project_id uuid not null,
properties jsonb not null default '{}'::jsonb,
is_identified boolean not null default false,
created_at timestamptz not null default now(),
version bigint not null default 0
);
create index if not exists persons_project_created_idx on pa.persons (project_id, created_at desc);
create table if not exists pa.person_distinct_ids (
project_id uuid not null,
distinct_id text not null check (length(distinct_id) between 1 and 200),
person_id uuid not null references pa.persons (id) on delete cascade,
version bigint not null default 0,
primary key (project_id, distinct_id)
);
create index if not exists person_distinct_ids_person_idx on pa.person_distinct_ids (person_id);
create table if not exists pa.person_overrides (
project_id uuid not null,
old_person_id uuid not null,
new_person_id uuid not null,
created_at timestamptz not null default now(),
primary key (project_id, old_person_id),
check (old_person_id <> new_person_id)
);
create index if not exists person_overrides_new_idx on pa.person_overrides (project_id, new_person_id);