Add PdfApiKey model and key storage helpers

Adds a Prisma model for per-student Clean PDF API keys plus a
hand-written migration (no local Postgres to run `migrate dev`
against). getOrCreatePdfKey/regenerateKey wrap the model with
lazy-creation and rotation logic on top of generatePdfKey().
This commit is contained in:
2026-07-06 11:53:31 +05:00
parent 1d5b4f9251
commit b49680c118
3 changed files with 48 additions and 0 deletions
+11
View File
@@ -47,6 +47,7 @@ model User {
questionMessages StudentQuestionMessage[]
wrappedRuns WrappedRun[]
toolUsages ToolUsage[]
pdfApiKey PdfApiKey?
}
// Obsidian Wrapped — агрегаты прогона (БЕЗ имён/текстов заметок; обработка волта 100% client-side)
@@ -82,6 +83,16 @@ model ToolUsage {
@@index([createdAt])
}
// Чистый PDF — персональный API-ключ студента (Zotero/curl)
model PdfApiKey {
id String @id @default(cuid())
userId String @unique
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
key String @unique // sbpdf_<random>, показывается студенту на /tools/clean-pdf
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model Session {
id String @id @default(cuid())
userId String