DROP VIEW "public"."procurement_rfqs_view";--> statement-breakpoint
ALTER TABLE "tag_subfield_options" DROP CONSTRAINT "tag_subfield_options_attributes_id_project_id_tag_subfields_attributes_id_project_id_fk";
--> statement-breakpoint
ALTER TABLE "tasks" ALTER COLUMN "code" DROP DEFAULT;--> statement-breakpoint
ALTER TABLE "tag_subfields" ADD CONSTRAINT "uniq_attribute_id_project" UNIQUE("attributes_id","project_id");--> statement-breakpoint
CREATE VIEW "public"."procurement_rfqs_view" AS (select "procurement_rfqs"."id", "procurement_rfqs"."rfq_code", "projects"."code", "projects"."name", "procurement_rfqs"."series", "procurement_rfqs"."rfq_sealed_yn", "items"."item_code", "items"."item_name", "procurement_rfqs"."status", "procurement_rfqs"."rfq_send_date", "procurement_rfqs"."due_date", "created_by_user"."name", "procurement_rfqs"."updated_at", "updated_by_user"."name", "procurement_rfqs"."remark", (
                SELECT material_code 
                FROM pr_items 
                WHERE procurement_rfqs_id = "procurement_rfqs"."id" 
                AND major_yn = true 
                LIMIT 1
            ) as "major_item_material_code", (
                SELECT COUNT(*) 
                FROM pr_items 
                WHERE procurement_rfqs_id = "procurement_rfqs"."id"
            ) as "pr_items_count" from "procurement_rfqs" left join "projects" on "procurement_rfqs"."project_id" = "projects"."id" left join "items" on "procurement_rfqs"."item_id" = "items"."id" left join "users" "created_by_user" on "procurement_rfqs"."created_by" = "created_by_user"."id" left join "users" "updated_by_user" on "procurement_rfqs"."updated_by" = "updated_by_user"."id");