text: CREATE EXTENSION IF NOT EXISTS pgcrypto;
  
  -- CreateEnum
  CREATE TYPE "Role" AS ENUM ('USER', 'ADMIN');
  
  -- CreateTable
  CREATE TABLE "Account" (
      "id" TEXT NOT NULL,
      "userId" TEXT NOT NULL,
      "type" TEXT NOT NULL,
      "provider" TEXT NOT NULL,
      "providerAccountId" TEXT NOT NULL,
      "refresh_token" TEXT,
      "access_token" TEXT,
      "expires_at" INTEGER,
      "token_type" TEXT,
      "scope" TEXT,
      "id_token" TEXT,
      "session_state" TEXT,
      "oauth_token_secret" TEXT,
      "oauth_token" TEXT,
  
      CONSTRAINT "Account_pkey" PRIMARY KEY ("id")
  );
  
  -- CreateTable
  CREATE TABLE "Session" (
      "id" TEXT NOT NULL,
      "sessionToken" TEXT NOT NULL,
      "userId" TEXT NOT NULL,
      "expires" TIMESTAMP(3) NOT NULL,
  
      CONSTRAINT "Session_pkey" PRIMARY KEY ("id")
  );
  
  -- CreateTable
  CREATE TABLE "User" (
      "id" TEXT NOT NULL,
      "name" TEXT,
      "username" TEXT DEFAULT CONCAT('User',SUBSTRING((gen_random_uuid()::TEXT),1,4)),
      "email" TEXT,
      "emailVerified" TIMESTAMP(3),
      "image" TEXT NOT NULL DEFAULT E'https://s.gravatar.com/avatar/d59b5e94d8190c84c1efe5d9863743ae?s=200',
      "enabled" BOOLEAN NOT NULL DEFAULT true,
      "role" "Role" NOT NULL DEFAULT E'USER',
  
      CONSTRAINT "User_pkey" PRIMARY KEY ("id")
  );
  
  -- CreateTable
  CREATE TABLE "VerificationToken" (
      "identifier" TEXT NOT NULL,
      "token" TEXT NOT NULL,
      "expires" TIMESTAMP(3) NOT NULL
  );
  
  -- CreateTable
  CREATE TABLE "category" (
      "id" SERIAL NOT NULL,
      "name" TEXT NOT NULL,
      "description" TEXT NOT NULL,
  
      CONSTRAINT "category_pkey" PRIMARY KEY ("id")
  );
  
  -- CreateTable
  CREATE TABLE "ctfList" (
      "id" SERIAL NOT NULL,
      "name" TEXT NOT NULL,
      "description" TEXT NOT NULL,
  
      CONSTRAINT "ctfList_pkey" PRIMARY KEY ("id")
  );
  
  -- CreateTable
  CREATE TABLE "challenges" (
      "id" SERIAL NOT NULL,
      "title" VARCHAR(255) NOT NULL,
      "hash" VARCHAR(300) NOT NULL,
      "categoryId" INTEGER NOT NULL,
      "ctfNameId" INTEGER NOT NULL,
      "description" TEXT NOT NULL,
      "service" BOOLEAN NOT NULL,
      "exposed" BOOLEAN NOT NULL DEFAULT true,
      "flag" TEXT NOT NULL,
      "case_insensitive" BOOLEAN NOT NULL DEFAULT true,
      "minPoints" INTEGER NOT NULL,
      "initialPoints" INTEGER NOT NULL,
      "points" INTEGER NOT NULL,
      "dynamicScoring" BOOLEAN NOT NULL,
      "solves" INTEGER NOT NULL DEFAULT 0,
      "min_seconds_btwn_submissions" SMALLINT NOT NULL DEFAULT 5,
  
      CONSTRAINT "challenges_pkey" PRIMARY KEY ("id")
  );
  
  -- CreateTable
  CREATE TABLE "hints" (
      "id" SERIAL NOT NULL,
      "challengeId" INTEGER NOT NULL,
      "body" TEXT NOT NULL,
  
      CONSTRAINT "hints_pkey" PRIMARY KEY ("id")
  );
  
  -- CreateTable
  CREATE TABLE "files" (
      "id" SERIAL NOT NULL,
      "challengeId" INTEGER NOT NULL,
      "title" VARCHAR(255) NOT NULL,
      "url" TEXT NOT NULL,
  
      CONSTRAINT "files_pkey" PRIMARY KEY ("id")
  );
  
  -- CreateTable
  CREATE TABLE "submissions" (
      "id" SERIAL NOT NULL,
      "added" TIMESTAMP(3) NOT NULL,
      "challengeId" INTEGER NOT NULL,
      "userId" TEXT NOT NULL,
      "flag" TEXT NOT NULL,
      "correct" BOOLEAN NOT NULL DEFAULT false,
  
      CONSTRAINT "submissions_pkey" PRIMARY KEY ("id")
  );
  
  -- CreateTable
  CREATE TABLE "email_whitelist" (
      "id" SERIAL NOT NULL,
      "email" TEXT NOT NULL,
  
      CONSTRAINT "email_whitelist_pkey" PRIMARY KEY ("id")
  );
  
  -- CreateTable
  CREATE TABLE "exceptions" (
      "id" SERIAL NOT NULL,
      "added" TIMESTAMP(3) NOT NULL,
      "message" TEXT NOT NULL,
      "code" VARCHAR(255) NOT NULL,
      "trace" TEXT NOT NULL,
  
      CONSTRAINT "exceptions_pkey" PRIMARY KEY ("id")
  );
  
  -- CreateIndex
  CREATE UNIQUE INDEX "Account_provider_providerAccountId_key" ON "Account"("provider", "providerAccountId");
  
  -- CreateIndex
  CREATE UNIQUE INDEX "Session_sessionToken_key" ON "Session"("sessionToken");
  
  -- CreateIndex
  CREATE UNIQUE INDEX "User_username_key" ON "User"("username");
  
  -- CreateIndex
  CREATE UNIQUE INDEX "User_email_key" ON "User"("email");
  
  -- CreateIndex
  CREATE UNIQUE INDEX "VerificationToken_token_key" ON "VerificationToken"("token");
  
  -- CreateIndex
  CREATE UNIQUE INDEX "VerificationToken_identifier_token_key" ON "VerificationToken"("identifier", "token");
  
  -- CreateIndex
  CREATE UNIQUE INDEX "category_name_key" ON "category"("name");
  
  -- CreateIndex
  CREATE UNIQUE INDEX "ctfList_name_key" ON "ctfList"("name");
  
  -- CreateIndex
  CREATE UNIQUE INDEX "email_whitelist_email_key" ON "email_whitelist"("email");
  
  -- AddForeignKey
  ALTER TABLE "Account" ADD CONSTRAINT "Account_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
  
  -- AddForeignKey
  ALTER TABLE "Session" ADD CONSTRAINT "Session_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
  
  -- AddForeignKey
  ALTER TABLE "challenges" ADD CONSTRAINT "challenges_categoryId_fkey" FOREIGN KEY ("categoryId") REFERENCES "category"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
  
  -- AddForeignKey
  ALTER TABLE "challenges" ADD CONSTRAINT "challenges_ctfNameId_fkey" FOREIGN KEY ("ctfNameId") REFERENCES "ctfList"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
  
  -- AddForeignKey
  ALTER TABLE "hints" ADD CONSTRAINT "hints_challengeId_fkey" FOREIGN KEY ("challengeId") REFERENCES "challenges"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
  
  -- AddForeignKey
  ALTER TABLE "files" ADD CONSTRAINT "files_challengeId_fkey" FOREIGN KEY ("challengeId") REFERENCES "challenges"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
  