From 90f79a7a691943a496f67f01c1e493256070e4de Mon Sep 17 00:00:00 2001 From: dujinkim Date: Mon, 7 Jul 2025 01:44:45 +0000 Subject: (대표님) 변경사항 20250707 10시 43분 - unstaged 변경사항 추가 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/migrations/0194_long_deadpool.sql | 58 ++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 db/migrations/0194_long_deadpool.sql (limited to 'db/migrations/0194_long_deadpool.sql') diff --git a/db/migrations/0194_long_deadpool.sql b/db/migrations/0194_long_deadpool.sql new file mode 100644 index 00000000..fe622ab9 --- /dev/null +++ b/db/migrations/0194_long_deadpool.sql @@ -0,0 +1,58 @@ +DROP VIEW "public"."tech_vendor_detail_view";--> statement-breakpoint +CREATE VIEW "public"."tech_vendor_detail_view" AS (select "id", "vendor_name", "vendor_code", "tax_id", "address", "country", "country_eng", "country_fab", "agent_name", "agent_phone", "agent_email", "phone", "email", "website", "status", "tech_vendor_type", "representative_name", "representative_email", "representative_phone", "representative_birth", "created_at", "updated_at", + (SELECT COALESCE( + json_agg( + json_build_object( + 'id', c.id, + 'contactName', c.contact_name, + 'contactPosition', c.contact_position, + 'contactEmail', c.contact_email, + 'contactPhone', c.contact_phone, + 'isPrimary', c.is_primary + ) + ), + '[]'::json + ) + FROM vendor_contacts c + WHERE c.vendor_id = tech_vendors.id) + as "contacts", + (SELECT COALESCE( + json_agg( + json_build_object( + 'id', a.id, + 'fileName', a.file_name, + 'filePath', a.file_path, + 'attachmentType', a.attachment_type, + 'createdAt', a.created_at + ) + ORDER BY a.attachment_type, a.created_at DESC + ), + '[]'::json + ) + FROM tech_vendor_attachments a + WHERE a.vendor_id = tech_vendors.id) + as "attachments", + (SELECT COUNT(*) + FROM tech_vendor_attachments a + WHERE a.vendor_id = tech_vendors.id) + as "attachment_count", + (SELECT COUNT(*) + FROM vendor_contacts c + WHERE c.vendor_id = tech_vendors.id) + as "contact_count", + (SELECT COALESCE( + json_agg( + json_build_object( + 'itemCode', i.item_code + ) + ), + '[]'::json + ) + FROM tech_vendor_possible_items i + LEFT JOIN items it ON i.item_code = it.item_code + WHERE i.vendor_id = tech_vendors.id) + as "possible_items", + (SELECT COUNT(*) + FROM tech_vendor_possible_items i + WHERE i.vendor_id = tech_vendors.id) + as "item_count" from "tech_vendors"); \ No newline at end of file -- cgit v1.2.3