-- AlterEnum
ALTER TYPE "LedgerType" ADD VALUE 'DEBIT_MISSION_SPEND';

-- CreateTable
CREATE TABLE "MissionSpend" (
    "id" TEXT NOT NULL,
    "userId" TEXT NOT NULL,
    "missionSlug" TEXT NOT NULL,
    "missionTitle" TEXT NOT NULL,
    "creditsSpent" INTEGER NOT NULL,
    "supporterNote" TEXT,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateIndex
CREATE INDEX "MissionSpend_userId_idx" ON "MissionSpend"("userId");

-- CreateIndex
CREATE INDEX "MissionSpend_missionSlug_idx" ON "MissionSpend"("missionSlug");

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

-- AlterTable
ALTER TABLE "LedgerEntry" ADD COLUMN "missionSpendId" TEXT;

-- CreateIndex
CREATE UNIQUE INDEX "LedgerEntry_missionSpendId_key" ON "LedgerEntry"("missionSpendId");

-- AddForeignKey
ALTER TABLE "LedgerEntry" ADD CONSTRAINT "LedgerEntry_missionSpendId_fkey" FOREIGN KEY ("missionSpendId") REFERENCES "MissionSpend"("id") ON DELETE SET NULL ON UPDATE CASCADE;
