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
94
95
96
97
98
99
100
101
102
103
104
105
106
|
import { boolean, jsonb, text, timestamp, integer, uuid } from "drizzle-orm/pg-core";
import { knoxSchema } from "./employee";
import { users } from '@/db/schema/users';
/**
* 결재 관련 테이블 정의
*
* 템플릿 관리
* 결재선 관리
* 결재 로그 관리 (히스토리 관리)
*
*/
// 결재 템플릿 히스토리
export const approvalTemplateHistory = knoxSchema.table('approval_template_history', {
id: uuid().primaryKey().defaultRandom(), // 히스토리 아이디 UUID
templateId: uuid()
.references(() => approvalTemplates.id, { onDelete: 'cascade' })
.notNull(),
version: integer().notNull(), // 히스토리 버전
subject: text().notNull(), // 템플릿 제목
content: text().notNull(), // 템플릿 내용
changeDescription: text(), // 변경 사항 설명
changedBy: integer() // 변경자 - eVCP 유저 아이디 기반 참조
.notNull()
.references(() => users.id, { onDelete: 'set null' }),
createdAt: timestamp().defaultNow().notNull(),
// 히스토리는 업데이트 없음. 생성 시점만 기록.
});
// 실제 결재 상신 로그
export const approvalLogs = knoxSchema.table("approval_logs", {
apInfId: text("ap_inf_id").primaryKey(),
userId: text("user_id").notNull(),
epId: text("ep_id").notNull(),
emailAddress: text("email_address").notNull(),
subject: text("subject").notNull(),
content: text("content").notNull(),
status: text("status").notNull(),
aplns: jsonb("aplns").notNull(), // approval lines = 결재선
isDeleted: boolean("is_deleted").notNull().default(false),
createdAt: timestamp("created_at").notNull().defaultNow(),
updatedAt: timestamp("updated_at").notNull().defaultNow(),
});
// 결재 템플릿
export const approvalTemplates = knoxSchema.table('approval_templates', {
id: uuid().primaryKey().defaultRandom(), // 템플릿 아이디 UUID
name: text().notNull(), // 템플릿 이름
// slug: text('slug').notNull().unique(), // 템플릿 슬러그는 UUID로 대체하기
subject: text().notNull(), // 템플릿 제목
content: text().notNull(), // 템플릿 내용
description: text(), // 템플릿 설명
category: text(), // 템플릿 카테고리 설명
// 선택된 결재선 참조 (nullable, 결재선은 별도에서 관리)
approvalLineId: uuid().references(() => approvalLines.id, { onDelete: 'set null' }),
// 메타데이터
createdBy: integer() // 템플릿 생성자 - eVCP 유저 아이디 기반 참조
.notNull()
.references(() => users.id, { onDelete: 'set null' }),
createdAt: timestamp().defaultNow().notNull(),
updatedAt: timestamp().defaultNow().notNull(),
});
// 결재선 템플릿
export const approvalLines = knoxSchema.table('approval_lines', {
id: uuid().primaryKey().defaultRandom(), // 결재선 아이디 UUID
name: text().notNull(), // 결재선 이름
description: text(), // 결재선 설명
category: text(),
// 핵심
aplns: jsonb().notNull(), // 결재선 구성
// 메타데이터
createdBy: integer() // 결재선 생성자 - eVCP 유저 아이디 기반 참조
.notNull()
.references(() => users.id, { onDelete: 'set null' }),
createdAt: timestamp().defaultNow().notNull(),
updatedAt: timestamp().defaultNow().notNull(),
});
//
// 결재 템플릿 변수
export const approvalTemplateVariables = knoxSchema.table('approval_template_variables', {
id: uuid().primaryKey().defaultRandom(), // 변수 아이디 UUID
approvalTemplateId: uuid()
.references(() => approvalTemplates.id, { onDelete: 'cascade' }),
variableName: text().notNull(), // 변수 이름
variableType: text().notNull(), // 변수 타입
defaultValue: text(), // 변수 기본값
description: text(), // 변수 설명
// 메타데이터
createdBy: integer() // 변수 생성자 - eVCP 유저 아이디 기반 참조
.notNull()
.references(() => users.id, { onDelete: 'set null' }),
createdAt: timestamp().defaultNow().notNull(),
updatedAt: timestamp().defaultNow().notNull(),
});
|