diff options
Diffstat (limited to 'db/schema')
| -rw-r--r-- | db/schema/integration-log.ts | 24 | ||||
| -rw-r--r-- | db/schema/integration.ts | 91 |
2 files changed, 115 insertions, 0 deletions
diff --git a/db/schema/integration-log.ts b/db/schema/integration-log.ts new file mode 100644 index 00000000..d90a36ec --- /dev/null +++ b/db/schema/integration-log.ts @@ -0,0 +1,24 @@ +import { pgTable, text, timestamp, varchar, serial, integer } from 'drizzle-orm/pg-core'; +import { integrations } from './integration'; + +export const integrationLogTable = pgTable('integration_log', { + id: serial("id").primaryKey(), + integrationId: integer("integration_id").notNull().references(() => integrations.id), + executionTime: timestamp('execution_time').notNull().defaultNow(), + status: varchar('status', { length: 50 }).notNull(), // 'success', 'failed', 'timeout', 'pending' + responseTime: integer('response_time'), // 응답시간 (ms) + errorMessage: text('error_message'), // 에러 메시지 + httpStatusCode: integer('http_status_code'), // HTTP 상태 코드 + retryCount: integer('retry_count').default(0), // 재시도 횟수 + requestMethod: varchar('request_method', { length: 10 }), // GET, POST, PUT, DELETE + requestUrl: text('request_url'), // 실제 요청 URL + ipAddress: varchar('ip_address', { length: 45 }), // 요청 IP 주소 + userAgent: text('user_agent'), // User Agent + sessionId: varchar('session_id', { length: 100 }), // 세션 ID + correlationId: varchar('correlation_id', { length: 100 }), // 상관관계 ID + createdAt: timestamp('created_at').notNull().defaultNow(), +}); + +// 타입 정의 +export type IntegrationLog = typeof integrationLogTable.$inferSelect; +export type NewIntegrationLog = typeof integrationLogTable.$inferInsert;
\ No newline at end of file diff --git a/db/schema/integration.ts b/db/schema/integration.ts new file mode 100644 index 00000000..02e5b486 --- /dev/null +++ b/db/schema/integration.ts @@ -0,0 +1,91 @@ +import { + pgTable, serial, integer, varchar, text, jsonb, timestamp, + pgEnum, index +} from "drizzle-orm/pg-core"; +import { users } from "./users"; + +/* ---------- ① ENUM 정의 ---------- */ +export const integrationTypeEnum = pgEnum("integration_type", [ + "rest_api", // REST/JSON + "soap", // SOAP/XML + "db_to_db" // DB Link·ETL·FDW 등 +]); + +export const integrationStatusEnum = pgEnum("integration_status", [ + "active", + "inactive", + "deprecated" +]); + +export const integrationChangeEnum = pgEnum("integration_change_type", [ + "create", + "update", + "status_change", + "delete" +]); + +/* ---------- ② 통합 리스트 ---------- */ +export const integrations = pgTable( + "integrations", + { + id: serial("id").primaryKey(), + /** 업무식별용 코드('INT_OPS_001') — URL·로그 등 여러 곳에서 쓰기 좋음 */ + code: varchar("code", { length: 50 }).unique().notNull(), + name: varchar("name", { length: 255 }).notNull(), + type: integrationTypeEnum("type").notNull(), + description: text("description"), + /** 양쪽 시스템 식별자(ERP, WMS 등) */ + sourceSystem: varchar("source_system", { length: 100 }).notNull(), + targetSystem: varchar("target_system", { length: 100 }).notNull(), + status: integrationStatusEnum("status").default("active").notNull(), + /** 각 통합별 개별 설정(JSON)—엔드포인트·쿼리·스케줄 등 */ + metadata: jsonb("metadata"), + /* 생성·수정 메타 */ + createdBy: integer("created_by") + .references(() => users.id, { onDelete: "set null" }), + updatedBy: integer("updated_by") + .references(() => users.id, { onDelete: "set null" }), + createdAt: timestamp("created_at").defaultNow().notNull(), + updatedAt: timestamp("updated_at").defaultNow().notNull() + }, + (t) => ({ + /* 조회용 보조 인덱스 */ + idxTypeStatus: index("idx_integrations_type_status") + .on(t.type, t.status) + }) +); + +/* ---------- ③ 이력 테이블 ---------- */ +export const integrationHistory = pgTable( + "integration_history", + { + id: serial("id").primaryKey(), + integrationId: integer("integration_id") + .references(() => integrations.id, { onDelete: "cascade" }) + .notNull(), + changeType: integrationChangeEnum("change_type").notNull(), + /* + * 변경 전·후 diff 또는 전체 스냅샷. + * { before: {...}, after: {...} } 구조로 저장해 두면 + * UI에서 쉽게 '줄바꿈 diff' 로 표시 가능 + */ + diff: jsonb("diff").notNull(), + changedBy: integer("changed_by") + .references(() => users.id, { onDelete: "set null" }), + changedAt: timestamp("changed_at").defaultNow().notNull(), + /* 필요 시 다중 변경 그룹핑용 트랜잭션-ID */ + txId: varchar("tx_id", { length: 50 }) + }, + (t) => ({ + idxIntegration: index("idx_history_integration") + .on(t.integrationId), + idxChangedAt: index("idx_history_changed_at") + .on(t.changedAt) + }) +); + +// 타입 정의 +export type Integration = typeof integrations.$inferSelect; +export type NewIntegration = typeof integrations.$inferInsert; +export type IntegrationHistory = typeof integrationHistory.$inferSelect; +export type NewIntegrationHistory = typeof integrationHistory.$inferInsert;
\ No newline at end of file |
