Changes
Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com>
This commit is contained in:
co-authored by
renee-png
parent
aa24b0c843
commit
6041e3ca9c
@@ -446,6 +446,48 @@ export type Database = {
|
||||
},
|
||||
]
|
||||
}
|
||||
document_templates: {
|
||||
Row: {
|
||||
body: string
|
||||
created_at: string
|
||||
created_by: string | null
|
||||
description: string | null
|
||||
fields: Json
|
||||
font_family: string
|
||||
font_size_pt: number
|
||||
id: string
|
||||
kind: string
|
||||
name: string
|
||||
updated_at: string
|
||||
}
|
||||
Insert: {
|
||||
body?: string
|
||||
created_at?: string
|
||||
created_by?: string | null
|
||||
description?: string | null
|
||||
fields?: Json
|
||||
font_family?: string
|
||||
font_size_pt?: number
|
||||
id?: string
|
||||
kind?: string
|
||||
name: string
|
||||
updated_at?: string
|
||||
}
|
||||
Update: {
|
||||
body?: string
|
||||
created_at?: string
|
||||
created_by?: string | null
|
||||
description?: string | null
|
||||
fields?: Json
|
||||
font_family?: string
|
||||
font_size_pt?: number
|
||||
id?: string
|
||||
kind?: string
|
||||
name?: string
|
||||
updated_at?: string
|
||||
}
|
||||
Relationships: []
|
||||
}
|
||||
documents: {
|
||||
Row: {
|
||||
case_id: string
|
||||
@@ -652,6 +694,53 @@ export type Database = {
|
||||
}
|
||||
Relationships: []
|
||||
}
|
||||
generated_documents: {
|
||||
Row: {
|
||||
body: string | null
|
||||
created_at: string
|
||||
created_by: string | null
|
||||
id: string
|
||||
kind: string
|
||||
name: string
|
||||
payload: Json
|
||||
storage_path: string | null
|
||||
template_id: string | null
|
||||
updated_at: string
|
||||
}
|
||||
Insert: {
|
||||
body?: string | null
|
||||
created_at?: string
|
||||
created_by?: string | null
|
||||
id?: string
|
||||
kind?: string
|
||||
name: string
|
||||
payload?: Json
|
||||
storage_path?: string | null
|
||||
template_id?: string | null
|
||||
updated_at?: string
|
||||
}
|
||||
Update: {
|
||||
body?: string | null
|
||||
created_at?: string
|
||||
created_by?: string | null
|
||||
id?: string
|
||||
kind?: string
|
||||
name?: string
|
||||
payload?: Json
|
||||
storage_path?: string | null
|
||||
template_id?: string | null
|
||||
updated_at?: string
|
||||
}
|
||||
Relationships: [
|
||||
{
|
||||
foreignKeyName: "generated_documents_template_id_fkey"
|
||||
columns: ["template_id"]
|
||||
isOneToOne: false
|
||||
referencedRelation: "document_templates"
|
||||
referencedColumns: ["id"]
|
||||
},
|
||||
]
|
||||
}
|
||||
homeowners: {
|
||||
Row: {
|
||||
address: string | null
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
-- Documents templates and generated docs
|
||||
|
||||
CREATE TABLE public.document_templates (
|
||||
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
name text NOT NULL,
|
||||
description text,
|
||||
kind text NOT NULL DEFAULT 'general', -- 'general' | 'pleading'
|
||||
body text NOT NULL DEFAULT '',
|
||||
fields jsonb NOT NULL DEFAULT '[]'::jsonb, -- [{key, label, type}]
|
||||
font_family text NOT NULL DEFAULT 'Bookman Old Style',
|
||||
font_size_pt integer NOT NULL DEFAULT 12,
|
||||
created_by uuid,
|
||||
created_at timestamptz NOT NULL DEFAULT now(),
|
||||
updated_at timestamptz NOT NULL DEFAULT now()
|
||||
);
|
||||
|
||||
ALTER TABLE public.document_templates ENABLE ROW LEVEL SECURITY;
|
||||
|
||||
CREATE POLICY "doc_templates_select_auth" ON public.document_templates
|
||||
FOR SELECT TO authenticated USING (true);
|
||||
CREATE POLICY "doc_templates_insert_auth" ON public.document_templates
|
||||
FOR INSERT TO authenticated WITH CHECK (auth.uid() IS NOT NULL);
|
||||
CREATE POLICY "doc_templates_update_owner" ON public.document_templates
|
||||
FOR UPDATE TO authenticated USING (is_admin(auth.uid()) OR created_by = auth.uid());
|
||||
CREATE POLICY "doc_templates_delete_owner" ON public.document_templates
|
||||
FOR DELETE TO authenticated USING (is_admin(auth.uid()) OR created_by = auth.uid());
|
||||
|
||||
CREATE TRIGGER trg_doc_templates_updated
|
||||
BEFORE UPDATE ON public.document_templates
|
||||
FOR EACH ROW EXECUTE FUNCTION public.tg_set_updated_at();
|
||||
|
||||
CREATE TABLE public.generated_documents (
|
||||
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
name text NOT NULL,
|
||||
template_id uuid REFERENCES public.document_templates(id) ON DELETE SET NULL,
|
||||
kind text NOT NULL DEFAULT 'general',
|
||||
payload jsonb NOT NULL DEFAULT '{}'::jsonb,
|
||||
body text,
|
||||
storage_path text,
|
||||
created_by uuid,
|
||||
created_at timestamptz NOT NULL DEFAULT now(),
|
||||
updated_at timestamptz NOT NULL DEFAULT now()
|
||||
);
|
||||
|
||||
ALTER TABLE public.generated_documents ENABLE ROW LEVEL SECURITY;
|
||||
|
||||
CREATE POLICY "gen_docs_select_owner" ON public.generated_documents
|
||||
FOR SELECT TO authenticated USING (is_admin(auth.uid()) OR created_by = auth.uid());
|
||||
CREATE POLICY "gen_docs_insert_auth" ON public.generated_documents
|
||||
FOR INSERT TO authenticated WITH CHECK (auth.uid() IS NOT NULL);
|
||||
CREATE POLICY "gen_docs_update_owner" ON public.generated_documents
|
||||
FOR UPDATE TO authenticated USING (is_admin(auth.uid()) OR created_by = auth.uid());
|
||||
CREATE POLICY "gen_docs_delete_owner" ON public.generated_documents
|
||||
FOR DELETE TO authenticated USING (is_admin(auth.uid()) OR created_by = auth.uid());
|
||||
|
||||
CREATE TRIGGER trg_gen_docs_updated
|
||||
BEFORE UPDATE ON public.generated_documents
|
||||
FOR EACH ROW EXECUTE FUNCTION public.tg_set_updated_at();
|
||||
|
||||
-- Storage bucket for generated docs
|
||||
INSERT INTO storage.buckets (id, name, public) VALUES ('generated-documents', 'generated-documents', false)
|
||||
ON CONFLICT (id) DO NOTHING;
|
||||
|
||||
CREATE POLICY "gen_docs_storage_select" ON storage.objects
|
||||
FOR SELECT TO authenticated
|
||||
USING (bucket_id = 'generated-documents' AND auth.uid()::text = (storage.foldername(name))[1]);
|
||||
CREATE POLICY "gen_docs_storage_insert" ON storage.objects
|
||||
FOR INSERT TO authenticated
|
||||
WITH CHECK (bucket_id = 'generated-documents' AND auth.uid()::text = (storage.foldername(name))[1]);
|
||||
CREATE POLICY "gen_docs_storage_delete" ON storage.objects
|
||||
FOR DELETE TO authenticated
|
||||
USING (bucket_id = 'generated-documents' AND auth.uid()::text = (storage.foldername(name))[1]);
|
||||
|
||||
-- Seed default Pleading template
|
||||
INSERT INTO public.document_templates (name, kind, description, body, fields)
|
||||
VALUES (
|
||||
'Florida Pleading',
|
||||
'pleading',
|
||||
'Standard Florida court pleading with caption header.',
|
||||
'',
|
||||
'[]'::jsonb
|
||||
);
|
||||
Reference in New Issue
Block a user