From 0ffba85c79a7693d887e6fe0cd991e42faea8f36 Mon Sep 17 00:00:00 2001
From: dujinkim <dujin.kim@dtsolution.co.kr>
Date: Mon, 15 Sep 2025 10:15:25 +0000
Subject: (공통) 스키마 index.ts 및 마이그레이션 파일 커밋
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 db/migrations/0362_talented_molten_man.sql | 36 ++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
 create mode 100644 db/migrations/0362_talented_molten_man.sql

(limited to 'db/migrations/0362_talented_molten_man.sql')

diff --git a/db/migrations/0362_talented_molten_man.sql b/db/migrations/0362_talented_molten_man.sql
new file mode 100644
index 00000000..58bbde58
--- /dev/null
+++ b/db/migrations/0362_talented_molten_man.sql
@@ -0,0 +1,36 @@
+DROP VIEW "public"."tbe_last_view";--> statement-breakpoint
+CREATE VIEW "public"."tbe_last_view" AS (select "rfq_last_tbe_sessions"."id" as "tbe_session_id", "rfq_last_tbe_sessions"."session_code" as "session_code", "rfq_last_tbe_sessions"."session_title" as "session_title", "rfq_last_tbe_sessions"."session_type" as "session_type", "rfq_last_tbe_sessions"."status" as "session_status", "rfq_last_tbe_sessions"."evaluation_result" as "evaluation_result", "rfq_last_tbe_sessions"."conditional_requirements" as "conditional_requirements", "rfq_last_tbe_sessions"."conditions_fulfilled" as "conditions_fulfilled", "rfqs_last"."id" as "rfq_id", "rfqs_last"."rfq_code" as "rfq_code", "rfqs_last"."rfq_type" as "rfq_type", "rfqs_last"."rfq_title" as "rfq_title", "rfqs_last"."series" as "series", "rfqs_last"."status" as "rfq_status", "rfqs_last"."due_date" as "rfq_due_date", "rfqs_last"."pic_name" as "pic_name", "rfqs_last"."eng_pic_name" as "eng_pic_name", "rfqs_last"."package_no" as "package_no", "rfqs_last"."package_name" as "package_name", "rfqs_last"."pr_number" as "pr_number", "rfqs_last"."pr_issue_date" as "pr_issue_date", "rfqs_last"."project_id" as "project_id", "projects"."code" as "project_code", "projects"."name" as "project_name", "rfqs_last"."project_company" as "project_company", "rfqs_last"."project_flag" as "project_flag", "rfqs_last"."project_site" as "project_site", "rfqs_last"."item_code" as "item_code", "rfqs_last"."item_name" as "item_name", "vendors"."id" as "vendor_id", "vendors"."vendor_code" as "vendor_code", "vendors"."vendor_name" as "vendor_name", "vendors"."country" as "vendor_country", "vendors"."email" as "vendor_email", "vendors"."status" as "vendor_status", "rfq_last_details"."id" as "rfq_detail_id", "rfq_last_details"."short_list" as "short_list", "rfq_last_details"."return_yn" as "return_yn", "rfq_last_tbe_sessions"."planned_start_date" as "planned_start_date", "rfq_last_tbe_sessions"."actual_start_date" as "actual_start_date", "rfq_last_tbe_sessions"."planned_end_date" as "planned_end_date", "rfq_last_tbe_sessions"."actual_end_date" as "actual_end_date", "rfq_last_tbe_sessions"."lead_evaluator_id" as "lead_evaluator_id", lead_user.name as "lead_evaluator_name", (
+        SELECT COUNT(*) 
+        FROM rfq_pr_items 
+        WHERE rfqs_last_id = "rfqs_last"."id"
+      ) as "pr_items_count", (
+        SELECT COUNT(*) 
+        FROM rfq_pr_items 
+        WHERE rfqs_last_id = "rfqs_last"."id"
+        AND major_yn = true
+      ) as "major_items_count", (
+        SELECT COUNT(*)
+        FROM rfq_last_tbe_document_reviews
+        WHERE tbe_session_id = "rfq_last_tbe_sessions"."id"
+        AND document_source = 'buyer'
+      ) as "buyer_documents_count", (
+        SELECT COUNT(*)
+        FROM rfq_last_tbe_vendor_documents
+        WHERE tbe_session_id = "rfq_last_tbe_sessions"."id"
+      ) as "vendor_documents_count", (
+        SELECT COUNT(*)
+        FROM rfq_last_tbe_document_reviews
+        WHERE tbe_session_id = "rfq_last_tbe_sessions"."id"
+        AND review_status IN ('검토완료', '승인')
+      ) as "reviewed_documents_count", (
+        SELECT COUNT(*)
+        FROM rfq_last_tbe_pdftron_comments pc
+        JOIN rfq_last_tbe_document_reviews dr ON pc.document_review_id = dr.id
+        WHERE dr.tbe_session_id = "rfq_last_tbe_sessions"."id"
+      ) as "total_comments_count", (
+        SELECT COUNT(*)
+        FROM rfq_last_tbe_pdftron_comments pc
+        JOIN rfq_last_tbe_document_reviews dr ON pc.document_review_id = dr.id
+        WHERE dr.tbe_session_id = "rfq_last_tbe_sessions"."id"
+        AND pc.status = 'open'
+      ) as "unresolved_comments_count", "rfq_last_tbe_sessions"."created_at" as "created_at", "rfq_last_tbe_sessions"."updated_at" as "updated_at" from "rfq_last_tbe_sessions" left join "rfqs_last" on "rfq_last_tbe_sessions"."rfqs_last_id" = "rfqs_last"."id" left join "rfq_last_details" on "rfq_last_tbe_sessions"."rfq_last_details_id" = "rfq_last_details"."id" left join "vendors" on "rfq_last_tbe_sessions"."vendor_id" = "vendors"."id" left join "projects" on "rfqs_last"."project_id" = "projects"."id" left join "users" "lead_user" on "rfq_last_tbe_sessions"."lead_evaluator_id" = "lead_user"."id");
\ No newline at end of file
-- 
cgit v1.2.3

