From a5b5584e1c3509a9051d8b2f4677721b6358e960 Mon Sep 17 00:00:00 2001 From: cfngc4594 Date: Tue, 11 Mar 2025 15:53:43 +0800 Subject: [PATCH] feat(prisma): add initial migration --- .../20250311071446_init/migration.sql | 53 +++++++++++++++++++ prisma/migrations/migration_lock.toml | 3 ++ 2 files changed, 56 insertions(+) create mode 100644 prisma/migrations/20250311071446_init/migration.sql create mode 100644 prisma/migrations/migration_lock.toml diff --git a/prisma/migrations/20250311071446_init/migration.sql b/prisma/migrations/20250311071446_init/migration.sql new file mode 100644 index 0000000..ae059d1 --- /dev/null +++ b/prisma/migrations/20250311071446_init/migration.sql @@ -0,0 +1,53 @@ +-- CreateEnum +CREATE TYPE "Role" AS ENUM ('ADMIN', 'TEACHER', 'STUDENT', 'GUEST'); + +-- CreateEnum +CREATE TYPE "Difficulty" AS ENUM ('EASY', 'MEDIUM', 'HARD'); + +-- CreateEnum +CREATE TYPE "EditorLanguage" AS ENUM ('c', 'cpp'); + +-- CreateTable +CREATE TABLE "User" ( + "id" SERIAL NOT NULL, + "name" TEXT NOT NULL, + "email" TEXT NOT NULL, + "role" "Role" NOT NULL DEFAULT 'GUEST', + + CONSTRAINT "User_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "Problem" ( + "id" SERIAL NOT NULL, + "title" TEXT NOT NULL, + "description" TEXT NOT NULL, + "solution" TEXT NOT NULL, + "difficulty" "Difficulty" NOT NULL DEFAULT 'EASY', + "published" BOOLEAN NOT NULL DEFAULT false, + "authorId" INTEGER NOT NULL, + + CONSTRAINT "Problem_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "Template" ( + "id" SERIAL NOT NULL, + "language" "EditorLanguage" NOT NULL, + "template" TEXT NOT NULL, + "problemId" INTEGER NOT NULL, + + CONSTRAINT "Template_pkey" PRIMARY KEY ("id") +); + +-- CreateIndex +CREATE UNIQUE INDEX "User_name_key" ON "User"("name"); + +-- CreateIndex +CREATE UNIQUE INDEX "User_email_key" ON "User"("email"); + +-- AddForeignKey +ALTER TABLE "Problem" ADD CONSTRAINT "Problem_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "Template" ADD CONSTRAINT "Template_problemId_fkey" FOREIGN KEY ("problemId") REFERENCES "Problem"("id") ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/prisma/migrations/migration_lock.toml b/prisma/migrations/migration_lock.toml new file mode 100644 index 0000000..648c57f --- /dev/null +++ b/prisma/migrations/migration_lock.toml @@ -0,0 +1,3 @@ +# Please do not edit this file manually +# It should be added in your version-control system (e.g., Git) +provider = "postgresql" \ No newline at end of file