ALTER TABLE public.client_invoices
ADD COLUMN IF NOT EXISTS qbo_invoice_id TEXT,
ADD COLUMN IF NOT EXISTS qbo_sync_status TEXT NOT NULL DEFAULT 'pending',
ADD COLUMN IF NOT EXISTS qbo_synced_at TIMESTAMPTZ,
ADD COLUMN IF NOT EXISTS qbo_sync_error TEXT;

CREATE UNIQUE INDEX IF NOT EXISTS idx_client_invoices_qbo_invoice_id
ON public.client_invoices (qbo_invoice_id)
WHERE qbo_invoice_id IS NOT NULL;

CREATE INDEX IF NOT EXISTS idx_client_invoices_qbo_sync_status
ON public.client_invoices (qbo_sync_status);