feat: add Request and Job schema with migration
Adds the Prisma schema (Request/Job models, RequestStatus/JobState enums), a Prisma client singleton at web/src/lib/db.ts, and the init_request_job migration, applied and verified against Postgres. Also publishes the db service's port (5432:5432) in docker-compose.yml so host-run Prisma commands can reach localhost:5432 for local dev.
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
-- CreateEnum
|
||||
CREATE TYPE "RequestStatus" AS ENUM ('pending', 'completed', 'needs_attention');
|
||||
|
||||
-- CreateEnum
|
||||
CREATE TYPE "JobState" AS ENUM ('requested', 'matching', 'matched', 'downloading', 'tagging', 'imported', 'needs_attention');
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "Request" (
|
||||
"id" TEXT NOT NULL,
|
||||
"artist" TEXT NOT NULL,
|
||||
"album" TEXT NOT NULL,
|
||||
"status" "RequestStatus" NOT NULL DEFAULT 'pending',
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
CONSTRAINT "Request_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "Job" (
|
||||
"id" TEXT NOT NULL,
|
||||
"requestId" TEXT NOT NULL,
|
||||
"state" "JobState" NOT NULL DEFAULT 'requested',
|
||||
"currentStage" TEXT NOT NULL DEFAULT 'intake',
|
||||
"attempts" INTEGER NOT NULL DEFAULT 0,
|
||||
"error" TEXT,
|
||||
"claimedAt" TIMESTAMP(3),
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" TIMESTAMP(3) NOT NULL,
|
||||
|
||||
CONSTRAINT "Job_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "Job_requestId_key" ON "Job"("requestId");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Job" ADD CONSTRAINT "Job_requestId_fkey" FOREIGN KEY ("requestId") REFERENCES "Request"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
@@ -0,0 +1,3 @@
|
||||
# Please do not edit this file manually
|
||||
# It should be added in your version-control system (e.g., Git)
|
||||
provider = "postgresql"
|
||||
@@ -0,0 +1,46 @@
|
||||
generator client {
|
||||
provider = "prisma-client-js"
|
||||
}
|
||||
|
||||
datasource db {
|
||||
provider = "postgresql"
|
||||
url = env("DATABASE_URL")
|
||||
}
|
||||
|
||||
enum RequestStatus {
|
||||
pending
|
||||
completed
|
||||
needs_attention
|
||||
}
|
||||
|
||||
enum JobState {
|
||||
requested
|
||||
matching
|
||||
matched
|
||||
downloading
|
||||
tagging
|
||||
imported
|
||||
needs_attention
|
||||
}
|
||||
|
||||
model Request {
|
||||
id String @id @default(cuid())
|
||||
artist String
|
||||
album String
|
||||
status RequestStatus @default(pending)
|
||||
createdAt DateTime @default(now())
|
||||
job Job?
|
||||
}
|
||||
|
||||
model Job {
|
||||
id String @id @default(cuid())
|
||||
request Request @relation(fields: [requestId], references: [id], onDelete: Cascade)
|
||||
requestId String @unique
|
||||
state JobState @default(requested)
|
||||
currentStage String @default("intake")
|
||||
attempts Int @default(0)
|
||||
error String?
|
||||
claimedAt DateTime?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
}
|
||||
Reference in New Issue
Block a user