-- Quick migration to add quotation_id to invoices and verify quotations table exists
-- This is a simplified version that skips form definitions

-- Add quotation reference to invoices
ALTER TABLE invoices 
ADD COLUMN IF NOT EXISTS quotation_id uuid REFERENCES quotations(quotation_id);

CREATE INDEX IF NOT EXISTS idx_invoices_quotation_id ON invoices(quotation_id);

COMMENT ON COLUMN invoices.quotation_id IS 'If this invoice was created from a quotation, reference to the original quotation';

-- Verify quotations table
DO $$
BEGIN
    IF EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'quotations') THEN
        RAISE NOTICE '✅ Quotations table exists and is ready';
    ELSE
        RAISE EXCEPTION 'Quotations table does not exist!';
    END IF;
END $$;

RAISE NOTICE 'Migration complete - quotations/invoices relationship established';
RAISE NOTICE 'Forms will need to be created via the UI or a separate migration';
