From b7f5af1f4b6691052bb3e77968a478ff27696095 Mon Sep 17 00:00:00 2001
From: dujinkim <dujin.kim@dtsolution.co.kr>
Date: Wed, 28 May 2025 00:33:50 +0000
Subject: (대표님 / 최겸) 스키마 변경사항 및 마이그레이션 커밋
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 db/migrations/0080_amusing_toad.sql | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)
 create mode 100644 db/migrations/0080_amusing_toad.sql

(limited to 'db/migrations/0080_amusing_toad.sql')

diff --git a/db/migrations/0080_amusing_toad.sql b/db/migrations/0080_amusing_toad.sql
new file mode 100644
index 00000000..80ba805a
--- /dev/null
+++ b/db/migrations/0080_amusing_toad.sql
@@ -0,0 +1,33 @@
+DROP VIEW "public"."vendor_investigations_view";--> statement-breakpoint
+CREATE VIEW "public"."vendor_investigations_view" AS (select "vendor_investigations"."id", "vendor_investigations"."vendor_id", "vendor_investigations"."pq_submission_id", "vendor_investigations"."requester_id", "vendor_investigations"."qm_manager_id", "vendor_investigations"."investigation_status", "vendor_investigations"."evaluation_type", "vendor_investigations"."investigation_address", "vendor_investigations"."investigation_method", "vendor_investigations"."scheduled_start_at", "vendor_investigations"."scheduled_end_at", "vendor_investigations"."forecasted_at", "vendor_investigations"."requested_at", "vendor_investigations"."confirmed_at", "vendor_investigations"."completed_at", "vendor_investigations"."evaluation_score", "vendor_investigations"."evaluation_result", "vendor_investigations"."investigation_notes", "vendor_investigations"."created_at", "vendor_investigations"."updated_at", "vendor_investigations"."created_at", "vendor_investigations"."updated_at", "vendors"."vendor_name", "vendors"."vendor_code", "vendors"."tax_id", "vendors"."status", "vendors"."country", "vendors"."email", "vendors"."phone", "vendors"."website", (
+        SELECT COALESCE(
+          json_agg(json_build_object(
+            'id', c.id,
+            'contactName', c.contact_name,
+            'contactEmail', c.contact_email,
+            'contactPhone', c.contact_phone,
+            'contactPosition', c.contact_position,
+            'isPrimary', c.is_primary,
+            'createdAt', c.created_at,
+            'updatedAt', c.updated_at
+          )),
+          '[]'::json
+        )
+        FROM vendor_contacts c
+        WHERE c.vendor_id = "vendors"."id"
+      ) as "contacts", (
+        SELECT COALESCE(
+          json_agg(json_build_object(
+            'id', pi.id,
+            'vendorId', pi.vendor_id,
+            'itemCode', pi.item_code,
+            'itemName', i.item_name,
+            'createdAt', pi.created_at,
+            'updatedAt', pi.updated_at
+          )),
+          '[]'::json
+        )
+        FROM vendor_possible_items pi
+        LEFT JOIN items i ON pi.item_code = i.item_code
+        WHERE pi.vendor_id = "vendors"."id"
+      ) as "possibleItems" from "vendor_investigations" left join "vendors" on "vendor_investigations"."vendor_id" = "vendors"."id");
\ No newline at end of file
-- 
cgit v1.2.3

