-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtriggers.sql
More file actions
48 lines (44 loc) · 2.05 KB
/
triggers.sql
File metadata and controls
48 lines (44 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
-- =====================================================
-- TURISTEI - TRIGGERS & AUTOMATIONS (DOCUMENTATION)
-- This file mirrors the production automation logic used in Supabase.
-- =====================================================
-- =====================================================
-- Financial automation: payment -> commissions -> payouts
-- =====================================================
-- Trigger: pagamentos_pedido_on_pago
-- Event: AFTER UPDATE on pagamentos_pedido
-- Condition: status changes to 'pago' (or equivalent)
-- Action:
-- - Generate per-item commission records (comissoes_itens)
-- using prestadores.comissao_override_percent when present,
-- otherwise config_plataforma.comissao_default_percent
-- - Generate payout summaries per provider (repasses_prestador)
-- using immutable values:
-- valor_bruto
-- comissao_plataforma_valor
-- valor_liquido
-- - Keep financial history immutable (no deletes)
-- =====================================================
-- Subscription automation: overdue -> suspension -> reactivation
-- =====================================================
-- Scheduled job (cron): subscription delinquency check
-- Action:
-- - Detect overdue providers (assinaturas / pagamentos_assinatura)
-- - Suspend access according to platform rules (no data deletion)
-- Trigger: subscription reactivation on payment
-- Event: AFTER INSERT/UPDATE on pagamentos_assinatura
-- Condition: payment marked as paid
-- Action:
-- - Reactivate provider subscription
-- - Restore access/visibility according to plan rules
-- =====================================================
-- Security hardening automation (critical)
-- =====================================================
-- Event Trigger: automatic EXECUTE hardening on function create/alter
-- Action:
-- - Revoke EXECUTE from PUBLIC/anon/authenticated
-- - Apply rule:
-- admin_* => GRANT EXECUTE to service_role only
-- app_* / meu_* => GRANT EXECUTE to authenticated only
-- others => closed by default
-- - Neutralize dangerous default privileges from Supabase