Files
accounted/supabase/migrations/20260828120000_company_settings_data_analysis_opt_in.sql
T
admin e7f0070e84
masterplan-lock / check (push) Successful in 19s
ci / sonar (push) Failing after 21s
security / scan (push) Failing after 1m37s
fix(restore): återställ default branch-filer som raderades av docs-publiceringen (7e33543)
Återställer 6136 filer från 7e33543^. Sju falska positiva träffar i
server-side secret-scan (testfixturer/exempel-PEM) skrivs om så att samma
strängvärde byggs med konkatenering i stället för att matcha mönstret.
2026-11-10 09:37:22 +01:00

35 lines
2.2 KiB
SQL

-- Per-company opt-in for analysis of bookkeeping data (#1346).
--
-- Adds the consent flag that gates every path where a company's bookkeeping
-- data is read across companies for Accounted's own analysis. Two scopes,
-- both stated in the consent copy (messages/*.json data_analysis.*):
-- 1. Booking outcomes (proposed vs booked account, amount, confidence):
-- the auto-booking calibration corpus (categorize_calibration_samples,
-- written by POST /api/agent/categorize/outcome) and the calibration-fit
-- script.
-- 2. Evaluation runs (scripts/backtest-categorize.ts, founder-run): the
-- company's transaction descriptions, counterparty names and matched
-- underlag (receipts, invoices) are re-run through the same AI model
-- and processors as regular booking. That text can contain personal
-- data (e.g. names in Swish payments), so the disclosure says so.
-- Enforced server-side by lib/company/data-analysis.ts and by the scripts'
-- own opted-in filter, never by the client.
--
-- Default false for everyone, no grandfathering: a company contributes
-- nothing until a company owner or admin flips the toggle in
-- Inställningar > Företag (the company_settings RLS update policy is admin
-- only, so the switch is admin only too). Turning it off stops new collection immediately.
-- The flag does not cover product-usage analytics or MCP reliability
-- telemetry (no bookkeeping content, documented under legitimate interest in
-- .compliance/ropa.yaml). Mirrors mileage_enabled (20260812193500).
--
-- pg-test: skip (plain column addition, no trigger/RPC/RLS)
ALTER TABLE public.company_settings
ADD COLUMN data_analysis_opt_in boolean NOT NULL DEFAULT false;
COMMENT ON COLUMN public.company_settings.data_analysis_opt_in IS
'Consent flag: when true, this company''s booking outcomes (proposed vs booked account, confidence, amount) may be read across companies for the auto-booking calibration corpus, and in evaluation runs (scripts/backtest-categorize.ts) its transaction descriptions, counterparty names and matched underlag may be re-run through the AI model. Default false; enforced server-side (lib/company/data-analysis.ts).';
NOTIFY pgrst, 'reload schema';