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"
|
||||
Reference in New Issue
Block a user