summaryrefslogtreecommitdiff
path: root/db/schema/knox/approvals.ts
diff options
context:
space:
mode:
Diffstat (limited to 'db/schema/knox/approvals.ts')
-rw-r--r--db/schema/knox/approvals.ts98
1 files changed, 94 insertions, 4 deletions
diff --git a/db/schema/knox/approvals.ts b/db/schema/knox/approvals.ts
index 27332ed6..0f8ee90a 100644
--- a/db/schema/knox/approvals.ts
+++ b/db/schema/knox/approvals.ts
@@ -1,7 +1,36 @@
-import { boolean, jsonb, text, timestamp, } from "drizzle-orm/pg-core";
+import { boolean, jsonb, text, timestamp, integer, uuid } from "drizzle-orm/pg-core";
import { knoxSchema } from "./employee";
+import { users } from '@/db/schema/users';
-export const approval = knoxSchema.table("approval", {
+/**
+ * 결재 관련 테이블 정의
+ *
+ * 템플릿 관리
+ * 결재선 관리
+ * 결재 로그 관리 (히스토리 관리)
+ *
+ */
+
+// 결재 템플릿 히스토리
+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(),
@@ -9,8 +38,69 @@ export const approval = knoxSchema.table("approval", {
subject: text("subject").notNull(),
content: text("content").notNull(),
status: text("status").notNull(),
- aplns: jsonb("aplns").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(),
-}); \ No newline at end of file
+});
+
+
+// 결재 템플릿
+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(),
+});
+