forked from mtusi2026/mtusi2026lab5
feat: accept uploads into staging with jobs, outbox and job processor
This commit is contained in:
@@ -78,17 +78,91 @@ model Attachment {
|
||||
sizeBytes Int @map("size_bytes")
|
||||
sha256 String @db.Char(64)
|
||||
objectKey String @unique @map("object_key") @db.VarChar(128)
|
||||
stagingKey String? @unique @map("staging_key") @db.VarChar(128)
|
||||
status String @db.VarChar(16)
|
||||
errorCode String? @map("error_code") @db.VarChar(64)
|
||||
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(3)
|
||||
updatedAt DateTime @default(now()) @updatedAt @map("updated_at") @db.Timestamptz(3)
|
||||
chat Chat @relation(fields: [chatId], references: [id], onDelete: Cascade)
|
||||
owner User @relation(fields: [ownerId], references: [id], onDelete: Restrict)
|
||||
messages MessageAttachment[]
|
||||
variants AttachmentVariant[]
|
||||
jobs AttachmentJob[]
|
||||
|
||||
@@index([chatId])
|
||||
@@index([ownerId])
|
||||
@@map("attachments")
|
||||
}
|
||||
|
||||
model AttachmentVariant {
|
||||
attachmentId String @map("attachment_id") @db.Uuid
|
||||
pipelineVersion Int @map("pipeline_version")
|
||||
name String @db.VarChar(16)
|
||||
contentType String @map("content_type") @db.VarChar(32)
|
||||
objectKey String @unique @map("object_key") @db.VarChar(128)
|
||||
sizeBytes Int @map("size_bytes")
|
||||
width Int
|
||||
height Int
|
||||
sha256 String @db.Char(64)
|
||||
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(3)
|
||||
attachment Attachment @relation(fields: [attachmentId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@id([attachmentId, pipelineVersion, name])
|
||||
@@map("attachment_variants")
|
||||
}
|
||||
|
||||
model AttachmentJob {
|
||||
id String @id @db.Uuid
|
||||
attachmentId String @map("attachment_id") @db.Uuid
|
||||
pipelineVersion Int @map("pipeline_version")
|
||||
status String @db.VarChar(16)
|
||||
attempt Int
|
||||
maxAttempts Int @map("max_attempts")
|
||||
nextAttemptAt DateTime @map("next_attempt_at") @db.Timestamptz(3)
|
||||
leaseOwner String? @map("lease_owner") @db.Uuid
|
||||
leaseUntil DateTime? @map("lease_until") @db.Timestamptz(3)
|
||||
errorCode String? @map("error_code") @db.VarChar(64)
|
||||
lastError String? @map("last_error") @db.VarChar(200)
|
||||
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(3)
|
||||
updatedAt DateTime @default(now()) @updatedAt @map("updated_at") @db.Timestamptz(3)
|
||||
finishedAt DateTime? @map("finished_at") @db.Timestamptz(3)
|
||||
attachment Attachment @relation(fields: [attachmentId], references: [id], onDelete: Cascade)
|
||||
events JobEvent[]
|
||||
outbox OutboxEntry[]
|
||||
|
||||
@@unique([attachmentId, pipelineVersion])
|
||||
@@index([status, leaseUntil])
|
||||
@@map("attachment_jobs")
|
||||
}
|
||||
|
||||
model JobEvent {
|
||||
id BigInt @id @default(autoincrement())
|
||||
jobId String @map("job_id") @db.Uuid
|
||||
attempt Int
|
||||
event String @db.VarChar(32)
|
||||
detail String? @db.VarChar(200)
|
||||
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(3)
|
||||
job AttachmentJob @relation(fields: [jobId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@index([jobId])
|
||||
@@map("job_events")
|
||||
}
|
||||
|
||||
model OutboxEntry {
|
||||
id BigInt @id @default(autoincrement())
|
||||
jobId String @map("job_id") @db.Uuid
|
||||
payload Json
|
||||
availableAt DateTime @default(now()) @map("available_at") @db.Timestamptz(3)
|
||||
publishedAt DateTime? @map("published_at") @db.Timestamptz(3)
|
||||
publishAttempts Int @default(0) @map("publish_attempts")
|
||||
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(3)
|
||||
job AttachmentJob @relation(fields: [jobId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@index([publishedAt, availableAt])
|
||||
@@index([jobId])
|
||||
@@map("outbox")
|
||||
}
|
||||
|
||||
model MessageAttachment {
|
||||
messageId String @map("message_id") @db.Uuid
|
||||
position Int @db.SmallInt
|
||||
|
||||
Reference in New Issue
Block a user