diff --git a/src/integrations/supabase/types.ts b/src/integrations/supabase/types.ts index ecb0ec9..5be89d8 100644 --- a/src/integrations/supabase/types.ts +++ b/src/integrations/supabase/types.ts @@ -2349,6 +2349,36 @@ export type Database = { }, ] } + ledger_templates: { + Row: { + created_at: string + created_by: string | null + description: string | null + entries: Json + id: string + name: string + updated_at: string + } + Insert: { + created_at?: string + created_by?: string | null + description?: string | null + entries?: Json + id?: string + name: string + updated_at?: string + } + Update: { + created_at?: string + created_by?: string | null + description?: string | null + entries?: Json + id?: string + name?: string + updated_at?: string + } + Relationships: [] + } message_attachments: { Row: { created_at: string diff --git a/supabase/migrations/20260426083507_ae86d25d-80c2-400c-bebd-31fce1634d09.sql b/supabase/migrations/20260426083507_ae86d25d-80c2-400c-bebd-31fce1634d09.sql new file mode 100644 index 0000000..d0d544d --- /dev/null +++ b/supabase/migrations/20260426083507_ae86d25d-80c2-400c-bebd-31fce1634d09.sql @@ -0,0 +1,31 @@ +-- Reusable ledger templates: a named bundle of ledger entry definitions +-- that can be applied to any homeowner collection ledger. +CREATE TABLE public.ledger_templates ( + id uuid PRIMARY KEY DEFAULT gen_random_uuid(), + name text NOT NULL, + description text, + entries jsonb NOT NULL DEFAULT '[]'::jsonb, + created_by uuid, + created_at timestamptz NOT NULL DEFAULT now(), + updated_at timestamptz NOT NULL DEFAULT now() +); + +ALTER TABLE public.ledger_templates ENABLE ROW LEVEL SECURITY; + +CREATE POLICY lt_select_auth ON public.ledger_templates + FOR SELECT TO authenticated USING (true); + +CREATE POLICY lt_insert_auth ON public.ledger_templates + FOR INSERT TO authenticated WITH CHECK (auth.uid() IS NOT NULL); + +CREATE POLICY lt_update_owner ON public.ledger_templates + FOR UPDATE TO authenticated + USING (is_admin(auth.uid()) OR created_by = auth.uid()); + +CREATE POLICY lt_delete_owner ON public.ledger_templates + FOR DELETE TO authenticated + USING (is_admin(auth.uid()) OR created_by = auth.uid()); + +CREATE TRIGGER trg_ledger_templates_touch + BEFORE UPDATE ON public.ledger_templates + FOR EACH ROW EXECUTE FUNCTION public.tg_set_updated_at();