diff options
| author | joonhoekim <26rote@gmail.com> | 2025-10-14 15:13:25 +0900 |
|---|---|---|
| committer | joonhoekim <26rote@gmail.com> | 2025-10-14 15:13:25 +0900 |
| commit | 598a40808b45413b373334092c3b60cab97d09b6 (patch) | |
| tree | bb0ad859c243d6de834839fb91f26e58dc993eb5 /db/schema/avl/vendor-pool.ts | |
| parent | 2665c5916e75a0d6f16098a09ab3c187266dd936 (diff) | |
(김준회) 벤더풀 유니크 처리 및 import 개선
Diffstat (limited to 'db/schema/avl/vendor-pool.ts')
| -rw-r--r-- | db/schema/avl/vendor-pool.ts | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/db/schema/avl/vendor-pool.ts b/db/schema/avl/vendor-pool.ts index 62f9dace..a1b7fa3a 100644 --- a/db/schema/avl/vendor-pool.ts +++ b/db/schema/avl/vendor-pool.ts @@ -1,4 +1,5 @@ -import { pgTable, text, boolean, integer, timestamp, varchar } from "drizzle-orm/pg-core"; +import { pgTable, text, boolean, integer, timestamp, varchar, uniqueIndex } from "drizzle-orm/pg-core"; +import { sql } from 'drizzle-orm'; import { createInsertSchema, createSelectSchema } from "drizzle-zod"; // Vendor Pool 테이블 @@ -95,7 +96,13 @@ export const vendorPool = pgTable("vendor_pool", { registrant: varchar("registrant", { length: 50 }), // 등재자 lastModifiedDate: timestamp("last_modified_date").defaultNow(), // 최종변경일 lastModifier: varchar("last_modifier", { length: 50 }), // 최종변경자 -}); +}, (table) => ({ + + // 새로운 unique 제약조건: 공사부문 + H/T + 자재그룹코드 + 협력업체명 + uniqueVendorPoolCombination: uniqueIndex("unique_vendor_pool_combination") + .on(table.constructionSector, table.htDivision, table.materialGroupCode, table.vendorName) + .where(sql`${table.materialGroupCode} IS NOT NULL AND ${table.vendorName} IS NOT NULL`) +})); // 복합키 인덱스 (자재그룹코드 + 벤더코드) // 구매 의도상은 복합키가 맞는 것 같은데, 요구사항 불명확하므로 별도 제약조건 없이 개발 후 요구 나오면 수정 |
