diff options
Diffstat (limited to 'db/schema/MDG/modelMaster.ts')
| -rw-r--r-- | db/schema/MDG/modelMaster.ts | 178 |
1 files changed, 178 insertions, 0 deletions
diff --git a/db/schema/MDG/modelMaster.ts b/db/schema/MDG/modelMaster.ts new file mode 100644 index 00000000..360989f9 --- /dev/null +++ b/db/schema/MDG/modelMaster.ts @@ -0,0 +1,178 @@ +import { pgTable, serial, varchar, timestamp } from "drizzle-orm/pg-core"; +import { relations } from "drizzle-orm"; + +/** + * 접근법 1: WSDL과 동일하게 DB 테이블/컬럼명 및 변수 이름 만들기 + * - 모든 테이블/컬럼명이 SAP 시스템의 네이밍을 그대로 유지 + * - 개발자가 SAP 시스템에 익숙하다면 이해하기 쉬움 + * - SAP 문서와 비교하기 쉬움 + */ + +// 자재 마스터 테이블 (MATL) +export const MATL = pgTable("MATL", { + id: serial("id").primaryKey(), + MATNR: varchar("MATNR", { length: 18 }).notNull().unique(), // Material Number (자재 번호) (PK) + MBRSH: varchar("MBRSH", { length: 1 }), // Industry Sector (산업 부문) + MTART: varchar("MTART", { length: 4 }), // Material Type (자재 유형) + LVORM: varchar("LVORM", { length: 1 }), // Deletion flag (삭제 플래그) + MEINS: varchar("MEINS", { length: 3 }), // Base Unit of Measure (기본 단위) + MATKL: varchar("MATKL", { length: 9 }), // Material Group (자재 그룹) + BISMT: varchar("BISMT", { length: 18 }), // Old material number (기존 자재 번호) + SPART: varchar("SPART", { length: 2 }), // Division (부문) + PRDHA: varchar("PRDHA", { length: 18 }), // Product hierachy (제품 계층) + MSTAE: varchar("MSTAE", { length: 2 }), // Material Status (자재 상태) + MSTDE: varchar("MSTDE", { length: 8 }), // Date from which the cross-plant material status is (자재 상태 유효 날짜) + BRGEW: varchar("BRGEW", { length: 13 }), // Gross weight (총 중량) + GEWEI: varchar("GEWEI", { length: 3 }), // Weight Unit (중량 단위) + NTGEW: varchar("NTGEW", { length: 13 }), // Net Weight (순 중량) + VOLUM: varchar("VOLUM", { length: 13 }), // Volume (체적) + VOLEH: varchar("VOLEH", { length: 3 }), // Volume Unit (체적 단위) + GROES: varchar("GROES", { length: 32 }), // Size/dimensions (크기/치수) + LAENG: varchar("LAENG", { length: 13 }), // Length (길이) + BREIT: varchar("BREIT", { length: 13 }), // Width (너비) + HOEHE: varchar("HOEHE", { length: 13 }), // Height (높이) + MEABM: varchar("MEABM", { length: 3 }), // Unit of Dimension for Length/Width/Height (치수 단위) + MAGRV: varchar("MAGRV", { length: 4 }), // Material Group: Packaging Materials (포장 자재 그룹) + VHART: varchar("VHART", { length: 4 }), // Packaging Material Type (포장 자재 유형) + ZZNAME: varchar("ZZNAME", { length: 40 }), // Material Name (자재 이름) + ZZSPEC: varchar("ZZSPEC", { length: 255 }), // Specification (자재 사양) + ZZDESC: varchar("ZZDESC", { length: 255 }), // Description (자재 설명) + ZZMMTYP: varchar("ZZMMTYP", { length: 1 }), // Material Master Type (자재 마스터 유형) + ZZREGDT: varchar("ZZREGDT", { length: 8 }), // Registered Date (등록 날짜) + ZZREGTM: varchar("ZZREGTM", { length: 6 }), // Registered Time (등록 시간) + ZZREGUS: varchar("ZZREGUS", { length: 12 }), // Registerd User (등록 사용자) + ZZAPPDT: varchar("ZZAPPDT", { length: 8 }), // Approval Date (승인 날짜) + ZZAPPTM: varchar("ZZAPPTM", { length: 6 }), // Approval Time (승인 시간) + ZZAPPUS: varchar("ZZAPPUS", { length: 12 }), // Approval User (승인 사용자) + ZZLAMDT: varchar("ZZLAMDT", { length: 8 }), // Last Modified Date (최종 수정 날짜) + ZZLAMTM: varchar("ZZLAMTM", { length: 6 }), // Last Modified Time (최종 수정 시간) + ZZLAMUS: varchar("ZZLAMUS", { length: 12 }), // Last Modified User (최종 수정 사용자) + ZZPRFLG: varchar("ZZPRFLG", { length: 1 }), // CRUD Status (처리 플래그) + ZZDOKAR: varchar("ZZDOKAR", { length: 3 }), // Document Type (문서 유형) + ZZDOKNR: varchar("ZZDOKNR", { length: 25 }), // Document Number (문서 번호) + ZZDOKTL: varchar("ZZDOKTL", { length: 3 }), // Document Part (문서 부분) + ZZDOKVR: varchar("ZZDOKVR", { length: 2 }), // Document Version (문서 버전) + createdAt: timestamp("created_at").defaultNow().notNull(), + updatedAt: timestamp("updated_at").defaultNow().notNull(), +}); + +// 자재 설명 테이블 (DESC) +export const DESC = pgTable("DESC", { + id: serial("id").primaryKey(), + MATNR: varchar("MATNR", { length: 18 }).notNull(), // Material Number (자재 번호) (FK) + SPRAS: varchar("SPRAS", { length: 1 }), // Language (언어) + MAKTX: varchar("MAKTX", { length: 40 }), // Material Description (Short Text) (자재 설명) + createdAt: timestamp("created_at").defaultNow().notNull(), + updatedAt: timestamp("updated_at").defaultNow().notNull(), +}); + +// 플랜트별 자재 데이터 테이블 (PLNT) +export const PLNT = pgTable("PLNT", { + id: serial("id").primaryKey(), + MATNR: varchar("MATNR", { length: 18 }).notNull(), // Material Number (자재 번호) (FK) + WERKS: varchar("WERKS", { length: 4 }), // Plant (플랜트) + LVORM: varchar("LVORM", { length: 1 }), // Deletion Flag (삭제 플래그) + MMSTA: varchar("MMSTA", { length: 2 }), // Plant-Specific Material Status (플랜트별 자재 상태) + MMSTD: varchar("MMSTD", { length: 8 }), // Date from which the plant-specific material status (플랜트별 자재 상태 유효 날짜) + ZZMTARP: varchar("ZZMTARP", { length: 4 }), // Plant Material Type (플랜트 자재 유형) + ZZREGDT: varchar("ZZREGDT", { length: 8 }), // Registered Dated (등록 날짜) + ZZREGTM: varchar("ZZREGTM", { length: 6 }), // Registered Time (등록 시간) + ZZREGUS: varchar("ZZREGUS", { length: 12 }), // Registered USER (등록 사용자) + ZZLAMDT: varchar("ZZLAMDT", { length: 8 }), // Last Modified Date (최종 수정 날짜) + ZZLAMTM: varchar("ZZLAMTM", { length: 6 }), // Last Modified Time (최종 수정 시간) + ZZLAMUS: varchar("ZZLAMUS", { length: 12 }), // Last Modified User (최종 수정 사용자) + ZZPRFLG: varchar("ZZPRFLG", { length: 1 }), // CRUD Status (처리 플래그) + createdAt: timestamp("created_at").defaultNow().notNull(), + updatedAt: timestamp("updated_at").defaultNow().notNull(), +}); + +// 단위 테이블 (UNIT) +export const UNIT = pgTable("UNIT", { + id: serial("id").primaryKey(), + MATNR: varchar("MATNR", { length: 18 }).notNull(), // Material Number (자재 번호) (FK) + MEINH: varchar("MEINH", { length: 3 }), // Alternative Unit of Measure for Stockkeeping Unit (대체 단위) + UMREZ: varchar("UMREZ", { length: 5 }), // Numerator for Conversion to Base Units of Measure (기본 단위 변환 분자) + UMREN: varchar("UMREN", { length: 5 }), // Denominator for conversion to base units of measure (기본 단위 변환 분모) + LAENG: varchar("LAENG", { length: 13 }), // Length (길이) + BREIT: varchar("BREIT", { length: 13 }), // Width (너비) + HOEHE: varchar("HOEHE", { length: 13 }), // Height (높이) + MEABM: varchar("MEABM", { length: 3 }), // Unit of Dimension for Length/Width/Height (치수 단위) + VOLUM: varchar("VOLUM", { length: 13 }), // Volume (체적) + VOLEH: varchar("VOLEH", { length: 3 }), // Volume unit (체적 단위) + BRGEW: varchar("BRGEW", { length: 13 }), // Gross Weight (총 중량) + GEWEI: varchar("GEWEI", { length: 3 }), // Weight Unit (중량 단위) + createdAt: timestamp("created_at").defaultNow().notNull(), + updatedAt: timestamp("updated_at").defaultNow().notNull(), +}); + +// 클래스 할당 테이블 (CLASSASGN) +export const CLASSASGN = pgTable("CLASSASGN", { + id: serial("id").primaryKey(), + MATNR: varchar("MATNR", { length: 18 }).notNull(), // Material Number (자재 번호) (FK) + CLASS: varchar("CLASS", { length: 18 }), // Class number (클래스 번호) + KLART: varchar("KLART", { length: 3 }), // Class Type (클래스 유형) + createdAt: timestamp("created_at").defaultNow().notNull(), + updatedAt: timestamp("updated_at").defaultNow().notNull(), +}); + +// 특성 할당 테이블 (CHARASGN) +export const CHARASGN = pgTable("CHARASGN", { + id: serial("id").primaryKey(), + MATNR: varchar("MATNR", { length: 18 }).notNull(), // Material Number (자재 번호) (FK) + CLASS: varchar("CLASS", { length: 18 }), // Class number (클래스 번호) + KLART: varchar("KLART", { length: 3 }), // Class Type (클래스 유형) + ATNAM: varchar("ATNAM", { length: 30 }), // Characteristic Name (특성 이름) + ATWRT: varchar("ATWRT", { length: 30 }), // Characteristic Value (특성 값) + ATFLV: varchar("ATFLV", { length: 16 }), // Internal floating point from (내부 실수값 시작) + ATAWE: varchar("ATAWE", { length: 3 }), // Unit of Measurement (측정 단위) + ATFLB: varchar("ATFLB", { length: 16 }), // Internal floating point value to (내부 실수값 끝) + ATAW1: varchar("ATAW1", { length: 3 }), // Unit of Measurement (측정 단위) + ATBEZ: varchar("ATBEZ", { length: 30 }), // 특성내역 (특성 설명) + ATWTB: varchar("ATWTB", { length: 30 }), // 특성값내역 (특성 값 설명) + createdAt: timestamp("created_at").defaultNow().notNull(), + updatedAt: timestamp("updated_at").defaultNow().notNull(), +}); + +// 관계 정의 +export const MATLRelations = relations(MATL, ({ many }) => ({ + descriptions: many(DESC), + plants: many(PLNT), + units: many(UNIT), + classAssignments: many(CLASSASGN), + characteristicAssignments: many(CHARASGN), +})); + +export const DESCRelations = relations(DESC, ({ one }) => ({ + material: one(MATL, { + fields: [DESC.MATNR], + references: [MATL.MATNR], + }), +})); + +export const PLNTRelations = relations(PLNT, ({ one }) => ({ + material: one(MATL, { + fields: [PLNT.MATNR], + references: [MATL.MATNR], + }), +})); + +export const UNITRelations = relations(UNIT, ({ one }) => ({ + material: one(MATL, { + fields: [UNIT.MATNR], + references: [MATL.MATNR], + }), +})); + +export const CLASSASGNRelations = relations(CLASSASGN, ({ one }) => ({ + material: one(MATL, { + fields: [CLASSASGN.MATNR], + references: [MATL.MATNR], + }), +})); + +export const CHARASGNRelations = relations(CHARASGN, ({ one }) => ({ + material: one(MATL, { + fields: [CHARASGN.MATNR], + references: [MATL.MATNR], + }), +})); |
