Skip to content

Commit

Permalink
Model changes for AssignmentRoster
Browse files Browse the repository at this point in the history
  • Loading branch information
marcospri committed Sep 3, 2024
1 parent 7064177 commit 9fa613d
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 31 deletions.
2 changes: 1 addition & 1 deletion lms/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from lms.models.assignment_grouping import AssignmentGrouping
from lms.models.assignment_membership import AssignmentMembership
from lms.models.course_groups_exported_from_h import CourseGroupsExportedFromH
from lms.models.course_roster import CourseRoster
from lms.models.dashboard_admin import DashboardAdmin
from lms.models.event import Event, EventData, EventType, EventUser
from lms.models.exceptions import ReusedConsumerKey
Expand Down Expand Up @@ -37,6 +36,7 @@
from lms.models.oauth2_token import OAuth2Token
from lms.models.organization import Organization
from lms.models.organization_usage import OrganizationUsageReport
from lms.models.roster import AssignmentRoster, CourseRoster
from lms.models.rsa_key import RSAKey
from lms.models.task_done import TaskDone
from lms.models.user import User
Expand Down
30 changes: 0 additions & 30 deletions lms/models/course_roster.py

This file was deleted.

67 changes: 67 additions & 0 deletions lms/models/roster.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
from sqlalchemy import ForeignKey, UniqueConstraint
from sqlalchemy.orm import Mapped, mapped_column, relationship

from lms.db import Base
from lms.models._mixins import CreatedUpdatedMixin


class CourseRoster(Base, CreatedUpdatedMixin):
"""
Store roster information for courses.
Stores a row per unique: (course, user and role)
"""

__tablename__ = "course_roster"

id: Mapped[int] = mapped_column(autoincrement=True, primary_key=True)

lms_course_id: Mapped[int] = mapped_column(
ForeignKey("lms_course.id", ondelete="cascade")
)
lms_course = relationship("LMSCourse")

lms_user_id: Mapped[int] = mapped_column(
ForeignKey("lms_user.id", ondelete="cascade")
)
lms_user = relationship("LMSUser")

lti_role_id: Mapped[int] = mapped_column(
ForeignKey("lti_role.id", ondelete="cascade")
)
lti_role = relationship("LTIRole")

active: Mapped[bool] = mapped_column()

__table_args__ = (UniqueConstraint("lms_course_id", "lms_user_id", "lti_role_id"),)


class AssignmentRoster(Base, CreatedUpdatedMixin):
"""
Store roster information for assignments.
Stores a row per unique: (assignment, user and role)
"""

__tablename__ = "assignment_roster"

id: Mapped[int] = mapped_column(autoincrement=True, primary_key=True)

assignment_id: Mapped[int] = mapped_column(
ForeignKey("assignment.id", ondelete="cascade")
)
assignment = relationship("Assignment")

lms_user_id: Mapped[int] = mapped_column(
ForeignKey("lms_user.id", ondelete="cascade")
)
lms_user = relationship("LMSUser")

lti_role_id: Mapped[int] = mapped_column(
ForeignKey("lti_role.id", ondelete="cascade")
)
lti_role = relationship("LTIRole")

active: Mapped[bool] = mapped_column()

__table_args__ = (UniqueConstraint("assignment_id", "lms_user_id", "lti_role_id"),)

0 comments on commit 9fa613d

Please sign in to comment.