summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authordujinkim <dujin.kim@dtsolution.co.kr>2025-08-04 09:36:26 +0000
committerdujinkim <dujin.kim@dtsolution.co.kr>2025-08-04 09:36:26 +0000
commit3e4d15271322397764601dee09441af8a5b3adf5 (patch)
tree2277d5f7154139b5cb155eb0edc0c36752112320 /db
parent92eda21e45d902663052575aaa4c4f80bfa2faea (diff)
parent59b5715ebb3e1fd7bd4eb02ce50399715734f865 (diff)
Merge branch 'dujinkim' of https://github.com/DTS-Development/SHI_EVCP into dujinkim
Diffstat (limited to 'db')
-rw-r--r--db/schema/docu-list-rule.ts49
1 files changed, 13 insertions, 36 deletions
diff --git a/db/schema/docu-list-rule.ts b/db/schema/docu-list-rule.ts
index 67d34d75..007646f9 100644
--- a/db/schema/docu-list-rule.ts
+++ b/db/schema/docu-list-rule.ts
@@ -1,4 +1,4 @@
-import { pgTable, serial, varchar, text, timestamp, boolean, integer } from "drizzle-orm/pg-core"
+import { pgTable, serial, varchar, text, timestamp, boolean, integer, unique } from "drizzle-orm/pg-core"
import { relations } from "drizzle-orm"
// ===== Code Groups 테이블 =====
@@ -18,7 +18,7 @@ export const codeGroups = pgTable("code_groups", {
export const documentClasses = pgTable("document_classes", {
id: serial("id").primaryKey(),
code: varchar("code", { length: 50 }).notNull().unique(), // CODE (자동 생성)
- value: varchar("value", { length: 100 }), // 사용자가 선택할 수 있는 값 (선택사항)
+ value: varchar("value", { length: 100 }).unique(), // 사용자가 선택할 수 있는 값 (고유해야 함)
description: varchar("description", { length: 200 }).notNull(), // 값의 의미 설명
codeGroupId: integer("code_group_id").references(() => codeGroups.id), // 참조하는 Code Group ID
isActive: boolean("is_active").default(true),
@@ -30,12 +30,19 @@ export const documentClasses = pgTable("document_classes", {
export const documentClassOptions = pgTable("document_class_options_new", {
id: serial("id").primaryKey(),
documentClassId: integer("document_class_id").notNull().references(() => documentClasses.id),
- optionValue: varchar("option_value", { length: 100 }).notNull(), // 하위 옵션 값 (예: "General", "Technical")
+ description: varchar("description", { length: 100 }).notNull(), // 하위 옵션 설명 (예: "General", "Technical")
optionCode: varchar("option_code", { length: 50 }), // 하위 옵션 코드 (선택사항)
- sortOrder: integer("sort_order").default(0), // 정렬 순서
isActive: boolean("is_active").default(true),
createdAt: timestamp("created_at", { withTimezone: true }).defaultNow().notNull(),
updatedAt: timestamp("updated_at", { withTimezone: true }).defaultNow().notNull(),
+}, (table) => {
+ return {
+ // 같은 Document Class 내에서 optionCode는 유니크해야 함
+ uniqueDocumentClassOption: unique("unique_document_class_option").on(
+ table.documentClassId,
+ table.optionCode
+ ),
+ }
})
// ===== ComboBox Settings 테이블 =====
@@ -49,19 +56,6 @@ export const comboBoxSettings = pgTable("combo_box_settings", {
updatedAt: timestamp("updated_at", { withTimezone: true }).defaultNow().notNull(),
})
-// ===== ComboBox Options 테이블 =====
-export const comboBoxOptions = pgTable("combo_box_options", {
- id: serial("id").primaryKey(),
- comboBoxSettingId: integer("combo_box_setting_id").notNull().references(() => comboBoxSettings.id),
- code: varchar("code", { length: 50 }).notNull(), // CODE (예: 100, 201, 202)
- description: varchar("description", { length: 200 }).notNull(), // Description (예: General, Feed Gas Reveive)
- remark: text("remark"), // Remark (비고)
- sortOrder: integer("sort_order").default(0), // 정렬 순서
- isActive: boolean("is_active").default(true),
- createdAt: timestamp("created_at", { withTimezone: true }).defaultNow().notNull(),
- updatedAt: timestamp("updated_at", { withTimezone: true }).defaultNow().notNull(),
-})
-
// ===== Document Number Types 테이블 =====
export const documentNumberTypes = pgTable("document_number_types", {
id: serial("id").primaryKey(),
@@ -76,8 +70,7 @@ export const documentNumberTypes = pgTable("document_number_types", {
export const documentNumberTypeConfigs = pgTable("document_number_type_configs", {
id: serial("id").primaryKey(),
documentNumberTypeId: integer("document_number_type_id").notNull().references(() => documentNumberTypes.id),
- codeGroupId: integer("code_group_id").references(() => codeGroups.id), // Code Group 또는 Document Class 중 하나만 선택
- documentClassId: integer("document_class_id").references(() => documentClasses.id), // Code Group 또는 Document Class 중 하나만 선택
+ codeGroupId: integer("code_group_id").references(() => codeGroups.id), // Code Group 참조
sdq: integer("sdq").notNull(), // 순서 번호 (1, 2, 3, 4, 5, 6)
description: varchar("description", { length: 200 }), // Description (예: [001] PROJECT NO)
remark: text("remark"), // Remark (비고)
@@ -114,20 +107,11 @@ export const documentClassOptionsRelations = relations(documentClassOptions, ({
}))
// ComboBox Settings 관계
-export const comboBoxSettingsRelations = relations(comboBoxSettings, ({ one, many }) => ({
+export const comboBoxSettingsRelations = relations(comboBoxSettings, ({ one }) => ({
codeGroup: one(codeGroups, {
fields: [comboBoxSettings.codeGroupId],
references: [codeGroups.id],
}),
- comboBoxOptions: many(comboBoxOptions), // ComboBox Setting 하위 옵션들
-}))
-
-// ComboBox Options 관계
-export const comboBoxOptionsRelations = relations(comboBoxOptions, ({ one }) => ({
- comboBoxSetting: one(comboBoxSettings, {
- fields: [comboBoxOptions.comboBoxSettingId],
- references: [comboBoxSettings.id],
- }),
}))
// Document Number Types 관계
@@ -145,10 +129,6 @@ export const documentNumberTypeConfigsRelations = relations(documentNumberTypeCo
fields: [documentNumberTypeConfigs.codeGroupId],
references: [codeGroups.id],
}),
- documentClass: one(documentClasses, {
- fields: [documentNumberTypeConfigs.documentClassId],
- references: [documentClasses.id],
- }),
}))
// ===== 타입 정의 =====
@@ -164,9 +144,6 @@ export type NewDocumentClassOption = typeof documentClassOptions.$inferInsert
export type ComboBoxSetting = typeof comboBoxSettings.$inferSelect
export type NewComboBoxSetting = typeof comboBoxSettings.$inferInsert
-export type ComboBoxOption = typeof comboBoxOptions.$inferSelect
-export type NewComboBoxOption = typeof comboBoxOptions.$inferInsert
-
export type DocumentNumberType = typeof documentNumberTypes.$inferSelect
export type NewDocumentNumberType = typeof documentNumberTypes.$inferInsert