Files

679 lines
21 KiB
Plaintext

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
SUBMITTING
CONFIRMING
ONCHAIN
FAILED
UNKNOWN
}
enum QueryResult {
FIRST_ACTIVATE
REPEAT
INVALID
DISABLED
ABNORMAL
}
enum JobType {
GEN_CODE
IMPORT_OUTBOUND
IMPORT_OUTBOUND_PREVIEW
BATCH_OUTBOUND
WATERMARK
ONCHAIN
BACKUP
RESTORE
}
enum JobStatus {
PENDING
PROCESSING
SUCCESS
PARTIAL
FAILED
}
enum JobItemStatus {
PENDING
PROCESSING
SUCCESS
FAILED
SKIPPED
UNKNOWN
}
enum OnchainChunkStatus {
PENDING
SUBMITTING
CONFIRMING
SUCCESS
PARTIAL
FAILED
UNKNOWN
}
enum OutboundImportSessionStatus {
PARSING
READY
IMPORTING
IMPORTED
PARTIAL
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")
createdOutboundRecords OutboundRecord[] @relation("OutboundRecordCreator")
updatedOutboundRecords OutboundRecord[] @relation("OutboundRecordUpdater")
uploadedOutboundImages OutboundImage[] @relation("OutboundImageUploader")
@@map("sys_user")
}
model Template {
id Int @id @default(autoincrement())
name String
remark String?
defaultTraceLayout Json? @map("default_trace_layout")
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?
showcaseImages Json? @map("showcase_images")
traceLayout Json? @map("trace_layout")
showOutboundTimeline Boolean @default(false) @map("show_outbound_timeline")
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[]
onchainChunks OnchainChunk[]
@@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? @map("audit_remark") @db.Text
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())
shortCode String @unique @map("short_code")
serialNo Int @unique @map("serial_no")
artworkId Int @map("artwork_id")
batchId Int @map("batch_id")
groupId Int? @map("group_id")
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[]
outbound OutboundRecord?
jobItems JobItem[]
@@index([artworkId])
@@index([batchId])
@@index([groupId])
@@index([status])
@@map("trace_code")
}
model TraceCodeSequence {
id Int @id
nextSeq Int @default(1) @map("next_seq")
updatedAt DateTime @updatedAt @map("updated_at")
@@map("trace_code_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")
tokenId BigInt? @map("token_id")
contractAddress String? @map("contract_address")
submittedAt DateTime? @map("submitted_at")
onchainAt DateTime? @map("onchain_at")
status ProofStatus @default(PENDING)
onchainChunkId String? @map("onchain_chunk_id")
failureReason String? @map("failure_reason") @db.Text
lastSyncedAt DateTime? @map("last_synced_at")
rawResponse Json? @map("raw_response")
// Consumer-requested V3 certificate; separate from the NFT mint transaction.
certificateState String @default("NONE") @map("certificate_state") @db.VarChar(20)
certificateRequest Json? @map("certificate_request")
certificateUrl String? @map("certificate_url") @db.Text
certificateError String? @map("certificate_error") @db.Text
certificateAttempts Int @default(0) @map("certificate_attempts")
certificateNextCheck DateTime? @map("certificate_next_check")
certificateLeaseUntil DateTime? @map("certificate_lease_until")
certificateLeaseToken String? @map("certificate_lease_token") @db.VarChar(36)
certificateRequestedAt DateTime? @map("certificate_requested_at")
certificateGeneratedAt DateTime? @map("certificate_generated_at")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
traceCode TraceCode @relation(fields: [traceCodeId], references: [id], onDelete: Restrict)
onchainChunk OnchainChunk? @relation(fields: [onchainChunkId], references: [id], onDelete: SetNull)
jobItems JobItem[]
@@unique([traceCodeId])
@@index([certificateState, certificateNextCheck])
@@index([status])
@@index([onchainChunkId])
@@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")
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? @map("user_agent") @db.Text
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")
items JobItem[]
onchainChunks OnchainChunk[]
@@index([type])
@@index([status])
@@map("job")
}
model JobItem {
id BigInt @id @default(autoincrement())
jobId String @map("job_id")
traceCodeId BigInt? @map("trace_code_id")
selectionKey String @map("selection_key")
proofId Int? @map("proof_id")
chunkId String? @map("chunk_id")
sequence Int @default(0)
shortCode String @map("short_code")
status JobItemStatus @default(PENDING)
payload Json?
result Json?
error String? @db.Text
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
job Job @relation(fields: [jobId], references: [id], onDelete: Cascade)
traceCode TraceCode? @relation(fields: [traceCodeId], references: [id], onDelete: Restrict)
proof BlockchainProof? @relation(fields: [proofId], references: [id], onDelete: SetNull)
chunk OnchainChunk? @relation(fields: [chunkId], references: [id], onDelete: SetNull)
@@unique([jobId, selectionKey])
@@index([jobId, status])
@@index([chunkId, status])
@@index([traceCodeId])
@@index([proofId])
@@map("job_item")
}
model OnchainChunk {
id String @id @default(cuid())
jobId String @map("job_id")
artworkId Int @map("artwork_id")
sequenceNo Int @map("sequence_no")
status OnchainChunkStatus @default(PENDING)
operateId String @unique @map("operate_id") @db.VarChar(20)
runToken String? @map("run_token")
productIds Json @map("product_ids")
metadataSnapshot Json @map("metadata_snapshot")
requestPayload Json @map("request_payload")
response Json?
txHash String? @map("tx_hash")
contractAddress String? @map("contract_address")
baseTokenId BigInt? @map("base_token_id")
failureReason String? @map("failure_reason") @db.Text
attemptCount Int @default(0) @map("attempt_count")
submittedAt DateTime? @map("submitted_at")
unknownAt DateTime? @map("unknown_at")
confirmedAt DateTime? @map("confirmed_at")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
job Job @relation(fields: [jobId], references: [id], onDelete: Cascade)
artwork Artwork @relation(fields: [artworkId], references: [id], onDelete: Restrict)
proofs BlockchainProof[]
items JobItem[]
@@unique([jobId, sequenceNo])
@@index([status])
@@index([status, updatedAt])
@@index([artworkId])
@@map("onchain_chunk")
}
model OutboundRecord {
id BigInt @id @default(autoincrement())
traceCodeId BigInt @unique @map("trace_code_id")
outTime DateTime @map("out_time")
remark String? @db.Text
createdBy Int? @map("created_by")
updatedBy Int? @map("updated_by")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
traceCode TraceCode @relation(fields: [traceCodeId], references: [id], onDelete: Restrict)
creator SysUser? @relation("OutboundRecordCreator", fields: [createdBy], references: [id], onDelete: SetNull)
updater SysUser? @relation("OutboundRecordUpdater", fields: [updatedBy], references: [id], onDelete: SetNull)
images OutboundImage[]
@@index([outTime])
@@map("outbound_record")
}
model OutboundImage {
id BigInt @id @default(autoincrement())
outboundRecordId BigInt @map("outbound_record_id")
fileKey String @unique @map("file_key") @db.VarChar(512)
fileName String @map("file_name")
mimeType String @map("mime_type")
size BigInt
width Int
height Int
sortOrder Int @default(0) @map("sort_order")
createdBy Int? @map("created_by")
createdAt DateTime @default(now()) @map("created_at")
outboundRecord OutboundRecord @relation(fields: [outboundRecordId], references: [id], onDelete: Cascade)
uploader SysUser? @relation("OutboundImageUploader", fields: [createdBy], references: [id], onDelete: SetNull)
@@index([outboundRecordId, sortOrder])
@@map("outbound_image")
}
model OperationLog {
id BigInt @id @default(autoincrement())
userId Int? @map("user_id")
username String?
role RoleType?
module String
action String
method String
path String @db.VarChar(512)
targetId String? @map("target_id")
status String
message String? @db.Text
ip String?
userAgent String? @map("user_agent") @db.Text
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") @db.VarChar(512)
requestId String? @unique @map("request_id")
previewJobId String? @unique @map("preview_job_id")
importJobId String? @unique @map("import_job_id")
importRunToken String? @map("import_run_token")
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")
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") @db.VarChar(1024)
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")
}