summaryrefslogtreecommitdiff
path: root/db/schema/vendorDocu.ts
diff options
context:
space:
mode:
Diffstat (limited to 'db/schema/vendorDocu.ts')
-rw-r--r--db/schema/vendorDocu.ts28
1 files changed, 15 insertions, 13 deletions
diff --git a/db/schema/vendorDocu.ts b/db/schema/vendorDocu.ts
index 58c0ad29..789f2cd7 100644
--- a/db/schema/vendorDocu.ts
+++ b/db/schema/vendorDocu.ts
@@ -652,7 +652,7 @@ export const syncConfigs = pgTable(
"sync_configs",
{
id: serial("id").primaryKey(),
- projectId: integer("project_id").notNull(),
+ vendorId: integer("vendor_id").notNull(),
targetSystem: varchar("target_system", { length: 50 }).notNull(), // 'SHI', 'SAP' 등
syncEnabled: boolean("sync_enabled").default(true),
@@ -670,7 +670,7 @@ export const syncConfigs = pgTable(
(table) => {
return {
contractSystemIdx: index("idx_sync_configs_contract_system").on(
- table.projectId,
+ table.vendorId,
table.targetSystem
),
}
@@ -682,7 +682,7 @@ export const changeLogs = pgTable(
"change_logs",
{
id: serial("id").primaryKey(),
- projectId: integer("project_id").notNull(),
+ vendorId: integer("vendor_id").notNull(),
entityType: varchar("entity_type", { length: 50 }).notNull(), // 'document', 'revision', 'attachment'
entityId: integer("entity_id").notNull(),
@@ -701,8 +701,8 @@ export const changeLogs = pgTable(
},
(table) => {
return {
- projectSyncedIdx: index("idx_change_logs_project_synced").on(
- table.projectId,
+ vendorSyncedIdx: index("idx_change_logs_vendor_synced").on(
+ table.vendorId,
table.isSynced
),
createdAtIdx: index("idx_change_logs_created_at").on(table.createdAt),
@@ -717,7 +717,7 @@ export const syncBatches = pgTable(
"sync_batches",
{
id: serial("id").primaryKey(),
- projectId: integer("project_id").notNull(),
+ vendorId: integer("vendor_id").notNull(),
targetSystem: varchar("target_system", { length: 50 }).notNull(),
batchSize: integer("batch_size").notNull(),
@@ -736,7 +736,7 @@ export const syncBatches = pgTable(
(table) => {
return {
projectSystemIdx: index("idx_sync_batches_project_system").on(
- table.projectId,
+ table.vendorId,
table.targetSystem
),
statusIdx: index("idx_sync_batches_status").on(table.status),
@@ -747,7 +747,7 @@ export const syncBatches = pgTable(
// 동기화 상태 추적을 위한 뷰
export const syncStatusView = pgView("sync_status_view", {
- projectId: integer("project_id").notNull(),
+ vendorId: integer("vendor_id").notNull(),
targetSystem: varchar("target_system", { length: 50 }).notNull(),
totalChanges: integer("total_changes").notNull(),
pendingChanges: integer("pending_changes").notNull(),
@@ -759,7 +759,7 @@ export const syncStatusView = pgView("sync_status_view", {
}).as(sql`
WITH change_stats AS (
SELECT
- cl.project_id,
+ cl.vendor_id,
sc.target_system,
COUNT(*) as total_changes,
COUNT(CASE WHEN cl.is_synced = false AND cl.sync_attempts < sc.retry_max_attempts THEN 1 END) as pending_changes,
@@ -768,12 +768,12 @@ export const syncStatusView = pgView("sync_status_view", {
MAX(cl.synced_at) as last_sync_at
FROM change_logs cl
CROSS JOIN sync_configs sc
- WHERE cl.project_id = sc.project_id
+ WHERE cl.vendor_id = sc.vendor_id
AND (cl.target_systems IS NULL OR cl.target_systems @> to_jsonb(ARRAY[sc.target_system]))
- GROUP BY cl.project_id, sc.target_system
+ GROUP BY cl.vendor_id, sc.target_system
)
SELECT
- cs.project_id,
+ cs.vendor_id,
cs.target_system,
COALESCE(cs.total_changes, 0) as total_changes,
COALESCE(cs.pending_changes, 0) as pending_changes,
@@ -787,7 +787,7 @@ export const syncStatusView = pgView("sync_status_view", {
END as next_sync_at,
sc.sync_enabled
FROM sync_configs sc
- LEFT JOIN change_stats cs ON sc.project_id = cs.project_id AND sc.target_system = cs.target_system
+ LEFT JOIN change_stats cs ON sc.vendor_id = cs.vendor_id AND sc.target_system = cs.target_system
`)
// 타입 추출
@@ -897,6 +897,7 @@ export const simplifiedDocumentsView = pgView("simplified_documents_view", {
filePath: string;
fileSize: number | null;
fileType: string | null;
+ dolceFilePath: string | null;
createdAt: Date;
updatedAt: Date;
}>;
@@ -922,6 +923,7 @@ export const simplifiedDocumentsView = pgView("simplified_documents_view", {
'filePath', da.file_path,
'fileSize', da.file_size,
'fileType', da.file_type,
+ 'dolceFilePath', da.dolce_file_path,
'createdAt', da.created_at,
'updatedAt', da.updated_at
) ORDER BY da.created_at