RYP-F1 in Wave P. Everything scoped by the org through website.team_id with bound parameters only; tested at the SQL level on a throwaway cluster with the upstream migrations plus the fork's 90 and 91. - Identify: the edge collector (contract v1.1, additive) and the page tag accept `identify(userId, traits)` and a `user` on any event. Insights links the session (upstream session_link and session.distinct_id) and keeps one profile per (app, user) with first and last seen and merged traits (migration 91_railyard_people). Before this, an identify from the collector made Insights refuse the whole batch. - Saved cohorts: performed (with min times), not performed, trait equals and first seen within; counts are live. On fixtures a cohort equals a hand-written SQL count (two definitions). - Retention by property (country, language, screen, trait.<key>; day or week periods), breakdowns (path, referrer, country, language, screen, event, hostname, data.<key>, trait.<key>). - Export: events (31 days) or profiles, JSON or CSV, 100,000 rows; formula cells defused. - Delete by user id: one statement removes events, event data, session data, revenue, replay and heatmap rows, links, sessions and the profile in the org's apps only; recorded in railyard_erasure; a pending request is retried by POST /api/v1/erasure/sweep (hourly), so it is done within 24 h. - Console /api/v1/insights/* for an org's ry_ token: the org comes from the token, app names resolve to the org's own app, the platform token never leaves; served only with RAILYARD_REPLAY_LIVE=1 (denylist rule railyard-slot-replay), else 503 "arriving". - New packages: @railyard/insights-react-native (offline queue, identify kept across restarts, reset, consent) and @railyard/insights-server (server track and identify; profiles, cohorts, retention, breakdown, export, deleteUser through the console). No dependencies. Env: RAILYARD_REPLAY_LIVE (console). Migration: insights 91_railyard_people (idempotent; scratch Postgres only). Tests: insights fork 9/9 (depth SQL incl. isolation, cohort vs hand SQL, erasure), edge 18/18, console 125/125 (tsc clean), RN 3/3, server 5/5 (incl. copy lint), CLI 18/18. The upstream vitest suite runs in the image build on box 2 or CI (not on the Mac). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
45 lines
2.2 KiB
SQL
45 lines
2.2 KiB
SQL
-- Railyard fork addition (PY3.2, Insights depth): identified people, saved
|
|
-- cohorts and delete-by-user requests. Idempotent; applied only to scratch
|
|
-- Postgres by agents (the image's migrate step applies it on box 2 at deploy).
|
|
--
|
|
-- railyard_profile: one row per (app, user id) from `identify`: first and last
|
|
-- seen, and the latest traits (a later identify merges its traits in).
|
|
CREATE TABLE IF NOT EXISTS "railyard_profile" (
|
|
"website_id" UUID NOT NULL,
|
|
"distinct_id" VARCHAR(50) NOT NULL,
|
|
"first_seen" TIMESTAMPTZ(6) NOT NULL,
|
|
"last_seen" TIMESTAMPTZ(6) NOT NULL,
|
|
"traits" JSONB NOT NULL DEFAULT '{}'::jsonb,
|
|
CONSTRAINT "railyard_profile_pkey" PRIMARY KEY ("website_id", "distinct_id"),
|
|
CONSTRAINT "railyard_profile_traits_object" CHECK (jsonb_typeof("traits") = 'object')
|
|
);
|
|
CREATE INDEX IF NOT EXISTS "railyard_profile_website_last_seen_idx" ON "railyard_profile" ("website_id", "last_seen" DESC);
|
|
|
|
-- Saved cohorts per org (team). The definition is validated by the fork
|
|
-- (src/railyard/cohorts.ts) before it is stored; SQL is built from it with
|
|
-- bound parameters only.
|
|
CREATE TABLE IF NOT EXISTS "railyard_cohort" (
|
|
"cohort_id" UUID NOT NULL,
|
|
"team_id" UUID NOT NULL,
|
|
"name" VARCHAR(100) NOT NULL,
|
|
"definition" JSONB NOT NULL,
|
|
"created_at" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
"updated_at" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
CONSTRAINT "railyard_cohort_pkey" PRIMARY KEY ("cohort_id"),
|
|
CONSTRAINT "railyard_cohort_team_name_key" UNIQUE ("team_id", "name")
|
|
);
|
|
|
|
-- Delete-by-user requests: done at once when possible; a pending row is retried
|
|
-- by the sweep (POST /api/v1/erasure/sweep, hourly) until done, within 24 h.
|
|
CREATE TABLE IF NOT EXISTS "railyard_erasure" (
|
|
"request_id" UUID NOT NULL,
|
|
"team_id" UUID NOT NULL,
|
|
"website_id" UUID,
|
|
"distinct_id" VARCHAR(50) NOT NULL,
|
|
"requested_at" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
"done_at" TIMESTAMPTZ(6),
|
|
"rows_deleted" INTEGER,
|
|
CONSTRAINT "railyard_erasure_pkey" PRIMARY KEY ("request_id")
|
|
);
|
|
CREATE INDEX IF NOT EXISTS "railyard_erasure_pending_idx" ON "railyard_erasure" ("requested_at") WHERE "done_at" IS NULL;
|