Git Product home page Git Product logo

Comments (2)

Codehagen avatar Codehagen commented on June 12, 2024

Attached is a schema for prisma:

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

generator client {
  provider = "prisma-client-js"
}

model User {
  user_id             Int                   @id @default(autoincrement())
  username            String
  email               String                @unique
  password            String
  role                String
  date_of_birth       DateTime
  contact_info        String?
  coached_teams       Team[]                @relation("TeamCoach")
  workouts            Workout[]
  athlete_teams       Athletes_Teams[]
  attendance          Attendance[]
  performance_metrics Performance_Metrics[]
  uploaded_files      Files[]
  event_results       Event_Results[]
  swimmer_events      Swimmers_Events[]
  sent_messages       Messages[]            @relation("MessageSender")
  received_messages   Messages[]            @relation("MessageRecipient")
}

model Team {
  team_id     Int              @id @default(autoincrement())
  team_name   String
  coach_id    Int
  description String?
  coach       User             @relation("TeamCoach", fields: [coach_id], references: [user_id])
  athletes    Athletes_Teams[]
  workouts    Workout[]
}

model Athletes_Teams {
  athlete_id Int
  team_id    Int
  join_date  DateTime?
  leave_date DateTime?
  athlete    User      @relation(fields: [athlete_id], references: [user_id])
  team       Team      @relation(fields: [team_id], references: [team_id])

  @@id([athlete_id, team_id])
}

model Workout {
  workout_id          Int                   @id @default(autoincrement())
  workout_name        String
  coach_id            Int
  team_id             Int?
  date                DateTime
  duration            String 
  description         String?
  coach               User                  @relation(fields: [coach_id], references: [user_id])
  team                Team?                 @relation(fields: [team_id], references: [team_id])
  performance_metrics Performance_Metrics[]
}

model Swim_Meet {
  meet_id       Int                @id @default(autoincrement())
  meet_name     String
  meet_date     DateTime
  location      String
  description   String?
  attendance    Attendance[]
  events        Swim_Meet_Events[]
  event_results Event_Results[]
}

model Attendance {
  attendance_id     Int       @id @default(autoincrement())
  athlete_id        Int
  meet_id           Int
  attendance_status String
  date              DateTime
  notes             String?
  athlete           User      @relation(fields: [athlete_id], references: [user_id])
  meet              Swim_Meet @relation(fields: [meet_id], references: [meet_id])
}

model Messages {
  message_id      Int       @id @default(autoincrement())
  sender_id       Int
  recipient_id    Int
  message_content String
  timestamp       DateTime  @default(now()) // Use `now()` to automatically set the message timestamp
  read_at         DateTime? // Nullable, set when the message is read
  deleted_at      DateTime? // Nullable, set when the message is 'deleted'
  sender          User      @relation("MessageSender", fields: [sender_id], references: [user_id])
  recipient       User      @relation("MessageRecipient", fields: [recipient_id], references: [user_id])

  @@index([sender_id])
  @@index([recipient_id])
}

model Performance_Metrics {
  performance_id Int      @id @default(autoincrement())
  athlete_id     Int
  workout_id     Int
  metric_type    String
  value          Float
  date           DateTime
  notes          String?
  athlete        User     @relation(fields: [athlete_id], references: [user_id])
  workout        Workout  @relation(fields: [workout_id], references: [workout_id])
}

model Files {
  file_id     Int      @id @default(autoincrement())
  file_name   String
  file_type   String
  file_size   BigInt
  file_url    String
  uploader_id Int
  upload_date DateTime
  description String?
  uploader    User     @relation(fields: [uploader_id], references: [user_id])
}

model Swim_Meet_Events {
  event_id        Int               @id @default(autoincrement())
  meet_id         Int
  event_name      String
  event_type      String
  event_distance  Int
  distance_unit   String
  event_gender    String?
  event_age_group String?
  meet            Swim_Meet         @relation(fields: [meet_id], references: [meet_id])
  swimmers        Swimmers_Events[]
  results         Event_Results[]
}

model Swimmers_Events {
  swimmer_event_id Int              @id @default(autoincrement())
  event_id         Int
  athlete_id       Int
  swim_time        String 
  event            Swim_Meet_Events @relation(fields: [event_id], references: [event_id])
  athlete          User             @relation(fields: [athlete_id], references: [user_id])
}

model Event_Results {
  result_id     Int              @id @default(autoincrement())
  meet_id       Int
  event_id      Int
  athlete_id    Int
  time_result   String 
  placement     Int
  points_earned Int
  meet          Swim_Meet        @relation(fields: [meet_id], references: [meet_id])
  event         Swim_Meet_Events @relation(fields: [event_id], references: [event_id])
  athlete       User             @relation(fields: [athlete_id], references: [user_id])
}

Under is a explanation of what is one to many etc:

1. User

  • coached_teams: A one-to-many relationship from User to Team through coach_id. A user can coach multiple teams.
  • workouts: A one-to-many relationship from User to Workout through coach_id. A user can create multiple workouts.
  • athlete_teams: A many-to-many relationship between User and Team via Athletes_Teams. Represents the teams that a user (athlete) belongs to.
  • attendance: A one-to-many relationship from User to Attendance. A user (athlete) can have multiple attendance records.
  • performance_metrics: A one-to-many relationship from User to Performance_Metrics. A user (athlete) can have multiple performance metrics.
  • uploaded_files: A one-to-many relationship from User to Files through uploader_id. A user can upload multiple files.
  • event_results: A one-to-many relationship from User to Event_Results. A user (athlete) can have multiple results in different events.
  • swimmer_events: A many-to-many relationship between User and Swim_Meet_Events via Swimmers_Events. Represents events in which a user (swimmer) participates.
  • sent_messages and received_messages: Represent the one-to-many relationships for messages sent and received by a user.

2. Team

  • coach: A many-to-one relationship from Team to User. Each team has one coach.
  • athletes: The other side of the many-to-many relationship with User via Athletes_Teams.
  • workouts: A one-to-many relationship from Team to Workout. A team can have multiple workouts scheduled.

3. Workout

  • coach: A many-to-one relationship linking each workout to a specific coach (User).
  • team: An optional many-to-one relationship linking each workout to a team. Some workouts might not be team-specific.
  • performance_metrics: A one-to-many relationship linking workouts to their associated performance metrics.

4. Swim_Meet

  • attendance: A one-to-many relationship from Swim_Meet to Attendance. Each meet can have multiple attendance records.
  • events: A one-to-many relationship from Swim_Meet to Swim_Meet_Events. Each swim meet can include multiple events.
  • event_results: A one-to-many relationship, indicating the results recorded at a specific meet.

5. Attendance

  • athlete and meet: Many-to-one relationships linking each attendance record to a specific athlete and meet.

6. Messages

  • sender and recipient: Many-to-one relationships from Messages to User, distinguishing between the sender and recipient of each message.

7. Performance_Metrics, Files, Event_Results

  • These models link back to User indicating which user the records are associated with, and in the case of Performance_Metrics and Event_Results, they also link to specific workouts or events.

8. Swim_Meet_Events and Swimmers_Events

  • Swim_Meet_Events: Links each event to a swim meet.
  • Swimmers_Events: The many-to-many relationship through which athletes are connected to specific events in a swim meet.

9. Event_Results

  • Links results to their respective meet, event, and athlete.

Could you look at this @JamesSingleton to see if the explanation for it is what you are thinking of ✨

from project-aqua.

JamesSingleton avatar JamesSingleton commented on June 12, 2024

@Codehagen I apologize that I am now just getting to this. For the Team, a swim team could have multiple coaches, for example, if you look at Arizona State University's swim team they have 1 Head Coach, 5 Assistant Coaches and 1 Diving Coach. Other than that, I think everything looks good. I guess I won't know until I start to wire everything together 😅

from project-aqua.

Related Issues (12)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.