Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prisma Quiz Schema #42

Open
Tracked by #46
icepick4 opened this issue Jan 15, 2024 · 0 comments
Open
Tracked by #46

Prisma Quiz Schema #42

icepick4 opened this issue Jan 15, 2024 · 0 comments

Comments

@icepick4
Copy link
Owner

Create the prisma schema for the quizzes with the types given in #41 as base.

Here is a first version (not final) :

model QuestionResult {
  id            Int          @id @default(autoincrement()) @db.UnsignedInt
  user_id       Int          @db.UnsignedInt
  country_id    Int          @db.UnsignedInt
  learning_type LearningType @default(capital)
  result        Score        @default(succeeded)
  created_at    DateTime     @default(now()) @db.Timestamp(0)
  country       Country      @relation(fields: [country_id], references: [id])

  @@index([country_id])
}

model QuizQuestion {
  id         Int          @id @default(autoincrement()) @db.UnsignedInt
  question   String       @db.VarChar(255)
  Quiz       Quiz?        @relation(fields: [quizId], references: [id])
  quizId     Int?         @db.UnsignedInt
  QuizAnswer QuizAnswer[]
}

model QuizAnswer {
  id           Int          @id @default(autoincrement()) @db.UnsignedInt
  answer       AnswerType   @default(capital)
  is_correct   Boolean
  quizId       Int          @db.UnsignedInt
  Quiz         Quiz         @relation(fields: [quizId], references: [id])
  question_id  Int          @db.UnsignedInt
  QuizQuestion QuizQuestion @relation(fields: [question_id], references: [id])

  @@index([quizId], map: "idx_quizanswer_quiz_id")
  @@index([question_id], map: "idx_quizanswer_question_id")
}

model Quiz {
  id          Int            @id @default(autoincrement()) @db.UnsignedInt
  name        String         @db.VarChar(255)
  difficulty  Int            @db.UnsignedInt
  theme       String         @db.VarChar(255)
  description String         @db.VarChar(255)
  questions   QuizQuestion[]
  answers     QuizAnswer[]

  created_at DateTime     @default(now()) @db.Timestamp(0)
  updated_at DateTime?    @default(now()) @db.DateTime(0)
  user_id    Int          @db.UnsignedInt
  QuizResult QuizResult[]

  @@index([name], map: "idx_quiz_name")
}

model QuizResult {
  id         Int      @id @default(autoincrement()) @db.UnsignedInt
  quiz_id    Int      @db.UnsignedInt
  user_id    Int      @db.UnsignedInt
  result     Int      @db.UnsignedInt
  created_at DateTime @default(now()) @db.Timestamp(0)
  quiz       Quiz     @relation(fields: [quiz_id], references: [id])

  @@index([quiz_id], map: "idx_quizresult_quiz_id")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant