DROP VIEW "public"."initial_rfq_detail";--> statement-breakpoint
ALTER TABLE "initial_rfq" ADD COLUMN "rfq_revision" integer DEFAULT 0 NOT NULL;--> statement-breakpoint
CREATE VIEW "public"."initial_rfq_detail" AS (
    SELECT 
        br.id as rfq_id,
        br.rfq_code,
        br.status as rfq_status,
        ir.id as initial_rfq_id,
        ir.initial_rfq_status,
        ir.vendor_id,
        v.vendor_code,
        v.vendor_name,
        v.country as vendor_country,
        v.business_size as vendor_business_size,
        ir.due_date,
        ir.valid_date,
        ir.incoterms_code,
        inc.description as incoterms_description,
        ir.short_list,
        ir.return_yn,
        ir.cp_request_yn,
        ir.prject_gtc_yn,
        ir.return_revision,
        ir.rfq_revision,
        ir.gtc,
        ir.gtc_valid_date,
        ir.classification,
        ir.sparepart,
        ir.created_at,
        ir.updated_at
    FROM b_rfqs br
    JOIN initial_rfq ir ON br.id = ir.rfq_id
    LEFT JOIN vendors v ON ir.vendor_id = v.id
    LEFT JOIN incoterms inc ON ir.incoterms_code = inc.code
);