case_phase_deliverables is referenced but never created
case_phase_deliverables is one of the most-used tables in the app — it holds the formal
phase documents (Nota de Culpa, Relatório de Inquérito, Relatório Final, …), is read by
generate-dossier (only status IN ('validated','closed') go into the dossier), written
by InquiryReportDrawer, and exposed through the portal (portal_items.item_type = 'DELIVERABLE').
Yet no migration in the set ever CREATEs it. The only migration that touches it is:
20260307224828 — ALTER TABLE public.case_phase_deliverables ADD COLUMN metadata ...
which alters a table that was never created in version control. It was created out-of-band in the Lovable/Supabase console.
What breaks: the migration history is not a complete, replayable schema. A rebuild
that provisions the database from these migrations will fail (the ALTER errors, and the
app crashes on every deliverable query). The true schema of this central table — its
columns, constraints, status enum, and the metadata shape — is unknown from the
repo and must be reconstructed from the code that reads/writes it:
- columns seen in code:
id, case_id, phase, title, description, file_path, file_name, file_size, mime_type, status, created_by, validated_by, validated_at, metadata statusvalues seen:draft,validated,closed(andreadyin some maps)metadata.kindseen:bodies_opinion_request,bodies_opinion_response,instructor_proposal,inquiry_report…
Rebuild implication
Treat the migration folder as incomplete. Reconstruct case_phase_deliverables (and
audit whether other tables are similarly console-created) before trusting any
"replay the migrations" plan. Capture its real schema from the live Supabase project.