Files
acmcc/supabase/migrations/20260328210346_76632da3-4620-4629-a610-13875950370c.sql
2026-06-01 20:19:26 -04:00

25 lines
1.1 KiB
SQL

CREATE TABLE public.expense_bundles (
id UUID NOT NULL DEFAULT gen_random_uuid() PRIMARY KEY,
name TEXT NOT NULL,
description TEXT,
client_id UUID REFERENCES public.associations(id) ON DELETE CASCADE NOT NULL,
created_by UUID,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE TABLE public.bundle_expenses (
id UUID NOT NULL DEFAULT gen_random_uuid() PRIMARY KEY,
bundle_id UUID REFERENCES public.expense_bundles(id) ON DELETE CASCADE NOT NULL,
expense_id UUID REFERENCES public.billable_expenses(id) ON DELETE CASCADE NOT NULL,
added_at TIMESTAMPTZ NOT NULL DEFAULT now(),
UNIQUE(bundle_id, expense_id)
);
ALTER TABLE public.expense_bundles ENABLE ROW LEVEL SECURITY;
ALTER TABLE public.bundle_expenses ENABLE ROW LEVEL SECURITY;
CREATE POLICY "Authenticated users can manage expense_bundles" ON public.expense_bundles FOR ALL TO authenticated USING (true) WITH CHECK (true);
CREATE POLICY "Authenticated users can manage bundle_expenses" ON public.bundle_expenses FOR ALL TO authenticated USING (true) WITH CHECK (true);