ALTER TABLE "crm_enquiries"
  ADD COLUMN IF NOT EXISTS "closed_won_at" timestamp with time zone,
  ADD COLUMN IF NOT EXISTS "closed_lost_at" timestamp with time zone,
  ADD COLUMN IF NOT EXISTS "closed_by_user_id" text,
  ADD COLUMN IF NOT EXISTS "po_number" text,
  ADD COLUMN IF NOT EXISTS "po_date" timestamp with time zone,
  ADD COLUMN IF NOT EXISTS "po_amount" double precision,
  ADD COLUMN IF NOT EXISTS "po_currency" text,
  ADD COLUMN IF NOT EXISTS "lost_reason" text,
  ADD COLUMN IF NOT EXISTS "lost_competitor" text,
  ADD COLUMN IF NOT EXISTS "lost_remark" text;

CREATE TABLE IF NOT EXISTS "crm_enquiry_attachments" (
  "id" text PRIMARY KEY NOT NULL,
  "organization_id" text NOT NULL,
  "enquiry_id" text NOT NULL,
  "category" text NOT NULL,
  "file_name" text NOT NULL,
  "original_file_name" text NOT NULL,
  "storage_provider" text NOT NULL,
  "storage_key" text NOT NULL,
  "file_size" integer,
  "file_type" text,
  "description" text,
  "uploaded_at" timestamp with time zone DEFAULT now() NOT NULL,
  "uploaded_by" text NOT NULL,
  "created_at" timestamp with time zone DEFAULT now() NOT NULL,
  "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
  "deleted_at" timestamp with time zone
);
