-- CreateTable
CREATE TABLE "User" (
    "id" TEXT NOT NULL,
    "patreonId" TEXT NOT NULL,
    "patreonFullName" TEXT,
    "imageUrl" TEXT NOT NULL,

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

-- CreateTable
CREATE TABLE "RateLimiterFlexible" (
    "key" TEXT NOT NULL,
    "points" INTEGER NOT NULL,
    "expire" TIMESTAMP(3),

    CONSTRAINT "RateLimiterFlexible_pkey" PRIMARY KEY ("key")
);

-- CreateTable
CREATE TABLE "stream_entity" (
    "id" TEXT NOT NULL,
    "date" TIMESTAMP(3) NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,
    "announcementUrl" VARCHAR(2048),

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

-- CreateTable
CREATE TABLE "Vod" (
    "id" TEXT NOT NULL,
    "streamId" TEXT NOT NULL,

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

-- CreateTable
CREATE TABLE "Upload" (
    "id" TEXT NOT NULL,
    "userId" TEXT NOT NULL,
    "vodId" TEXT,
    "fileKeys" TEXT[],
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "Vtuber" (
    "id" TEXT NOT NULL,
    "image" TEXT,
    "slug" TEXT,
    "displayName" TEXT,
    "chaturbate" TEXT,
    "twitter" TEXT,
    "patreon" TEXT,
    "twitch" TEXT,
    "tiktok" TEXT,
    "onlyfans" TEXT,
    "youtube" TEXT,
    "linktree" TEXT,
    "carrd" TEXT,
    "fansly" TEXT,
    "pornhub" TEXT,
    "discord" TEXT,
    "reddit" TEXT,
    "throne" TEXT,
    "instagram" TEXT,
    "facebook" TEXT,
    "merch" TEXT,
    "description" TEXT,
    "themeColor" TEXT,
    "fanslyId" TEXT,
    "chaturbateId" TEXT,
    "twitterId" TEXT,

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

-- CreateTable
CREATE TABLE "_VodToVtuber" (
    "A" TEXT NOT NULL,
    "B" TEXT NOT NULL,

    CONSTRAINT "_VodToVtuber_AB_pkey" PRIMARY KEY ("A","B")
);

-- CreateIndex
CREATE UNIQUE INDEX "User_patreonId_key" ON "User"("patreonId");

-- CreateIndex
CREATE UNIQUE INDEX "Upload_vodId_key" ON "Upload"("vodId");

-- CreateIndex
CREATE INDEX "_VodToVtuber_B_index" ON "_VodToVtuber"("B");

-- AddForeignKey
ALTER TABLE "Vod" ADD CONSTRAINT "Vod_streamId_fkey" FOREIGN KEY ("streamId") REFERENCES "stream_entity"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

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

-- AddForeignKey
ALTER TABLE "Upload" ADD CONSTRAINT "Upload_vodId_fkey" FOREIGN KEY ("vodId") REFERENCES "Vod"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "_VodToVtuber" ADD CONSTRAINT "_VodToVtuber_A_fkey" FOREIGN KEY ("A") REFERENCES "Vod"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "_VodToVtuber" ADD CONSTRAINT "_VodToVtuber_B_fkey" FOREIGN KEY ("B") REFERENCES "Vtuber"("id") ON DELETE CASCADE ON UPDATE CASCADE;
