Skip to content

added dbml file and updated dbml-schema #1123

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

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft

Conversation

YuDavidCao
Copy link
Collaborator

@YuDavidCao YuDavidCao commented Jul 3, 2025

GitHub Issues addressed

  • This PR closes

What I did

  • Added dbml schema to help visualize db

How to use:

Copy paste the dbml file into https://dbdiagram.io/

How is it done:

https://github.com/hamedsj/DbmlForDjango

Screenshots

  • Before
  • After

Testing

  • A brief explanation of tests done/written or how reviewers can test your work

Questions/Discussions/Notes

Summary by CodeRabbit

  • New Features
    • Introduced a comprehensive database structure to support academic and user management, including tables for users, permissions, groups, schools, departments, courses, instructors, semesters, clubs, and categories.
    • Added support for course enrollments, grades, sections, scheduling, and user-generated reviews, questions, and answers.
    • Implemented mechanisms for voting, feedback, and logging user actions, enhancing interaction and data integrity across the platform.

Copy link

coderabbitai bot commented Jul 3, 2025

Walkthrough

A comprehensive new database schema is introduced for an academic and user management system. The schema defines tables for users, permissions, academic entities (schools, departments, courses, instructors, semesters), clubs, scheduling, enrollments, grades, reviews, Q&A, and voting, with extensive foreign key relationships and many-to-many associations.

Changes

File(s) Change Summary
db/dbschema.dbml Added a complete database schema modeling users, permissions, academic structures, clubs, scheduling, reviews, Q&A, voting, and all related relationships and constraints.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Course
    participant Instructor
    participant Review
    participant Vote

    User->>Course: Enrolls / Views course
    User->>Instructor: Views instructor info
    User->>Review: Submits review for Course/Instructor
    User->>Vote: Votes on Review
    Review->>Course: Linked to course
    Review->>Instructor: Optionally linked to instructor
    Vote->>Review: Vote references review
Loading
sequenceDiagram
    participant User
    participant Schedule
    participant ScheduledCourse
    participant Section
    participant Instructor

    User->>Schedule: Creates schedule
    Schedule->>ScheduledCourse: Adds course to schedule
    ScheduledCourse->>Section: Links to section
    ScheduledCourse->>Instructor: Optionally links to instructor
Loading

Poem

In the warren of data, new tables arise,
Clubs, courses, and grades—oh my, what a prize!
Users and schedules, reviews in the mix,
With votes and permissions, it’s all in the fix.
🐇 Hopping through schemas, with relations so neat,
Academic adventures—now fully complete!


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🧹 Nitpick comments (3)
db/dbschema.dbml (3)

21-21: Document many-to-many junction tables

The schema shows many-to-many relationships but doesn't explicitly define the junction tables that will be created. This makes the actual database structure unclear.

Consider explicitly defining junction tables for clarity:

table Group_Permission {
  group_id foreign_key
  permission_id foreign_key
}

table User_Group {
  user_id foreign_key
  group_id foreign_key
}

table Instructor_Department {
  instructor_id foreign_key
  department_id foreign_key
}

Also applies to: 91-92, 101-101, 121-121, 172-172


1-324: Consider documenting database indexes

The schema lacks index definitions for foreign keys and commonly queried fields. This could lead to performance issues in production.

Consider adding index documentation for:

  • All foreign key fields (automatically created by most databases)
  • Composite indexes for common query patterns (e.g., semester.year + semester.season)
  • Fields used in WHERE clauses (e.g., course.number, user.computing_id)
  • Fields used in JOIN operations

135-168: Reduce duplication in grade tables

CourseGrade and CourseInstructorGrade have identical grade distribution fields, violating the DRY principle.

Consider creating a base grade distribution structure:

table GradeDistribution {
  average float
  a_plus int
  a int
  a_minus int
  b_plus int
  b int
  b_minus int
  c_plus int
  c int
  c_minus int
  dfw int
  total_enrolled int
  id int [primary_key]
}

table CourseGrade {
  course foreign_key
  grade_distribution foreign_key
  id int [primary_key]
}

table CourseInstructorGrade {
  instructor foreign_key
  course foreign_key
  grade_distribution foreign_key
  id int [primary_key]
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f260bb3 and 35b24ab.

⛔ Files ignored due to path filters (1)
  • db/dbschema.jpg is excluded by !**/*.jpg
📒 Files selected for processing (1)
  • db/dbschema.dbml (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: django
  • GitHub Check: pylint

ref: LogEntry.user > User.id
ref: LogEntry.content_type > ContentType.id
ref: Permission.content_type > ContentType.id
ref: Group.permissions > Permission.name
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Critical: Foreign key references should use primary keys

Foreign key references are incorrectly pointing to non-primary key fields (e.g., name, first_name) instead of id fields. This violates referential integrity best practices and can cause performance and data consistency issues.

Apply these corrections to use primary keys:

-ref: Group.permissions > Permission.name
+ref: Group.permissions > Permission.id
-ref: User.groups > Group.name
+ref: User.groups > Group.id
-ref: User.user_permissions > Permission.name
+ref: User.user_permissions > Permission.id
-ref: Instructor.departments > Department.name
+ref: Instructor.departments > Department.id
-ref: Course.disciplines > Discipline.name
+ref: Course.disciplines > Discipline.id
-ref: Section.instructors > Instructor.first_name
+ref: Section.instructors > Instructor.id

Also applies to: 289-293, 299-299

🤖 Prompt for AI Agents
In db/dbschema.dbml at line 285 and also lines 289-293 and 299, foreign key
references currently point to non-primary key fields like 'name' or
'first_name'. Update these foreign key references to point to the corresponding
primary key fields, typically 'id', to ensure proper referential integrity and
data consistency.


table User {
computing_id varchar [note: "primary_key : False<br>max_length : 20<br>nullable : False<br>blank : True"]
graduation_year int [note: "primary_key : False<br>nullable : True<br>blank : True"]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add validation constraints for graduation_year

The graduation_year field lacks validation constraints. Consider adding minimum and maximum year boundaries to prevent invalid data entry.

Add constraints in your Django model:

graduation_year = models.IntegerField(
    validators=[MinValueValidator(1900), MaxValueValidator(2100)],
    null=True, blank=True
)
🤖 Prompt for AI Agents
In db/dbschema.dbml at line 80, the graduation_year field lacks validation
constraints to ensure valid year values. Add minimum and maximum year boundaries
by updating the Django model to include validators MinValueValidator(1900) and
MaxValueValidator(2100) on the graduation_year IntegerField, while keeping null
and blank as True.

Comment on lines +207 to +209
course foreign_key
club foreign_key
instructor foreign_key
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider separating course and club reviews

The Review table has foreign keys to both course and club, suggesting it serves dual purposes. This violates the single responsibility principle and could complicate queries and business logic.

Consider splitting into separate tables:

  • CourseReview for course-related reviews
  • ClubReview for club-related reviews

This would improve maintainability and allow for type-specific fields and validations.

🤖 Prompt for AI Agents
In db/dbschema.dbml around lines 207 to 209, the Review table currently has
foreign keys to both course and club, mixing two distinct review types. To fix
this, split the Review table into two separate tables: CourseReview with a
foreign key to course, and ClubReview with a foreign key to club. This
separation will clarify responsibilities, simplify queries, and allow for
specific fields and validations per review type.

club foreign_key
instructor foreign_key
semester foreign_key
email varchar [note: "primary_key : False<br>nullable : True<br>blank : True"]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Security concern: Redundant email storage

The email field appears redundant since reviews are already linked to users who have email addresses. Storing emails in multiple places increases PII exposure risk.

Remove the email field and retrieve it through the user relationship when needed:

-email varchar [note: "primary_key : False<br>nullable : True<br>blank : True"]
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
email varchar [note: "primary_key : False<br>nullable : True<br>blank : True"]
🤖 Prompt for AI Agents
In db/dbschema.dbml at line 211, the email field is redundant because user
emails can be accessed via the user relationship in reviews. Remove the email
field from this table to reduce PII exposure and ensure any email data is
retrieved through the associated user entity instead.

@YuDavidCao YuDavidCao marked this pull request as draft July 3, 2025 15:40
Copy link
Collaborator

@Jay-Lalwani Jay-Lalwani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool! can you turn what you did into a short script? db changes often...

@YuDavidCao
Copy link
Collaborator Author

Yeah yeah, ima see what the coderabbit is saying about the foreign key thing tho, it is a very old package. Ima look into it a bit more once I got the time. I don't want to generate wrong diagrams xD

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

Successfully merging this pull request may close these issues.

2 participants