-- CreateTable CREATE TABLE "User" ( "id" TEXT NOT NULL, "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, "updatedAt" TIMESTAMP(3) NOT NULL, "email" TEXT NOT NULL, "password" TEXT NOT NULL, "firstName" TEXT, "lastName" TEXT, CONSTRAINT "User_pkey" PRIMARY KEY ("id") ); -- CreateTable CREATE TABLE "RefreshToken" ( "token" TEXT NOT NULL, "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, "expiresAt" TIMESTAMP(3) NOT NULL DEFAULT NOW() + interval '3 months', "userId" TEXT NOT NULL, CONSTRAINT "RefreshToken_pkey" PRIMARY KEY ("token") ); -- CreateTable CREATE TABLE "Share" ( "id" TEXT NOT NULL, "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, "uploadLocked" BOOLEAN NOT NULL DEFAULT false, "isZipReady" BOOLEAN NOT NULL DEFAULT false, "views" INTEGER NOT NULL DEFAULT 0, "expiration" TIMESTAMP(3) NOT NULL, "creatorId" TEXT NOT NULL, CONSTRAINT "Share_pkey" PRIMARY KEY ("id") ); -- CreateTable CREATE TABLE "File" ( "id" TEXT NOT NULL, "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, "name" TEXT NOT NULL, "size" TEXT NOT NULL, "shareId" TEXT NOT NULL, CONSTRAINT "File_pkey" PRIMARY KEY ("id") ); -- CreateTable CREATE TABLE "ShareSecurity" ( "id" TEXT NOT NULL, "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, "password" TEXT, "maxViews" INTEGER, "shareId" TEXT, CONSTRAINT "ShareSecurity_pkey" PRIMARY KEY ("id") ); -- CreateIndex CREATE UNIQUE INDEX "User_email_key" ON "User"("email"); -- CreateIndex CREATE UNIQUE INDEX "ShareSecurity_shareId_key" ON "ShareSecurity"("shareId"); -- AddForeignKey ALTER TABLE "RefreshToken" ADD CONSTRAINT "RefreshToken_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "Share" ADD CONSTRAINT "Share_creatorId_fkey" FOREIGN KEY ("creatorId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "File" ADD CONSTRAINT "File_shareId_fkey" FOREIGN KEY ("shareId") REFERENCES "Share"("id") ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "ShareSecurity" ADD CONSTRAINT "ShareSecurity_shareId_fkey" FOREIGN KEY ("shareId") REFERENCES "Share"("id") ON DELETE CASCADE ON UPDATE CASCADE;