From e46b7ccad4db812dfc8455b20425469afad61788 Mon Sep 17 00:00:00 2001
From: dujinkim <dujin.kim@dtsolution.co.kr>
Date: Tue, 13 May 2025 03:07:39 +0000
Subject: (대표님) drizzle-kit migrations and snapshots
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 db/migrations/0044_solid_dreaming_celestial.sql | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
 create mode 100644 db/migrations/0044_solid_dreaming_celestial.sql

(limited to 'db/migrations/0044_solid_dreaming_celestial.sql')

diff --git a/db/migrations/0044_solid_dreaming_celestial.sql b/db/migrations/0044_solid_dreaming_celestial.sql
new file mode 100644
index 00000000..cd218013
--- /dev/null
+++ b/db/migrations/0044_solid_dreaming_celestial.sql
@@ -0,0 +1,18 @@
+DROP VIEW "public"."normalized_rfq_details_view";--> statement-breakpoint
+DROP VIEW "public"."procurement_rfqs_view";--> statement-breakpoint
+ALTER TABLE "procurement_rfqs" RENAME COLUMN "item_code" TO "item_id";--> statement-breakpoint
+ALTER TABLE "procurement_rfqs" DROP CONSTRAINT "procurement_rfqs_item_code_items_id_fk";
+--> statement-breakpoint
+ALTER TABLE "procurement_rfqs" ADD CONSTRAINT "procurement_rfqs_item_id_items_id_fk" FOREIGN KEY ("item_id") REFERENCES "public"."items"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
+CREATE VIEW "public"."normalized_rfq_details_view" AS (select "procurement_rfq_details"."id", "procurement_rfqs"."id", "procurement_rfqs"."rfq_code", "projects"."code", "projects"."name", "items"."item_code", "items"."item_name", "vendors"."vendor_name", "vendors"."vendor_code", "procurement_rfq_details"."currency", "payment_terms"."code", "payment_terms"."description", "incoterms"."code", "incoterms"."description", "procurement_rfq_details"."incoterms_detail", "procurement_rfq_details"."delivery_date", "procurement_rfq_details"."tax_code", "procurement_rfq_details"."place_of_shipping", "procurement_rfq_details"."place_of_destination", "procurement_rfq_details"."material_price_related_yn", "updated_by_user"."name", "procurement_rfq_details"."updated_at" from "procurement_rfq_details" left join "procurement_rfqs" on "procurement_rfq_details"."procurement_rfqs_id" = "procurement_rfqs"."id" left join "projects" on "procurement_rfqs"."project_id" = "projects"."id" left join "items" on "procurement_rfqs"."item_id" = "items"."id" left join "vendors" on "procurement_rfq_details"."vendors_id" = "vendors"."id" left join "payment_terms" on "procurement_rfq_details"."payment_terms_code" = "payment_terms"."code" left join "incoterms" on "procurement_rfq_details"."incoterms_code" = "incoterms"."code" left join "users" "updated_by_user" on "procurement_rfq_details"."updated_by" = "updated_by_user"."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"."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");
\ No newline at end of file
-- 
cgit v1.2.3

