From 25ffda52c4b8d29f0885df818d11e371480bee42 Mon Sep 17 00:00:00 2001 From: "Kalle (Sendou)" <38327916+Sendouc@users.noreply.github.com> Date: Mon, 14 Dec 2020 17:58:46 +0200 Subject: [PATCH] add salmon run tables migration --- package.json | 6 +- .../migration.sql | 50 +++++++++++++ prisma/schema.prisma | 73 +++++++++++++++++-- 3 files changed, 118 insertions(+), 11 deletions(-) create mode 100644 prisma/migrations/20201214154513_salmon_run_tables/migration.sql diff --git a/package.json b/package.json index ac891cda1..f7236a412 100644 --- a/package.json +++ b/package.json @@ -6,9 +6,9 @@ "dev": "next dev", "build": "lingui compile && next build", "start": "next start", - "migrate": "prisma migrate dev --preview-feature", - "migrate:save": "npx prisma migrate save --name init --experimental", - "migrate:up": "npx prisma migrate up --experimental", + "migrate": "prisma migrate deploy --preview-feature", + "migrate:save": "prisma migrate dev --create-only --preview-feature", + "migrate:up": "prisma migrate dev --preview-feature", "studio": "npx prisma studio", "gen": "npx prisma generate", "seed": "ts-node prisma/seed.ts", diff --git a/prisma/migrations/20201214154513_salmon_run_tables/migration.sql b/prisma/migrations/20201214154513_salmon_run_tables/migration.sql new file mode 100644 index 000000000..c0faa41a4 --- /dev/null +++ b/prisma/migrations/20201214154513_salmon_run_tables/migration.sql @@ -0,0 +1,50 @@ +-- CreateEnum +CREATE TYPE "public"."SalmonRunRecordCategory" AS ENUM ('TOTAL', 'TOTAL_NO_NIGHT', 'PRINCESS', 'NT_NORMAL', 'HT_NORMAL', 'LT_NORMAL', 'NT_RUSH', 'HT_RUSH', 'NT_FOG', 'HT_FOG', 'LT_FOG', 'NT_GOLDIE', 'HT_GOLDIE', 'NT_GRILLERS', 'HT_GRILLERS', 'NT_MOTHERSHIP', 'HT_MOTHERSHIP', 'LT_MOTHERSHIP', 'LT_COHOCK'); + +-- CreateTable +CREATE TABLE "SalmonRunRotation" ( + "id" INTEGER NOT NULL, + "startTime" TIMESTAMP(3) NOT NULL, + "endTime" TIMESTAMP(3) NOT NULL, + "weapons" TEXT[], + "grizzcoWeapon" TEXT, + "stage" TEXT NOT NULL +); + +-- CreateTable +CREATE TABLE "SalmonRunRecord" ( +"id" SERIAL, + "rotationId" INTEGER NOT NULL, + "submitterId" INTEGER NOT NULL, + "goldenEggCount" INTEGER NOT NULL, + "approved" BOOLEAN NOT NULL, + "category" "SalmonRunRecordCategory" NOT NULL, + "links" TEXT[], + "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + + PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "SalmonRunPlayer" ( + "recordId" INTEGER NOT NULL, + "userId" INTEGER NOT NULL +); + +-- CreateIndex +CREATE UNIQUE INDEX "SalmonRunRotation.id_unique" ON "SalmonRunRotation"("id"); + +-- CreateIndex +CREATE UNIQUE INDEX "SalmonRunPlayer.recordId_userId_unique" ON "SalmonRunPlayer"("recordId", "userId"); + +-- AddForeignKey +ALTER TABLE "SalmonRunRecord" ADD FOREIGN KEY("rotationId")REFERENCES "SalmonRunRotation"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "SalmonRunRecord" ADD FOREIGN KEY("submitterId")REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "SalmonRunPlayer" ADD FOREIGN KEY("recordId")REFERENCES "SalmonRunRecord"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "SalmonRunPlayer" ADD FOREIGN KEY("userId")REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index cdf200520..65a4a848b 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -9,14 +9,16 @@ generator client { } model User { - id Int @id @default(autoincrement()) - username String - discriminator String - discordId String @unique - discordAvatar String? - profile Profile? - player Player? - builds Build[] + id Int @id @default(autoincrement()) + username String + discriminator String + discordId String @unique + discordAvatar String? + profile Profile? + player Player? + builds Build[] + submittedRecords SalmonRunRecord[] + salmonRunRecords SalmonRunPlayer[] } model Profile { @@ -157,3 +159,58 @@ model Build { @@index(userId) @@index(abilityPoints) } + +model SalmonRunRotation { + id Int @unique + startTime DateTime + endTime DateTime + weapons String[] + grizzcoWeapon String? + stage String + records SalmonRunRecord[] +} + +enum SalmonRunRecordCategory { + TOTAL + TOTAL_NO_NIGHT + PRINCESS + NT_NORMAL + HT_NORMAL + LT_NORMAL + NT_RUSH + HT_RUSH + NT_FOG + HT_FOG + LT_FOG + NT_GOLDIE + HT_GOLDIE + NT_GRILLERS + HT_GRILLERS + NT_MOTHERSHIP + HT_MOTHERSHIP + LT_MOTHERSHIP + LT_COHOCK +} + +model SalmonRunRecord { + id Int @id @default(autoincrement()) + rotationId Int + submitterId Int + goldenEggCount Int + approved Boolean + category SalmonRunRecordCategory + links String[] + createdAt DateTime @default(now()) + rotation SalmonRunRotation @relation(fields: [rotationId], references: [id]) + submitter User @relation(fields: [submitterId], references: [id]) + players SalmonRunPlayer[] +} + +model SalmonRunPlayer { + recordId Int + userId Int + record SalmonRunRecord @relation(fields: [recordId], references: [id]) + user User @relation(fields: [userId], references: [id]) + + @@unique([recordId, userId]) +}