import { relations } from "drizzle-orm"; import { pgTable, varchar, text, timestamp ,serial, integer, pgEnum} from "drizzle-orm/pg-core" export const items = pgTable("items", { id: serial("id").primaryKey(), itemCode: varchar("item_code", { length: 100 }).unique(), itemName: varchar("item_name", { length: 255 }).notNull(), description: text("description"), createdAt: timestamp("created_at").defaultNow().notNull(), updatedAt: timestamp("updated_at").defaultNow().notNull(), }); export type Item = typeof items.$inferSelect export const itemsRelations = relations(items, ({ many }) => ({ shipbuilding: many(itemShipbuilding), })); // 조선 기능(공종) 유형 enum 정의 export const workTypeEnum = pgEnum('work_type', ['기장', '전장', '선실', '배관', '철의']); //조선 아이템 테이블 //아이템코드(:자재그룹코드), 아이템이름(:아이템리스트), 공종(:workType), 선종, createdAt(:생성일), updatedAt(:수정일) export const itemShipbuilding = pgTable("item_shipbuilding", { id: serial("id").primaryKey(), itemId: integer("item_id").notNull().references(() => items.id, { onDelete: 'cascade' }), workType: workTypeEnum("work_type").notNull(), shipTypes: text("ship_types").notNull().default('A-MAX'), }); //조선 아이템 관계 정의 export const itemShipbuildingRelations = relations(itemShipbuilding, ({ one }) => ({ item: one(items, { fields: [itemShipbuilding.itemId], references: [items.id], }), })); export type ItemShipbuilding = typeof itemShipbuilding.$inferSelect; export type ItemWithShipbuilding = Item & ItemShipbuilding;