-- CreateTable CREATE TABLE "public"."Review" ( "id" SERIAL NOT NULL, "score" SMALLINT, "review" TEXT, "internalNote" TEXT, "rankingValue" INTEGER, "showcase" BOOLEAN NOT NULL DEFAULT false, "answerId" INTEGER NOT NULL, "reviewerId" INTEGER NOT NULL, "createdAt" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, "updatedAt" TIMESTAMPTZ(3) NOT NULL, CONSTRAINT "Review_pkey" PRIMARY KEY ("id") ); -- CreateIndex CREATE UNIQUE INDEX "Review_answerId_key" ON "public"."Review" ("answerId"); -- AddForeignKey ALTER TABLE "public"."Review" ADD CONSTRAINT "Review_answerId_fkey" FOREIGN KEY ("answerId") REFERENCES "public"."QuestAnswer" ("id") ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "public"."Review" ADD CONSTRAINT "Review_reviewerId_fkey" FOREIGN KEY ("reviewerId") REFERENCES "public"."User" ("id") ON DELETE CASCADE ON UPDATE CASCADE; insert into public."Review" ("internalNote", "rankingValue", review, score, showcase, "reviewerId", "answerId", "updatedAt", "createdAt") select "internalNote", "rankingValue", review, score, showcase, "reviewerId", id, "updatedAt", "updatedAt" from "QuestAnswer" where "reviewerId" is not null; -- DropForeignKey ALTER TABLE "public"."QuestAnswer" DROP CONSTRAINT "QuestAnswer_reviewerId_fkey"; -- AlterTable ALTER TABLE "public"."QuestAnswer" DROP COLUMN "internalNote", DROP COLUMN "rankingValue", DROP COLUMN "review", DROP COLUMN "reviewerId", DROP COLUMN "score", DROP COLUMN "showcase", ADD COLUMN "final" BOOLEAN NOT NULL DEFAULT false;