From bba10d31ac49e37c8916e7d7fbebe0b52f4ba651 Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Sat, 18 Apr 2026 01:16:25 +0000 Subject: [PATCH] Changes Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com> --- src/integrations/supabase/types.ts | 99 +++++++++++++++++++ ...2_8f2085e8-1834-4de6-bab8-e87c8d7a0a41.sql | 60 +++++++++++ 2 files changed, 159 insertions(+) create mode 100644 supabase/migrations/20260418011622_8f2085e8-1834-4de6-bab8-e87c8d7a0a41.sql diff --git a/src/integrations/supabase/types.ts b/src/integrations/supabase/types.ts index c990442..100e462 100644 --- a/src/integrations/supabase/types.ts +++ b/src/integrations/supabase/types.ts @@ -26,6 +26,7 @@ export type Database = { created_by: string | null direction: string duration_minutes: number | null + external_id: string | null follow_up_date: string | null follow_up_required: boolean homeowner_id: string | null @@ -45,6 +46,7 @@ export type Database = { created_by?: string | null direction?: string duration_minutes?: number | null + external_id?: string | null follow_up_date?: string | null follow_up_required?: boolean homeowner_id?: string | null @@ -64,6 +66,7 @@ export type Database = { created_by?: string | null direction?: string duration_minutes?: number | null + external_id?: string | null follow_up_date?: string | null follow_up_required?: boolean homeowner_id?: string | null @@ -153,6 +156,7 @@ export type Database = { created_by: string | null default_hourly_rate: number | null description: string | null + external_id: string | null filing_date: string | null id: string judge: string | null @@ -188,6 +192,7 @@ export type Database = { created_by?: string | null default_hourly_rate?: number | null description?: string | null + external_id?: string | null filing_date?: string | null id?: string judge?: string | null @@ -223,6 +228,7 @@ export type Database = { created_by?: string | null default_hourly_rate?: number | null description?: string | null + external_id?: string | null filing_date?: string | null id?: string judge?: string | null @@ -313,6 +319,7 @@ export type Database = { client_type: Database["public"]["Enums"]["client_type"] created_at: string created_by: string | null + external_id: string | null id: string management_company: string | null name: string @@ -334,6 +341,7 @@ export type Database = { client_type?: Database["public"]["Enums"]["client_type"] created_at?: string created_by?: string | null + external_id?: string | null id?: string management_company?: string | null name: string @@ -355,6 +363,7 @@ export type Database = { client_type?: Database["public"]["Enums"]["client_type"] created_at?: string created_by?: string | null + external_id?: string | null id?: string management_company?: string | null name?: string @@ -741,6 +750,7 @@ export type Database = { created_at: string created_by: string | null email: string | null + external_id: string | null id: string name: string notes: string | null @@ -759,6 +769,7 @@ export type Database = { created_at?: string created_by?: string | null email?: string | null + external_id?: string | null id?: string name: string notes?: string | null @@ -777,6 +788,7 @@ export type Database = { created_at?: string created_by?: string | null email?: string | null + external_id?: string | null id?: string name?: string notes?: string | null @@ -926,6 +938,7 @@ export type Database = { case_id: string created_at: string description: string | null + external_id: string | null folder: string id: string mime_type: string | null @@ -938,6 +951,7 @@ export type Database = { case_id: string created_at?: string description?: string | null + external_id?: string | null folder?: string id?: string mime_type?: string | null @@ -950,6 +964,7 @@ export type Database = { case_id?: string created_at?: string description?: string | null + external_id?: string | null folder?: string id?: string mime_type?: string | null @@ -1025,6 +1040,72 @@ export type Database = { } Relationships: [] } + events: { + Row: { + all_day: boolean + case_id: string | null + client_id: string | null + created_at: string + created_by: string | null + description: string | null + end_at: string | null + event_type: string + external_id: string | null + id: string + location: string | null + start_at: string + title: string + updated_at: string + } + Insert: { + all_day?: boolean + case_id?: string | null + client_id?: string | null + created_at?: string + created_by?: string | null + description?: string | null + end_at?: string | null + event_type?: string + external_id?: string | null + id?: string + location?: string | null + start_at: string + title: string + updated_at?: string + } + Update: { + all_day?: boolean + case_id?: string | null + client_id?: string | null + created_at?: string + created_by?: string | null + description?: string | null + end_at?: string | null + event_type?: string + external_id?: string | null + id?: string + location?: string | null + start_at?: string + title?: string + updated_at?: string + } + Relationships: [ + { + foreignKeyName: "events_case_id_fkey" + columns: ["case_id"] + isOneToOne: false + referencedRelation: "cases" + referencedColumns: ["id"] + }, + { + foreignKeyName: "events_client_id_fkey" + columns: ["client_id"] + isOneToOne: false + referencedRelation: "clients" + referencedColumns: ["id"] + }, + ] + } expenses: { Row: { amount: number @@ -1033,6 +1114,7 @@ export type Database = { created_at: string description: string expense_date: string + external_id: string | null id: string invoice_id: string | null receipt_storage_path: string | null @@ -1046,6 +1128,7 @@ export type Database = { created_at?: string description: string expense_date?: string + external_id?: string | null id?: string invoice_id?: string | null receipt_storage_path?: string | null @@ -1059,6 +1142,7 @@ export type Database = { created_at?: string description?: string expense_date?: string + external_id?: string | null id?: string invoice_id?: string | null receipt_storage_path?: string | null @@ -1241,6 +1325,7 @@ export type Database = { created_at: string created_by: string | null email: string | null + external_id: string | null first_name: string id: string last_name: string @@ -1256,6 +1341,7 @@ export type Database = { created_at?: string created_by?: string | null email?: string | null + external_id?: string | null first_name: string id?: string last_name: string @@ -1271,6 +1357,7 @@ export type Database = { created_at?: string created_by?: string | null email?: string | null + external_id?: string | null first_name?: string id?: string last_name?: string @@ -1559,6 +1646,7 @@ export type Database = { created_at: string created_by: string | null due_date: string | null + external_id: string | null id: string invoice_number: string is_retainer: boolean @@ -1578,6 +1666,7 @@ export type Database = { created_at?: string created_by?: string | null due_date?: string | null + external_id?: string | null id?: string invoice_number: string is_retainer?: boolean @@ -1597,6 +1686,7 @@ export type Database = { created_at?: string created_by?: string | null due_date?: string | null + external_id?: string | null id?: string invoice_number?: string is_retainer?: boolean @@ -2023,6 +2113,7 @@ export type Database = { case_id: string created_at: string created_by: string | null + external_id: string | null id: string report_storage_path: string | null title: string @@ -2032,6 +2123,7 @@ export type Database = { case_id: string created_at?: string created_by?: string | null + external_id?: string | null id?: string report_storage_path?: string | null title: string @@ -2041,6 +2133,7 @@ export type Database = { case_id?: string created_at?: string created_by?: string | null + external_id?: string | null id?: string report_storage_path?: string | null title?: string @@ -2166,6 +2259,7 @@ export type Database = { created_by: string | null description: string | null due_date: string | null + external_id: string | null id: string parent_task_id: string | null priority: Database["public"]["Enums"]["task_priority"] @@ -2183,6 +2277,7 @@ export type Database = { created_by?: string | null description?: string | null due_date?: string | null + external_id?: string | null id?: string parent_task_id?: string | null priority?: Database["public"]["Enums"]["task_priority"] @@ -2200,6 +2295,7 @@ export type Database = { created_by?: string | null description?: string | null due_date?: string | null + external_id?: string | null id?: string parent_task_id?: string | null priority?: Database["public"]["Enums"]["task_priority"] @@ -2239,6 +2335,7 @@ export type Database = { case_id: string created_at: string description: string + external_id: string | null hourly_rate: number hours: number id: string @@ -2252,6 +2349,7 @@ export type Database = { case_id: string created_at?: string description: string + external_id?: string | null hourly_rate?: number hours: number id?: string @@ -2265,6 +2363,7 @@ export type Database = { case_id?: string created_at?: string description?: string + external_id?: string | null hourly_rate?: number hours?: number id?: string diff --git a/supabase/migrations/20260418011622_8f2085e8-1834-4de6-bab8-e87c8d7a0a41.sql b/supabase/migrations/20260418011622_8f2085e8-1834-4de6-bab8-e87c8d7a0a41.sql new file mode 100644 index 0000000..e576c8a --- /dev/null +++ b/supabase/migrations/20260418011622_8f2085e8-1834-4de6-bab8-e87c8d7a0a41.sql @@ -0,0 +1,60 @@ +-- Calendar events table +CREATE TABLE IF NOT EXISTS public.events ( + id uuid PRIMARY KEY DEFAULT gen_random_uuid(), + case_id uuid REFERENCES public.cases(id) ON DELETE CASCADE, + client_id uuid REFERENCES public.clients(id) ON DELETE SET NULL, + title text NOT NULL, + description text, + location text, + start_at timestamptz NOT NULL, + end_at timestamptz, + all_day boolean NOT NULL DEFAULT false, + event_type text NOT NULL DEFAULT 'general', + external_id text, + created_by uuid, + created_at timestamptz NOT NULL DEFAULT now(), + updated_at timestamptz NOT NULL DEFAULT now() +); + +CREATE UNIQUE INDEX IF NOT EXISTS events_external_id_uidx ON public.events(external_id) WHERE external_id IS NOT NULL; +CREATE INDEX IF NOT EXISTS events_case_id_idx ON public.events(case_id); +CREATE INDEX IF NOT EXISTS events_start_at_idx ON public.events(start_at); + +ALTER TABLE public.events ENABLE ROW LEVEL SECURITY; + +CREATE POLICY "events_select" ON public.events FOR SELECT TO authenticated + USING (case_id IS NULL OR public.can_access_case(case_id, auth.uid()) OR public.is_admin(auth.uid())); +CREATE POLICY "events_insert" ON public.events FOR INSERT TO authenticated + WITH CHECK (auth.uid() IS NOT NULL); +CREATE POLICY "events_update" ON public.events FOR UPDATE TO authenticated + USING (public.is_admin(auth.uid()) OR created_by = auth.uid() OR (case_id IS NOT NULL AND public.can_access_case(case_id, auth.uid()))); +CREATE POLICY "events_delete" ON public.events FOR DELETE TO authenticated + USING (public.is_admin(auth.uid()) OR created_by = auth.uid()); + +CREATE TRIGGER events_set_updated_at BEFORE UPDATE ON public.events + FOR EACH ROW EXECUTE FUNCTION public.tg_set_updated_at(); + +-- Add external_id to common imported tables for idempotent re-imports +ALTER TABLE public.cases ADD COLUMN IF NOT EXISTS external_id text; +ALTER TABLE public.clients ADD COLUMN IF NOT EXISTS external_id text; +ALTER TABLE public.contacts ADD COLUMN IF NOT EXISTS external_id text; +ALTER TABLE public.homeowners ADD COLUMN IF NOT EXISTS external_id text; +ALTER TABLE public.tasks ADD COLUMN IF NOT EXISTS external_id text; +ALTER TABLE public.invoices ADD COLUMN IF NOT EXISTS external_id text; +ALTER TABLE public.expenses ADD COLUMN IF NOT EXISTS external_id text; +ALTER TABLE public.time_entries ADD COLUMN IF NOT EXISTS external_id text; +ALTER TABLE public.call_logs ADD COLUMN IF NOT EXISTS external_id text; +ALTER TABLE public.documents ADD COLUMN IF NOT EXISTS external_id text; +ALTER TABLE public.status_updates ADD COLUMN IF NOT EXISTS external_id text; + +CREATE UNIQUE INDEX IF NOT EXISTS cases_external_id_uidx ON public.cases(external_id) WHERE external_id IS NOT NULL; +CREATE UNIQUE INDEX IF NOT EXISTS clients_external_id_uidx ON public.clients(external_id) WHERE external_id IS NOT NULL; +CREATE UNIQUE INDEX IF NOT EXISTS contacts_external_id_uidx ON public.contacts(external_id) WHERE external_id IS NOT NULL; +CREATE UNIQUE INDEX IF NOT EXISTS homeowners_external_id_uidx ON public.homeowners(external_id) WHERE external_id IS NOT NULL; +CREATE UNIQUE INDEX IF NOT EXISTS tasks_external_id_uidx ON public.tasks(external_id) WHERE external_id IS NOT NULL; +CREATE UNIQUE INDEX IF NOT EXISTS invoices_external_id_uidx ON public.invoices(external_id) WHERE external_id IS NOT NULL; +CREATE UNIQUE INDEX IF NOT EXISTS expenses_external_id_uidx ON public.expenses(external_id) WHERE external_id IS NOT NULL; +CREATE UNIQUE INDEX IF NOT EXISTS time_entries_external_id_uidx ON public.time_entries(external_id) WHERE external_id IS NOT NULL; +CREATE UNIQUE INDEX IF NOT EXISTS call_logs_external_id_uidx ON public.call_logs(external_id) WHERE external_id IS NOT NULL; +CREATE UNIQUE INDEX IF NOT EXISTS documents_external_id_uidx ON public.documents(external_id) WHERE external_id IS NOT NULL; +CREATE UNIQUE INDEX IF NOT EXISTS status_updates_external_id_uidx ON public.status_updates(external_id) WHERE external_id IS NOT NULL; \ No newline at end of file