caelum0x efde34d3a3 feat(product-analytics): insight builders for trends, funnels, retention, paths, stickiness and lifecycle, with the shared fixture and hand-SQL tests (A2)
Pure (query, project) -> {sql, params} builders; property keys and values are
always bound. People resolve through pa.person_overrides. Postgres shapes are
ported from the vendored Umami SQL (copied unmodified into
src/insights/ported/umami with its MIT licence) and the semantics from the
upstream product-analytics runners (MIT, commit cbb1e9253027).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-30 04:50:51 +03:00

35 lines
1.1 KiB
SQL

-- Row level security for the insights tables (same policy as 0009): the
-- request role sees only pa.current_project(), and the service also binds
-- project_id in every query.
do $$
declare
t text;
begin
foreach t in array array[
'actions', 'cohorts', 'cohort_people', 'saved_insights', 'dashboards', 'dashboard_tiles',
'insight_cache', 'rollup_state', 'insight_versions'
]
loop
execute format('alter table pa.%I enable row level security', t);
execute format('drop policy if exists project_isolation on pa.%I', t);
execute format(
'create policy project_isolation on pa.%I for all to pa_app using (project_id = pa.current_project()) with check (project_id = pa.current_project())',
t
);
execute format('grant select, insert, update, delete on pa.%I to pa_app', t);
end loop;
end
$$;
do $$
begin
if exists (select 1 from pg_roles where rolname = 'anon') then
execute 'revoke all on all tables in schema pa from anon';
end if;
if exists (select 1 from pg_roles where rolname = 'authenticated') then
execute 'revoke all on all tables in schema pa from authenticated';
end if;
end
$$;