Files
accounted/supabase/migrations/20240101000005_invoice_reminders.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

34 lines
1.7 KiB
SQL

-- Migration 5: Invoice Reminders
-- Automated reminder tracking with self-service action tokens
-- =============================================================================
-- invoice_reminders
-- =============================================================================
create table public.invoice_reminders (
id uuid primary key default uuid_generate_v4(),
invoice_id uuid references public.invoices (id) on delete cascade not null,
user_id uuid references auth.users on delete cascade not null,
reminder_level integer not null check (reminder_level in (1, 2, 3)),
sent_at timestamptz default now(),
email_to text not null,
response_type text check (response_type in ('marked_paid', 'disputed')),
response_at timestamptz,
action_token text unique not null default encode(gen_random_bytes(32), 'hex'),
action_token_used boolean default false,
created_at timestamptz not null default now()
);
alter table public.invoice_reminders enable row level security;
create policy "invoice_reminders_select" on public.invoice_reminders
for select using (auth.uid() = user_id);
create policy "invoice_reminders_insert" on public.invoice_reminders
for insert with check (auth.uid() = user_id);
create policy "invoice_reminders_update" on public.invoice_reminders
for update using (auth.uid() = user_id);
create policy "invoice_reminders_delete" on public.invoice_reminders
for delete using (auth.uid() = user_id);
create index idx_invoice_reminders_action_token on public.invoice_reminders (action_token);
create index idx_invoice_reminders_invoice on public.invoice_reminders (invoice_id);