diff --git a/prisma/migrations/20250515021331_add_game_ratings/migration.sql b/prisma/migrations/20250515021331_add_game_ratings/migration.sql new file mode 100644 index 0000000..52a2f5f --- /dev/null +++ b/prisma/migrations/20250515021331_add_game_ratings/migration.sql @@ -0,0 +1,41 @@ +/* + Warnings: + + - You are about to drop the column `mReviewCount` on the `Game` table. All the data in the column will be lost. + - You are about to drop the column `mReviewRating` on the `Game` table. All the data in the column will be lost. + +*/ +-- AlterEnum +-- This migration adds more than one value to an enum. +-- With PostgreSQL versions 11 and earlier, this is not possible +-- in a single migration. This can be worked around by creating +-- multiple migrations, each migration adding only one value to +-- the enum. + + +ALTER TYPE "MetadataSource" ADD VALUE 'Metacritic'; +ALTER TYPE "MetadataSource" ADD VALUE 'OpenCritic'; + +-- AlterTable +ALTER TABLE "Game" DROP COLUMN "mReviewCount", +DROP COLUMN "mReviewRating"; + +-- CreateTable +CREATE TABLE "GameRating" ( + "id" TEXT NOT NULL, + "metadataSource" "MetadataSource" NOT NULL, + "metadataId" TEXT NOT NULL, + "created" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "mReviewCount" INTEGER NOT NULL, + "mReviewRating" DOUBLE PRECISION NOT NULL, + "mReviewHref" TEXT, + "gameId" TEXT NOT NULL, + + CONSTRAINT "GameRating_pkey" PRIMARY KEY ("id") +); + +-- CreateIndex +CREATE UNIQUE INDEX "GameRating_metadataSource_metadataId_key" ON "GameRating"("metadataSource", "metadataId"); + +-- AddForeignKey +ALTER TABLE "GameRating" ADD CONSTRAINT "GameRating_gameId_fkey" FOREIGN KEY ("gameId") REFERENCES "Game"("id") ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/prisma/models/content.prisma b/prisma/models/content.prisma index 4631b06..3ac08b1 100644 --- a/prisma/models/content.prisma +++ b/prisma/models/content.prisma @@ -55,8 +55,8 @@ model GameRating { mReviewHref String? - Game Game? @relation(fields: [gameId], references: [id], onDelete: Cascade) - gameId String? + Game Game @relation(fields: [gameId], references: [id], onDelete: Cascade) + gameId String @@unique([metadataSource, metadataId], name: "metadataKey") }