feat: add Candidate and LibraryItem schema

Adds Candidate (per-job download candidates found by the pipeline)
and LibraryItem (per-request imported album, deduped on
artist+album) tables. LibraryItem.requestId is @unique since
Request.libraryItem is a one-to-one back-relation (required for
Prisma validation, matching the existing Job.requestId pattern).
This commit is contained in:
Jonathan
2026-07-10 18:40:41 +02:00
parent 991365e746
commit 60f3cd0df9
2 changed files with 86 additions and 13 deletions
@@ -0,0 +1,42 @@
-- CreateTable
CREATE TABLE "Candidate" (
"id" TEXT NOT NULL,
"jobId" TEXT NOT NULL,
"source" TEXT NOT NULL,
"format" TEXT NOT NULL,
"qualityClass" INTEGER NOT NULL,
"trackCount" INTEGER NOT NULL,
"confidence" DOUBLE PRECISION NOT NULL,
"sourceRef" TEXT NOT NULL,
"chosen" BOOLEAN NOT NULL DEFAULT false,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "Candidate_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "LibraryItem" (
"id" TEXT NOT NULL,
"requestId" TEXT NOT NULL,
"artist" TEXT NOT NULL,
"album" TEXT NOT NULL,
"path" TEXT NOT NULL,
"source" TEXT NOT NULL,
"format" TEXT NOT NULL,
"qualityClass" INTEGER NOT NULL,
"importedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "LibraryItem_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE UNIQUE INDEX "LibraryItem_requestId_key" ON "LibraryItem"("requestId");
-- CreateIndex
CREATE UNIQUE INDEX "LibraryItem_artist_album_key" ON "LibraryItem"("artist", "album");
-- AddForeignKey
ALTER TABLE "Candidate" ADD CONSTRAINT "Candidate_jobId_fkey" FOREIGN KEY ("jobId") REFERENCES "Job"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "LibraryItem" ADD CONSTRAINT "LibraryItem_requestId_fkey" FOREIGN KEY ("requestId") REFERENCES "Request"("id") ON DELETE CASCADE ON UPDATE CASCADE;
+31
View File
@@ -30,6 +30,7 @@ model Request {
status RequestStatus @default(pending)
createdAt DateTime @default(now())
job Job?
libraryItem LibraryItem?
}
model Job {
@@ -43,4 +44,34 @@ model Job {
claimedAt DateTime?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
candidates Candidate[]
}
model Candidate {
id String @id @default(cuid())
job Job @relation(fields: [jobId], references: [id], onDelete: Cascade)
jobId String
source String
format String
qualityClass Int
trackCount Int
confidence Float
sourceRef String
chosen Boolean @default(false)
createdAt DateTime @default(now())
}
model LibraryItem {
id String @id @default(cuid())
request Request @relation(fields: [requestId], references: [id], onDelete: Cascade)
requestId String @unique
artist String
album String
path String
source String
format String
qualityClass Int
importedAt DateTime @default(now())
@@unique([artist, album])
}