From b859e4b6174c1dcc851f407158abb848bcd13d14 Mon Sep 17 00:00:00 2001 From: smyalygames Date: Mon, 27 Feb 2023 16:26:06 +0000 Subject: [PATCH] feat(db): add outreach to database --- .../migration.sql | 18 ++------ prisma/schema.prisma | 41 ++++++++++--------- 2 files changed, 25 insertions(+), 34 deletions(-) rename prisma/migrations/{20230220171028_outreach => 20230227164244_outreach}/migration.sql (72%) diff --git a/prisma/migrations/20230220171028_outreach/migration.sql b/prisma/migrations/20230227164244_outreach/migration.sql similarity index 72% rename from prisma/migrations/20230220171028_outreach/migration.sql rename to prisma/migrations/20230227164244_outreach/migration.sql index 4410b38..365a7af 100644 --- a/prisma/migrations/20230220171028_outreach/migration.sql +++ b/prisma/migrations/20230227164244_outreach/migration.sql @@ -1,10 +1,10 @@ -- CreateTable CREATE TABLE "Event" ( "id" SERIAL NOT NULL, + "eventType" TEXT NOT NULL, "leaderId" TEXT NOT NULL, "startTime" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, "endTime" TIMESTAMP(3), - "eventTypeType" TEXT NOT NULL, CONSTRAINT "Event_pkey" PRIMARY KEY ("id") ); @@ -16,17 +16,10 @@ CREATE TABLE "EventType" ( CONSTRAINT "EventType_pkey" PRIMARY KEY ("type") ); --- CreateTable -CREATE TABLE "EventStat" ( - "eventId" INTEGER NOT NULL, - "statId" INTEGER NOT NULL, - - CONSTRAINT "EventStat_pkey" PRIMARY KEY ("eventId","statId") -); - -- CreateTable CREATE TABLE "Stat" ( "id" SERIAL NOT NULL, + "eventId" INTEGER NOT NULL, "leaderId" TEXT NOT NULL, "vegan" INTEGER NOT NULL DEFAULT 0, "considered" INTEGER NOT NULL DEFAULT 0, @@ -47,16 +40,13 @@ CREATE TABLE "ParticipantStat" ( ); -- AddForeignKey -ALTER TABLE "Event" ADD CONSTRAINT "Event_eventTypeType_fkey" FOREIGN KEY ("eventTypeType") REFERENCES "EventType"("type") ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE "Event" ADD CONSTRAINT "Event_eventType_fkey" FOREIGN KEY ("eventType") REFERENCES "EventType"("type") ON DELETE RESTRICT ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "Event" ADD CONSTRAINT "Event_leaderId_fkey" FOREIGN KEY ("leaderId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; -- AddForeignKey -ALTER TABLE "EventStat" ADD CONSTRAINT "EventStat_eventId_fkey" FOREIGN KEY ("eventId") REFERENCES "Event"("id") ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "EventStat" ADD CONSTRAINT "EventStat_statId_fkey" FOREIGN KEY ("statId") REFERENCES "Stat"("id") ON DELETE RESTRICT ON UPDATE CASCADE; +ALTER TABLE "Stat" ADD CONSTRAINT "Stat_eventId_fkey" FOREIGN KEY ("eventId") REFERENCES "Event"("id") ON DELETE RESTRICT ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "Stat" ADD CONSTRAINT "Stat_leaderId_fkey" FOREIGN KEY ("leaderId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 33d427b..7d85512 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -68,7 +68,7 @@ model Verify { finishTime DateTime? manual Boolean @default(false) // If they were verified with the verify command timedOut Boolean @default(false) // If they got kicked out of verification because they timed out - //complete Boolean @default(false) // If the verification was incomplete + // complete Boolean @default(false) // If the verification was incomplete // Roles they got from verification vegan Boolean @default(false) // If they got verified as a vegan activist Boolean @default(false) // If they got the activist role when they verified @@ -88,14 +88,14 @@ model Verify { } model Event { - id Int @id @default(autoincrement()) - type EventType @relation(fields: [eventTypeType], references: [type]) - leader User @relation("eventLeader", fields: [leaderId], references: [id]) // Not sure if this will stay - leaderId String - startTime DateTime @default(now()) - endTime DateTime? - EventStat EventStat[] - eventTypeType String + id Int @id @default(autoincrement()) + type EventType @relation(fields: [eventType], references: [type]) + eventType String + leader User @relation("eventLeader", fields: [leaderId], references: [id]) // Not sure if this will stay + leaderId String + startTime DateTime @default(now()) + endTime DateTime? + stats Stat[] } model EventType { @@ -104,17 +104,18 @@ model EventType { } model Stat { - id Int @id @default(autoincrement()) - leader User @relation("statLeader", fields: [leaderId], references: [id]) // Not sure if this will stay - leaderId String - vegan Int @default(0) - considered Int @default(0) - antivegan Int @default(0) - thanked Int @default(0) - documentary Int @default(0) - educated Int @default(0) - EventStat EventStat[] - ParticipantStat ParticipantStat[] + id Int @id @default(autoincrement()) + event Event @relation(fields: [eventId], references: [id]) + eventId Int + leader User @relation("statLeader", fields: [leaderId], references: [id]) // Not sure if this will stay + leaderId String + vegan Int @default(0) + considered Int @default(0) + antivegan Int @default(0) + thanked Int @default(0) + documentary Int @default(0) + educated Int @default(0) + participationStats ParticipantStat[] } model ParticipantStat {