/*
  Warnings:

  - The `voteType` column on the `DealVote` table would be dropped and recreated. This will lead to data loss if there is data in the column.

*/
-- AlterTable
ALTER TABLE "DealVote" ADD COLUMN     "lastVotedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
DROP COLUMN "voteType",
ADD COLUMN     "voteType" INTEGER NOT NULL DEFAULT 0;

-- CreateTable
CREATE TABLE "DealVoteHistory" (
    "id" SERIAL NOT NULL,
    "dealId" INTEGER NOT NULL,
    "userId" INTEGER NOT NULL,
    "voteType" INTEGER NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "DealVoteHistory_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE INDEX "DealVoteHistory_dealId_idx" ON "DealVoteHistory"("dealId");

-- CreateIndex
CREATE INDEX "DealVoteHistory_userId_idx" ON "DealVoteHistory"("userId");

-- CreateIndex
CREATE INDEX "DealVoteHistory_createdAt_idx" ON "DealVoteHistory"("createdAt");

-- CreateIndex
CREATE INDEX "DealVote_dealId_idx" ON "DealVote"("dealId");

-- AddForeignKey
ALTER TABLE "DealVoteHistory" ADD CONSTRAINT "DealVoteHistory_dealId_fkey" FOREIGN KEY ("dealId") REFERENCES "Deal"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "DealVoteHistory" ADD CONSTRAINT "DealVoteHistory_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
