generator client { provider = "prisma-client-js" } datasource db { provider = "mysql" url = env("DATABASE_URL") } enum RoleType { SUPER_ADMIN OPERATOR AUDITOR VIEWER } enum UserStatus { ACTIVE DISABLED } enum TemplateStatus { ENABLED DISABLED } enum FieldType { TEXT NUMBER DATE IMAGE FILE LINK TEXTAREA } enum ArtworkStatus { DRAFT ACTIVE DISABLED } enum AuditStatus { PENDING APPROVED REJECTED } enum ArtworkRevisionStatus { PENDING APPROVED REJECTED } enum NodeType { CREATE PRODUCE STORAGE OUTBOUND OTHER } enum CertType { PHOTO CERT APPRAISAL } enum BatchStatus { PENDING GENERATING DONE FAILED } enum TraceCodeStatus { INACTIVE ACTIVE DISABLED ABNORMAL } enum ProofStatus { PENDING CONFIRMING ONCHAIN FAILED } enum QueryResult { FIRST_ACTIVATE REPEAT INVALID DISABLED ABNORMAL } enum JobType { GEN_CODE IMPORT_OUTBOUND IMPORT_OUTBOUND_PREVIEW WATERMARK ONCHAIN BACKUP RESTORE } enum JobStatus { PENDING PROCESSING SUCCESS PARTIAL FAILED } enum OutboundImportSessionStatus { PARSING READY IMPORTING IMPORTED FAILED EXPIRED } enum OutboundImportRowStatus { VALID INVALID IMPORTED FAILED } enum BackupStatus { PENDING PROCESSING SUCCESS FAILED } model SysUser { id Int @id @default(autoincrement()) username String @unique passwordHash String @map("password_hash") realName String? @map("real_name") role RoleType @default(VIEWER) status UserStatus @default(ACTIVE) lastLoginAt DateTime? @map("last_login_at") createdAt DateTime @default(now()) @map("created_at") updatedAt DateTime @updatedAt @map("updated_at") artworks Artwork[] operationLogs OperationLog[] outboundImportSessions OutboundImportSession[] backupRecords BackupRecord[] submittedArtworkRevisions ArtworkRevision[] @relation("ArtworkRevisionSubmitter") reviewedArtworkRevisions ArtworkRevision[] @relation("ArtworkRevisionReviewer") @@map("sys_user") } model Template { id Int @id @default(autoincrement()) name String remark String? status TemplateStatus @default(ENABLED) createdAt DateTime @default(now()) @map("created_at") updatedAt DateTime @updatedAt @map("updated_at") deletedAt DateTime? @map("deleted_at") fields TemplateField[] artworks Artwork[] @@map("template") } model TemplateField { id Int @id @default(autoincrement()) templateId Int @map("template_id") fieldKey String @map("field_key") label String type FieldType @default(TEXT) required Boolean @default(false) sortOrder Int @default(0) @map("sort_order") template Template @relation(fields: [templateId], references: [id], onDelete: Cascade) @@index([templateId]) @@map("template_field") } model Artwork { id Int @id @default(autoincrement()) templateId Int @map("template_id") title String artist String? archiveNo String? @unique @map("archive_no") dynamicFields Json? @map("dynamic_fields") images Json? status ArtworkStatus @default(DRAFT) auditStatus AuditStatus @default(PENDING) @map("audit_status") auditRemark String? @map("audit_remark") auditedBy Int? @map("audited_by") auditedAt DateTime? @map("audited_at") createdBy Int? @map("created_by") createdAt DateTime @default(now()) @map("created_at") updatedAt DateTime @updatedAt @map("updated_at") deletedAt DateTime? @map("deleted_at") template Template @relation(fields: [templateId], references: [id]) creator SysUser? @relation(fields: [createdBy], references: [id]) traceNodes TraceNode[] certificates Certificate[] batches Batch[] traceCodes TraceCode[] revisions ArtworkRevision[] @@index([templateId]) @@index([status]) @@index([auditStatus]) @@map("artwork") } model ArtworkRevision { id String @id @default(cuid()) artworkId Int @map("artwork_id") title String reason String? @db.Text beforeSnapshot Json @map("before_snapshot") afterSnapshot Json @map("after_snapshot") status ArtworkRevisionStatus @default(PENDING) auditRemark String? @db.Text @map("audit_remark") submittedBy Int? @map("submitted_by") submittedAt DateTime @default(now()) @map("submitted_at") reviewedBy Int? @map("reviewed_by") reviewedAt DateTime? @map("reviewed_at") artwork Artwork @relation(fields: [artworkId], references: [id], onDelete: Cascade) submitter SysUser? @relation("ArtworkRevisionSubmitter", fields: [submittedBy], references: [id]) reviewer SysUser? @relation("ArtworkRevisionReviewer", fields: [reviewedBy], references: [id]) @@index([artworkId]) @@index([status]) @@index([submittedAt]) @@map("artwork_revision") } model TraceNode { id Int @id @default(autoincrement()) artworkId Int @map("artwork_id") nodeType NodeType @default(OTHER) @map("node_type") title String occurredAt DateTime? @map("occurred_at") location String? description String? @db.Text mediaFiles Json? @map("media_files") sortOrder Int @default(0) @map("sort_order") artwork Artwork @relation(fields: [artworkId], references: [id], onDelete: Cascade) @@index([artworkId]) @@map("trace_node") } model Certificate { id Int @id @default(autoincrement()) artworkId Int @map("artwork_id") name String issuer String? issuedAt DateTime? @map("issued_at") type CertType @default(CERT) originFileUrl String @map("origin_file_url") watermarkFileUrl String? @map("watermark_file_url") createdAt DateTime @default(now()) @map("created_at") artwork Artwork @relation(fields: [artworkId], references: [id], onDelete: Cascade) @@index([artworkId]) @@map("certificate") } model TraceCodeGroup { id Int @id @default(autoincrement()) name String remark String? createdAt DateTime @default(now()) @map("created_at") traceCodes TraceCode[] @@map("trace_code_group") } model Batch { id Int @id @default(autoincrement()) batchNo String @unique @map("batch_no") artworkId Int @map("artwork_id") quantity Int generatedCount Int @default(0) @map("generated_count") status BatchStatus @default(PENDING) createdBy Int? @map("created_by") createdAt DateTime @default(now()) @map("created_at") artwork Artwork @relation(fields: [artworkId], references: [id]) traceCodes TraceCode[] @@index([artworkId]) @@map("batch") } model TraceCode { id BigInt @id @default(autoincrement()) code String @unique shortCode String @unique @map("short_code") artworkId Int @map("artwork_id") batchId Int @map("batch_id") groupId Int? @map("group_id") outTime DateTime? @map("out_time") outImage String? @map("out_image") outImages Json? @map("out_images") remark String? status TraceCodeStatus @default(INACTIVE) queryCount Int @default(0) @map("query_count") firstActivatedAt DateTime? @map("first_activated_at") lastQueriedAt DateTime? @map("last_queried_at") url String? createdAt DateTime @default(now()) @map("created_at") artwork Artwork @relation(fields: [artworkId], references: [id]) batch Batch @relation(fields: [batchId], references: [id]) group TraceCodeGroup? @relation(fields: [groupId], references: [id]) proofs BlockchainProof[] queryLogs QueryLog[] @@index([artworkId]) @@index([batchId]) @@index([groupId]) @@index([status]) @@map("trace_code") } model TraceCodeDailySequence { dateKey String @id @map("date_key") @db.VarChar(6) nextSeq Int @default(0) @map("next_seq") updatedAt DateTime @updatedAt @map("updated_at") @@map("trace_code_daily_sequence") } model BlockchainProof { id Int @id @default(autoincrement()) traceCodeId BigInt @map("trace_code_id") dataHash String @map("data_hash") txHash String? @map("tx_hash") blockHash String? @map("block_hash") blockHeight BigInt? @map("block_height") chainName String? @map("chain_name") explorerUrl String? @map("explorer_url") onchainAt DateTime? @map("onchain_at") status ProofStatus @default(PENDING) rawResponse Json? @map("raw_response") createdAt DateTime @default(now()) @map("created_at") traceCode TraceCode @relation(fields: [traceCodeId], references: [id], onDelete: Cascade) @@index([traceCodeId]) @@map("blockchain_proof") } model QueryLog { id BigInt @id @default(autoincrement()) traceCodeId BigInt? @map("trace_code_id") artworkId Int? @map("artwork_id") shortCode String? @map("short_code") code String? archiveNo String? @map("archive_no") batchNo String? @map("batch_no") queryCount Int? @map("query_count") firstActivatedAt DateTime? @map("first_activated_at") queriedAt DateTime @default(now()) @map("queried_at") queryResult QueryResult @map("query_result") ip String? userAgent String? @db.Text @map("user_agent") deviceType String? @map("device_type") browser String? os String? traceCode TraceCode? @relation(fields: [traceCodeId], references: [id]) @@index([traceCodeId]) @@index([queriedAt]) @@index([archiveNo]) @@index([batchNo]) @@map("query_log") } model Job { id String @id @default(cuid()) type JobType status JobStatus @default(PENDING) total Int @default(0) successCount Int @default(0) @map("success_count") failCount Int @default(0) @map("fail_count") resultFileUrl String? @map("result_file_url") payload Json? error String? @db.Text createdBy Int? @map("created_by") createdAt DateTime @default(now()) @map("created_at") updatedAt DateTime @updatedAt @map("updated_at") @@map("job") } model OperationLog { id BigInt @id @default(autoincrement()) userId Int? @map("user_id") username String? role RoleType? module String action String method String path String targetId String? @map("target_id") status String message String? @db.Text ip String? userAgent String? @db.Text @map("user_agent") durationMs Int? @map("duration_ms") requestSummary Json? @map("request_summary") createdAt DateTime @default(now()) @map("created_at") user SysUser? @relation(fields: [userId], references: [id]) @@index([userId]) @@index([module]) @@index([action]) @@index([status]) @@index([createdAt]) @@map("operation_log") } model OutboundImportSession { id String @id @default(cuid()) status OutboundImportSessionStatus @default(PARSING) fileName String @map("file_name") fileKey String? @map("file_key") total Int @default(0) validCount Int @default(0) @map("valid_count") invalidCount Int @default(0) @map("invalid_count") error String? @db.Text committedAt DateTime? @map("committed_at") expiresAt DateTime @map("expires_at") createdBy Int? @map("created_by") createdAt DateTime @default(now()) @map("created_at") updatedAt DateTime @updatedAt @map("updated_at") creator SysUser? @relation(fields: [createdBy], references: [id]) rows OutboundImportRow[] @@index([status]) @@index([createdBy]) @@index([expiresAt]) @@map("outbound_import_session") } model OutboundImportRow { id BigInt @id @default(autoincrement()) sessionId String @map("session_id") rowNo Int @map("row_no") status OutboundImportRowStatus @default(INVALID) shortCode String? @map("short_code") batchNo String? @map("batch_no") outTime DateTime? @map("out_time") outImagePaths Json? @map("out_image_paths") outImageKeys Json? @map("out_image_keys") txHash String? @map("tx_hash") onchainAt DateTime? @map("onchain_at") blockHeight BigInt? @map("block_height") remark String? reason String? @db.Text preview Json? createdAt DateTime @default(now()) @map("created_at") session OutboundImportSession @relation(fields: [sessionId], references: [id], onDelete: Cascade) @@index([sessionId]) @@index([status]) @@index([shortCode]) @@map("outbound_import_row") } model BackupRecord { id String @id @default(cuid()) fileName String @map("file_name") filePath String @map("file_path") size BigInt @default(0) status BackupStatus @default(PENDING) mode String @default("BACKUP") manifest Json? error String? @db.Text createdBy Int? @map("created_by") createdAt DateTime @default(now()) @map("created_at") updatedAt DateTime @updatedAt @map("updated_at") creator SysUser? @relation(fields: [createdBy], references: [id]) @@index([status]) @@index([mode]) @@index([createdBy]) @@index([createdAt]) @@map("backup_record") } model SystemSetting { id Int @id @default(autoincrement()) key String @unique value String @db.Text updatedAt DateTime @updatedAt @map("updated_at") @@map("system_setting") }