Changes
Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com>
This commit is contained in:
co-authored by
renee-png
parent
cfbdb74860
commit
fc8bb95010
@@ -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();
|
||||
Reference in New Issue
Block a user