summaryrefslogtreecommitdiff
path: root/db/migrations/0236_sparkling_switch.sql
diff options
context:
space:
mode:
authordujinkim <dujin.kim@dtsolution.co.kr>2025-07-25 07:51:15 +0000
committerdujinkim <dujin.kim@dtsolution.co.kr>2025-07-25 07:51:15 +0000
commit2650b7c0bb0ea12b68a58c0439f72d61df04b2f1 (patch)
tree17156183fd74b69d78178065388ac61a18ac07b4 /db/migrations/0236_sparkling_switch.sql
parentd32acea05915bd6c1ed4b95e56c41ef9204347bc (diff)
(대표님) 정기평가 대상, 미들웨어 수정, nextauth 토큰 처리 개선, GTC 등
(최겸) 기술영업
Diffstat (limited to 'db/migrations/0236_sparkling_switch.sql')
-rw-r--r--db/migrations/0236_sparkling_switch.sql65
1 files changed, 65 insertions, 0 deletions
diff --git a/db/migrations/0236_sparkling_switch.sql b/db/migrations/0236_sparkling_switch.sql
new file mode 100644
index 00000000..c011ba93
--- /dev/null
+++ b/db/migrations/0236_sparkling_switch.sql
@@ -0,0 +1,65 @@
+ALTER TABLE "tech_vendor_candidates" DISABLE ROW LEVEL SECURITY;--> statement-breakpoint
+DROP VIEW "public"."tech_vendor_candidates_with_vendor_info";--> statement-breakpoint
+DROP VIEW "public"."tech_vendor_items_view";--> statement-breakpoint
+DROP VIEW "public"."tech_vendor_detail_view";--> statement-breakpoint
+DROP TABLE "tech_vendor_candidates" CASCADE;--> statement-breakpoint
+ALTER TABLE "tech_vendor_contacts" ADD COLUMN "contact_title" varchar(100);--> statement-breakpoint
+ALTER TABLE "tech_vendor_possible_items" ADD COLUMN "shipbuilding_item_id" integer;--> statement-breakpoint
+ALTER TABLE "tech_vendor_possible_items" ADD COLUMN "offshore_top_item_id" integer;--> statement-breakpoint
+ALTER TABLE "tech_vendor_possible_items" ADD COLUMN "offshore_hull_item_id" integer;--> statement-breakpoint
+ALTER TABLE "tech_vendor_possible_items" ADD CONSTRAINT "tech_vendor_possible_items_shipbuilding_item_id_item_shipbuilding_id_fk" FOREIGN KEY ("shipbuilding_item_id") REFERENCES "public"."item_shipbuilding"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
+ALTER TABLE "tech_vendor_possible_items" ADD CONSTRAINT "tech_vendor_possible_items_offshore_top_item_id_item_offshore_top_id_fk" FOREIGN KEY ("offshore_top_item_id") REFERENCES "public"."item_offshore_top"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
+ALTER TABLE "tech_vendor_possible_items" ADD CONSTRAINT "tech_vendor_possible_items_offshore_hull_item_id_item_offshore_hull_id_fk" FOREIGN KEY ("offshore_hull_item_id") REFERENCES "public"."item_offshore_hull"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
+ALTER TABLE "tech_vendor_possible_items" DROP COLUMN "vendor_code";--> statement-breakpoint
+ALTER TABLE "tech_vendor_possible_items" DROP COLUMN "vendor_email";--> statement-breakpoint
+ALTER TABLE "tech_vendor_possible_items" DROP COLUMN "item_code";--> statement-breakpoint
+ALTER TABLE "tech_vendor_possible_items" DROP COLUMN "work_type";--> statement-breakpoint
+ALTER TABLE "tech_vendor_possible_items" DROP COLUMN "ship_types";--> statement-breakpoint
+ALTER TABLE "tech_vendor_possible_items" DROP COLUMN "item_list";--> statement-breakpoint
+ALTER TABLE "tech_vendor_possible_items" DROP COLUMN "sub_item_list";--> 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,
+ 'contactTitle', c.contact_title,
+ 'contactEmail', c.contact_email,
+ 'contactPhone', c.contact_phone,
+ 'isPrimary', c.is_primary
+ )
+ ),
+ '[]'::json
+ )
+ FROM tech_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 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