27 lines
1.2 KiB
SQL
27 lines
1.2 KiB
SQL
-- Karten-Analytics: Views, vCard-Downloads und QR-Scans pro Karte.
|
|
-- ====================================================================
|
|
-- Privacy-by-default: nur das Notwendigste (Datum, Route, optional
|
|
-- Country aus IP), kein Tracking-Cookie, keine Personen-Identifikation.
|
|
-- Aufbewahrung: 365 Tage (Trigger / Cron später; keine harte Retention
|
|
-- aktuell).
|
|
|
|
create table if not exists public.card_view_log (
|
|
id uuid primary key default gen_random_uuid(),
|
|
employee_id uuid not null references public.employees(id) on delete cascade,
|
|
route text not null check (route in ('card', 'vcard', 'qr')),
|
|
occurred_at timestamptz not null default now(),
|
|
-- Optional: nur Country (z.B. "DE") aus dem CF/Edge-Header. Kein PII.
|
|
country text,
|
|
-- Referrer-Quelle gekürzt: nur Domain, keine vollständigen URLs.
|
|
referrer_domain text
|
|
);
|
|
|
|
create index if not exists card_view_log_employee_id_idx
|
|
on public.card_view_log (employee_id, occurred_at desc);
|
|
|
|
create index if not exists card_view_log_occurred_at_idx
|
|
on public.card_view_log (occurred_at desc);
|
|
|
|
alter table public.card_view_log enable row level security;
|
|
-- Service-Role-only — anon hat keinen Zugriff.
|