Files
accounted/supabase/migrations/20260909100300_seed_trial_capability_grants_zettle.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

40 lines
1.2 KiB
PL/PgSQL

-- REPLACE seed_trial_capability_grants to add zettle_sync while keeping the
-- byrå suppression from 20260826130300 / 20260901081417.
CREATE OR REPLACE FUNCTION public.seed_trial_capability_grants()
RETURNS trigger
LANGUAGE plpgsql
SECURITY DEFINER
SET search_path = public
AS $$
BEGIN
-- Byrå-team companies are covered by the team's agreement (WL-10):
-- no company-scoped trial, so no trial-expiry noise toward byrå clients.
IF NEW.team_id IS NOT NULL AND EXISTS (
SELECT 1 FROM public.teams t
WHERE t.id = NEW.team_id
AND t.kind = 'byra'
) THEN
RETURN NEW;
END IF;
-- Full PAID set as of 20260909100300; keep this VALUES list in step with
-- lib/entitlements/keys.ts PAID_CAPABILITIES whenever a key is added.
INSERT INTO public.capability_grants (company_id, capability_key, source, expires_at)
SELECT NEW.id, k.key, 'trial', NEW.created_at + interval '30 days'
FROM (VALUES
('ai'),
('bank_sync'),
('skatteverket'),
('email_send'),
('stripe_payments'),
('woocommerce_sync'),
('shopify_sync'),
('zettle_sync'),
('multi_user')
) AS k(key)
ON CONFLICT (company_id, team_id, capability_key, source) DO NOTHING;
RETURN NEW;
END;
$$;