1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
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', ['기장', '전장', '선실', '배관', '철의']);
// 해양 TOP 기능(공종) 유형 enum 정의
export const offshoreTopWorkTypeEnum = pgEnum('offshore_top_work_type', ['TM', 'TS', 'TE', 'TP']);
// 해양 HULL 기능(공종) 유형 enum 정의
export const offshoreHullWorkTypeEnum = pgEnum('offshore_hull_work_type', ['HA', 'HE', 'HH', 'HM', 'NC']);
//조선 아이템 테이블
//아이템코드(:자재그룹코드), 아이템이름(:아이템리스트), 공종(:workType), 선종, createdAt(:생성일), updatedAt(:수정일)
export const itemShipbuilding = pgTable("item_shipbuilding", {
id: serial("id").primaryKey(),
itemCode: varchar("item_code", { length: 100 }).notNull().references(() => items.itemCode, { onDelete: 'cascade' }),
workType: workTypeEnum("work_type").notNull(),
itemList: text("item_list"),
shipTypes: text("ship_types").notNull().default('OPTION'),
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow().notNull(),
});
//조선 아이템 관계 정의
export const itemShipbuildingRelations = relations(itemShipbuilding, ({ one }) => ({
item: one(items, {
fields: [itemShipbuilding.itemCode],
references: [items.itemCode],
}),
}));
export type ItemShipbuilding = typeof itemShipbuilding.$inferSelect;
export type ItemWithShipbuilding = Item & ItemShipbuilding;
//해양 TOP 아이템 테이블
export const itemOffshoreTop = pgTable("item_offshore_top", {
id: serial("id").primaryKey(),
itemCode: varchar("item_code", { length: 100 }).notNull().references(() => items.itemCode, { onDelete: 'cascade' }),
workType: offshoreTopWorkTypeEnum("work_type").notNull(),
itemList: text("item_list"),
subItemList: text("sub_item_list"),
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow().notNull(),
});
//해양 HULL 아이템 테이블
export const itemOffshoreHull = pgTable("item_offshore_hull", {
id: serial("id").primaryKey(),
itemCode: varchar("item_code", { length: 100 }).notNull().references(() => items.itemCode, { onDelete: 'cascade' }),
workType: offshoreHullWorkTypeEnum("work_type").notNull(),
itemList: text("item_list"),
subItemList: text("sub_item_list"),
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow().notNull(),
});
//해양 TOP 아이템 관계 정의
export const itemOffshoreTopRelations = relations(itemOffshoreTop, ({ one }) => ({
item: one(items, {
fields: [itemOffshoreTop.itemCode],
references: [items.itemCode],
}),
}));
//해양 HULL 아이템 관계 정의
export const itemOffshoreHullRelations = relations(itemOffshoreHull, ({ one }) => ({
item: one(items, {
fields: [itemOffshoreHull.itemCode],
references: [items.itemCode],
}),
}));
export type ItemOffshoreTop = typeof itemOffshoreTop.$inferSelect;
export type ItemOffshoreHull = typeof itemOffshoreHull.$inferSelect;
export type ItemWithOffshoreTop = Item & ItemOffshoreTop;
export type ItemWithOffshoreHull = Item & ItemOffshoreHull;
//각 테이블별 컬럼 변경(itemid -> itemCode)
|