feat: 搭建 NestJS 后端基础设施与 Prisma 数据模型
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,310 @@
|
||||
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 NodeType {
|
||||
CREATE
|
||||
PRODUCE
|
||||
STORAGE
|
||||
OUTBOUND
|
||||
OTHER
|
||||
}
|
||||
|
||||
enum CertType {
|
||||
PHOTO
|
||||
CERT
|
||||
APPRAISAL
|
||||
}
|
||||
|
||||
enum BatchStatus {
|
||||
PENDING
|
||||
GENERATING
|
||||
DONE
|
||||
FAILED
|
||||
}
|
||||
|
||||
enum TraceCodeStatus {
|
||||
UNBOUND
|
||||
INACTIVE
|
||||
ACTIVE
|
||||
DISABLED
|
||||
ABNORMAL
|
||||
}
|
||||
|
||||
enum ProofStatus {
|
||||
PENDING
|
||||
ONCHAIN
|
||||
FAILED
|
||||
}
|
||||
|
||||
enum QueryResult {
|
||||
FIRST_ACTIVATE
|
||||
REPEAT
|
||||
INVALID
|
||||
DISABLED
|
||||
ABNORMAL
|
||||
}
|
||||
|
||||
enum JobType {
|
||||
GEN_CODE
|
||||
IMPORT_OUTBOUND
|
||||
WATERMARK
|
||||
ONCHAIN
|
||||
}
|
||||
|
||||
enum JobStatus {
|
||||
PENDING
|
||||
PROCESSING
|
||||
SUCCESS
|
||||
PARTIAL
|
||||
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[]
|
||||
|
||||
@@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?
|
||||
dynamicFields Json? @map("dynamic_fields")
|
||||
images Json?
|
||||
status ArtworkStatus @default(DRAFT)
|
||||
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[]
|
||||
traceCode TraceCode?
|
||||
|
||||
@@index([templateId])
|
||||
@@index([status])
|
||||
@@map("artwork")
|
||||
}
|
||||
|
||||
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 Batch {
|
||||
id Int @id @default(autoincrement())
|
||||
batchNo String @unique @map("batch_no")
|
||||
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")
|
||||
|
||||
traceCodes TraceCode[]
|
||||
|
||||
@@map("batch")
|
||||
}
|
||||
|
||||
model TraceCode {
|
||||
id BigInt @id @default(autoincrement())
|
||||
code String @unique
|
||||
shortCode String @unique @map("short_code")
|
||||
artworkId Int? @unique @map("artwork_id")
|
||||
batchId Int? @map("batch_id")
|
||||
sku String?
|
||||
archiveNo String? @map("archive_no")
|
||||
outTime DateTime? @map("out_time")
|
||||
outImage String? @map("out_image")
|
||||
remark String?
|
||||
status TraceCodeStatus @default(UNBOUND)
|
||||
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])
|
||||
proofs BlockchainProof[]
|
||||
queryLogs QueryLog[]
|
||||
|
||||
@@index([batchId])
|
||||
@@index([status])
|
||||
@@map("trace_code")
|
||||
}
|
||||
|
||||
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")
|
||||
queriedAt DateTime @default(now()) @map("queried_at")
|
||||
queryResult QueryResult @map("query_result")
|
||||
ip String?
|
||||
region String?
|
||||
userAgent String? @db.Text @map("user_agent")
|
||||
deviceType String? @map("device_type")
|
||||
|
||||
traceCode TraceCode? @relation(fields: [traceCodeId], references: [id])
|
||||
|
||||
@@index([traceCodeId])
|
||||
@@index([queriedAt])
|
||||
@@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 SystemSetting {
|
||||
id Int @id @default(autoincrement())
|
||||
key String @unique
|
||||
value String @db.Text
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
@@map("system_setting")
|
||||
}
|
||||
Reference in New Issue
Block a user