From 5cdd06a5bde4a3b36450930f5e1cec4a2b570916 Mon Sep 17 00:00:00 2001 From: GitBluub Date: Mon, 26 Sep 2022 23:33:31 +0900 Subject: [PATCH] fix: prisma migrations --- .../migrations/20220924080202_/migration.sql | 26 ------------- .../migrations/20220924081654_/migration.sql | 28 -------------- .../migrations/20220926065731_/migration.sql | 10 ----- .../migrations/20220926080922_/migration.sql | 8 ---- .../migrations/20220926082047_/migration.sql | 8 ---- .../migrations/20220926084154_/migration.sql | 8 ---- .../migration.sql | 37 ++++++++++++++++--- 7 files changed, 32 insertions(+), 93 deletions(-) delete mode 100644 back/prisma/migrations/20220924080202_/migration.sql delete mode 100644 back/prisma/migrations/20220924081654_/migration.sql delete mode 100644 back/prisma/migrations/20220926065731_/migration.sql delete mode 100644 back/prisma/migrations/20220926080922_/migration.sql delete mode 100644 back/prisma/migrations/20220926082047_/migration.sql delete mode 100644 back/prisma/migrations/20220926084154_/migration.sql rename back/prisma/migrations/{20220924084638_ => 20220926143147_}/migration.sql (53%) diff --git a/back/prisma/migrations/20220924080202_/migration.sql b/back/prisma/migrations/20220924080202_/migration.sql deleted file mode 100644 index c51015f..0000000 --- a/back/prisma/migrations/20220924080202_/migration.sql +++ /dev/null @@ -1,26 +0,0 @@ --- CreateEnum -CREATE TYPE "DifficultyPoint" AS ENUM ('TwoHands', 'Rhythm', 'NoteCombo', 'Arpeggio', 'Distance', 'LeftHand', 'RightHand', 'LeadHandChange', 'ChordComplexity', 'ChordTiming', 'Length', 'PedalPoint', 'Precision'); - --- CreateTable -CREATE TABLE "User" ( - "id" SERIAL NOT NULL, - "username" TEXT NOT NULL, - "password" TEXT NOT NULL, - "email" TEXT NOT NULL, - - CONSTRAINT "User_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "Lesson" ( - "id" SERIAL NOT NULL, - "title" TEXT NOT NULL, - "description" TEXT NOT NULL, - "requiredLvl" INTEGER NOT NULL, - "difficulyPoint" "DifficultyPoint" NOT NULL, - - CONSTRAINT "Lesson_pkey" PRIMARY KEY ("id") -); - --- CreateIndex -CREATE UNIQUE INDEX "User_username_key" ON "User"("username"); diff --git a/back/prisma/migrations/20220924081654_/migration.sql b/back/prisma/migrations/20220924081654_/migration.sql deleted file mode 100644 index 0bc5d2e..0000000 --- a/back/prisma/migrations/20220924081654_/migration.sql +++ /dev/null @@ -1,28 +0,0 @@ -/* - Warnings: - - - You are about to drop the column `difficulyPoint` on the `Lesson` table. All the data in the column will be lost. - - You are about to drop the column `requiredLvl` on the `Lesson` table. All the data in the column will be lost. - - Added the required column `mainSkill` to the `Lesson` table without a default value. This is not possible if the table is not empty. - - Added the required column `requiredLevel` to the `Lesson` table without a default value. This is not possible if the table is not empty. - -*/ --- AlterTable -ALTER TABLE "Lesson" DROP COLUMN "difficulyPoint", -DROP COLUMN "requiredLvl", -ADD COLUMN "mainSkill" "DifficultyPoint" NOT NULL, -ADD COLUMN "requiredLevel" INTEGER NOT NULL; - --- CreateTable -CREATE TABLE "LessonHistory" ( - "lessonID" INTEGER NOT NULL, - "userID" INTEGER NOT NULL, - - CONSTRAINT "LessonHistory_pkey" PRIMARY KEY ("lessonID","userID") -); - --- AddForeignKey -ALTER TABLE "LessonHistory" ADD CONSTRAINT "LessonHistory_userID_fkey" FOREIGN KEY ("userID") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "LessonHistory" ADD CONSTRAINT "LessonHistory_lessonID_fkey" FOREIGN KEY ("lessonID") REFERENCES "Lesson"("id") ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/back/prisma/migrations/20220926065731_/migration.sql b/back/prisma/migrations/20220926065731_/migration.sql deleted file mode 100644 index 5d85f48..0000000 --- a/back/prisma/migrations/20220926065731_/migration.sql +++ /dev/null @@ -1,10 +0,0 @@ -/* - Warnings: - - - You are about to drop the column `title` on the `Lesson` table. All the data in the column will be lost. - - Added the required column `name` to the `Lesson` table without a default value. This is not possible if the table is not empty. - -*/ --- AlterTable -ALTER TABLE "Lesson" DROP COLUMN "title", -ADD COLUMN "name" TEXT NOT NULL; diff --git a/back/prisma/migrations/20220926080922_/migration.sql b/back/prisma/migrations/20220926080922_/migration.sql deleted file mode 100644 index 41fdc96..0000000 --- a/back/prisma/migrations/20220926080922_/migration.sql +++ /dev/null @@ -1,8 +0,0 @@ --- DropForeignKey -ALTER TABLE "Song" DROP CONSTRAINT "Song_genreId_fkey"; - --- AlterTable -ALTER TABLE "Song" ALTER COLUMN "genreId" DROP NOT NULL; - --- AddForeignKey -ALTER TABLE "Song" ADD CONSTRAINT "Song_genreId_fkey" FOREIGN KEY ("genreId") REFERENCES "Genre"("id") ON DELETE SET NULL ON UPDATE CASCADE; diff --git a/back/prisma/migrations/20220926082047_/migration.sql b/back/prisma/migrations/20220926082047_/migration.sql deleted file mode 100644 index 6bb82d6..0000000 --- a/back/prisma/migrations/20220926082047_/migration.sql +++ /dev/null @@ -1,8 +0,0 @@ --- DropForeignKey -ALTER TABLE "Song" DROP CONSTRAINT "Song_artistId_fkey"; - --- AlterTable -ALTER TABLE "Song" ALTER COLUMN "artistId" DROP NOT NULL; - --- AddForeignKey -ALTER TABLE "Song" ADD CONSTRAINT "Song_artistId_fkey" FOREIGN KEY ("artistId") REFERENCES "Artist"("id") ON DELETE SET NULL ON UPDATE CASCADE; diff --git a/back/prisma/migrations/20220926084154_/migration.sql b/back/prisma/migrations/20220926084154_/migration.sql deleted file mode 100644 index 21b258d..0000000 --- a/back/prisma/migrations/20220926084154_/migration.sql +++ /dev/null @@ -1,8 +0,0 @@ -/* - Warnings: - - - You are about to drop the column `description` on the `Song` table. All the data in the column will be lost. - -*/ --- AlterTable -ALTER TABLE "Song" DROP COLUMN "description"; diff --git a/back/prisma/migrations/20220924084638_/migration.sql b/back/prisma/migrations/20220926143147_/migration.sql similarity index 53% rename from back/prisma/migrations/20220924084638_/migration.sql rename to back/prisma/migrations/20220926143147_/migration.sql index 07bf1b5..2e548f1 100644 --- a/back/prisma/migrations/20220924084638_/migration.sql +++ b/back/prisma/migrations/20220926143147_/migration.sql @@ -1,3 +1,6 @@ +-- CreateEnum +CREATE TYPE "DifficultyPoint" AS ENUM ('TwoHands', 'Rhythm', 'NoteCombo', 'Arpeggio', 'Distance', 'LeftHand', 'RightHand', 'LeadHandChange', 'ChordComplexity', 'ChordTiming', 'Length', 'PedalPoint', 'Precision'); + -- CreateTable CREATE TABLE "User" ( "id" SERIAL NOT NULL, @@ -12,10 +15,9 @@ CREATE TABLE "User" ( CREATE TABLE "Song" ( "id" SERIAL NOT NULL, "name" TEXT NOT NULL, - "description" TEXT NOT NULL, - "artistId" INTEGER NOT NULL, + "artistId" INTEGER, "albumId" INTEGER, - "genreId" INTEGER NOT NULL, + "genreId" INTEGER, "difficulties" JSONB NOT NULL, CONSTRAINT "Song_pkey" PRIMARY KEY ("id") @@ -45,6 +47,25 @@ CREATE TABLE "Album" ( CONSTRAINT "Album_pkey" PRIMARY KEY ("id") ); +-- CreateTable +CREATE TABLE "Lesson" ( + "id" SERIAL NOT NULL, + "name" TEXT NOT NULL, + "description" TEXT NOT NULL, + "requiredLevel" INTEGER NOT NULL, + "mainSkill" "DifficultyPoint" NOT NULL, + + CONSTRAINT "Lesson_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "LessonHistory" ( + "lessonID" INTEGER NOT NULL, + "userID" INTEGER NOT NULL, + + CONSTRAINT "LessonHistory_pkey" PRIMARY KEY ("lessonID","userID") +); + -- CreateIndex CREATE UNIQUE INDEX "User_username_key" ON "User"("username"); @@ -52,10 +73,16 @@ CREATE UNIQUE INDEX "User_username_key" ON "User"("username"); CREATE UNIQUE INDEX "Song_name_key" ON "Song"("name"); -- AddForeignKey -ALTER TABLE "Song" ADD CONSTRAINT "Song_genreId_fkey" FOREIGN KEY ("genreId") REFERENCES "Genre"("id") ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE "Song" ADD CONSTRAINT "Song_genreId_fkey" FOREIGN KEY ("genreId") REFERENCES "Genre"("id") ON DELETE SET NULL ON UPDATE CASCADE; -- AddForeignKey -ALTER TABLE "Song" ADD CONSTRAINT "Song_artistId_fkey" FOREIGN KEY ("artistId") REFERENCES "Artist"("id") ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE "Song" ADD CONSTRAINT "Song_artistId_fkey" FOREIGN KEY ("artistId") REFERENCES "Artist"("id") ON DELETE SET NULL ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "Song" ADD CONSTRAINT "Song_albumId_fkey" FOREIGN KEY ("albumId") REFERENCES "Album"("id") ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "LessonHistory" ADD CONSTRAINT "LessonHistory_userID_fkey" FOREIGN KEY ("userID") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "LessonHistory" ADD CONSTRAINT "LessonHistory_lessonID_fkey" FOREIGN KEY ("lessonID") REFERENCES "Lesson"("id") ON DELETE RESTRICT ON UPDATE CASCADE;