diff --git a/src/integrations/supabase/types.ts b/src/integrations/supabase/types.ts index c8784fe..c52fcac 100644 --- a/src/integrations/supabase/types.ts +++ b/src/integrations/supabase/types.ts @@ -1652,7 +1652,9 @@ export type Database = { external_id: string | null id: string invoice_id: string | null + quantity: number receipt_storage_path: string | null + unit_price: number updated_at: string user_id: string } @@ -1667,7 +1669,9 @@ export type Database = { external_id?: string | null id?: string invoice_id?: string | null + quantity?: number receipt_storage_path?: string | null + unit_price?: number updated_at?: string user_id: string } @@ -1682,7 +1686,9 @@ export type Database = { external_id?: string | null id?: string invoice_id?: string | null + quantity?: number receipt_storage_path?: string | null + unit_price?: number updated_at?: string user_id?: string } diff --git a/supabase/migrations/20260425185053_96ee636e-66fc-4cd1-98ec-a96801a73c96.sql b/supabase/migrations/20260425185053_96ee636e-66fc-4cd1-98ec-a96801a73c96.sql new file mode 100644 index 0000000..7e3097d --- /dev/null +++ b/supabase/migrations/20260425185053_96ee636e-66fc-4cd1-98ec-a96801a73c96.sql @@ -0,0 +1,11 @@ +-- Add quantity and unit_price columns to expenses for itemized billing. +-- amount remains the stored total = quantity * unit_price for backwards +-- compatibility with reports, invoices, and trust accounting. +ALTER TABLE public.expenses + ADD COLUMN IF NOT EXISTS quantity numeric NOT NULL DEFAULT 1, + ADD COLUMN IF NOT EXISTS unit_price numeric NOT NULL DEFAULT 0; + +-- Backfill: for existing rows, set unit_price = amount and quantity = 1. +UPDATE public.expenses + SET unit_price = amount, quantity = 1 + WHERE unit_price = 0 AND amount IS NOT NULL; \ No newline at end of file