From b456315b0f6db69b194c202e82423cf6d6dad8c8 Mon Sep 17 00:00:00 2001
From: "gpt-engineer-app[bot]"
<159125892+gpt-engineer-app[bot]@users.noreply.github.com>
Date: Mon, 20 Apr 2026 00:27:43 +0000
Subject: [PATCH 1/2] Changes
Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com>
---
...0_d9250127-482e-4590-956b-cff8fdbaaba6.sql | 30 +++++++++++++++++++
1 file changed, 30 insertions(+)
create mode 100644 supabase/migrations/20260420002740_d9250127-482e-4590-956b-cff8fdbaaba6.sql
diff --git a/supabase/migrations/20260420002740_d9250127-482e-4590-956b-cff8fdbaaba6.sql b/supabase/migrations/20260420002740_d9250127-482e-4590-956b-cff8fdbaaba6.sql
new file mode 100644
index 0000000..16ebaaa
--- /dev/null
+++ b/supabase/migrations/20260420002740_d9250127-482e-4590-956b-cff8fdbaaba6.sql
@@ -0,0 +1,30 @@
+-- Function: ensure a case with the Collections practice area has at least one collection row.
+CREATE OR REPLACE FUNCTION public.tg_ensure_collection_for_collections_case()
+RETURNS trigger
+LANGUAGE plpgsql
+SECURITY DEFINER
+SET search_path = public
+AS $$
+BEGIN
+ IF NEW.practice_area = 'Community Ass''n Law - Collections' THEN
+ IF NOT EXISTS (SELECT 1 FROM public.collections WHERE case_id = NEW.id) THEN
+ INSERT INTO public.collections (case_id, status, opened_at, created_by)
+ VALUES (NEW.id, 'late_notice', COALESCE(NEW.opened_at, CURRENT_DATE), NEW.created_by);
+ END IF;
+ END IF;
+ RETURN NEW;
+END;
+$$;
+
+DROP TRIGGER IF EXISTS trg_ensure_collection_for_collections_case ON public.cases;
+CREATE TRIGGER trg_ensure_collection_for_collections_case
+AFTER INSERT OR UPDATE OF practice_area ON public.cases
+FOR EACH ROW
+EXECUTE FUNCTION public.tg_ensure_collection_for_collections_case();
+
+-- One-time backfill for existing cases.
+INSERT INTO public.collections (case_id, status, opened_at, created_by)
+SELECT c.id, 'late_notice', COALESCE(c.opened_at, CURRENT_DATE), c.created_by
+FROM public.cases c
+WHERE c.practice_area = 'Community Ass''n Law - Collections'
+ AND NOT EXISTS (SELECT 1 FROM public.collections col WHERE col.case_id = c.id);
\ No newline at end of file
From 420ddabc1e02d86e5c2e9879f527353b9d16206f Mon Sep 17 00:00:00 2001
From: "gpt-engineer-app[bot]"
<159125892+gpt-engineer-app[bot]@users.noreply.github.com>
Date: Mon, 20 Apr 2026 00:27:53 +0000
Subject: [PATCH 2/2] Changes
Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com>
---
src/routes/cases.index.tsx | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/src/routes/cases.index.tsx b/src/routes/cases.index.tsx
index 31740a6..b3b194f 100644
--- a/src/routes/cases.index.tsx
+++ b/src/routes/cases.index.tsx
@@ -482,7 +482,14 @@ function CasesList() {