Files
Lyra/web/prisma/migrations/20260710144250_init_request_job/migration.sql
T
Jonathan ab4db641b0 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.
2026-07-10 16:43:22 +02:00

38 lines
1.2 KiB
SQL

-- 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;