Skip to content

Commit

Permalink
Migration for LMSSegment
Browse files Browse the repository at this point in the history
  • Loading branch information
marcospri committed Nov 8, 2024
1 parent 7d9fea6 commit 5f2e583
Showing 1 changed file with 149 additions and 0 deletions.
149 changes: 149 additions & 0 deletions lms/migrations/versions/2ff20de04a9d_create_lms_segment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
"""Create lms_segment."""

import sqlalchemy as sa
from alembic import op

revision = "2ff20de04a9d"
down_revision = "ba295703738b"


def upgrade() -> None:
op.create_table(
"lms_segment",
sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
sa.Column(
"type",
sa.Enum(
"course",
"canvas_section",
"canvas_group",
"blackboard_group",
"d2l_group",
"moodle_group",
"section",
"group",
name="type",
native_enum=False,
length=64,
),
nullable=False,
),
sa.Column("lms_id", sa.String(), nullable=False),
sa.Column("name", sa.String(), nullable=False),
sa.Column("h_authority_provided_id", sa.String(), nullable=False),
sa.Column("lms_course_id", sa.Integer(), nullable=True),
sa.Column("lms_group_set_id", sa.Integer(), nullable=True),
sa.Column(
"created", sa.DateTime(), server_default=sa.text("now()"), nullable=False
),
sa.Column(
"updated", sa.DateTime(), server_default=sa.text("now()"), nullable=False
),
sa.ForeignKeyConstraint(
["lms_course_id"],
["lms_course.id"],
name=op.f("fk__lms_segment__lms_course_id__lms_course"),
),
sa.ForeignKeyConstraint(
["lms_group_set_id"],
["lms_group_set.id"],
name=op.f("fk__lms_segment__lms_group_set_id__lms_group_set"),
ondelete="cascade",
),
sa.PrimaryKeyConstraint("id", name=op.f("pk__lms_segment")),
)
op.create_index(
op.f("ix__lms_segment_h_authority_provided_id"),
"lms_segment",
["h_authority_provided_id"],
unique=True,
)
op.create_index(
op.f("ix__lms_segment_lms_group_set_id"),
"lms_segment",
["lms_group_set_id"],
unique=False,
)
op.create_index(
op.f("ix__lms_segment_lms_id"), "lms_segment", ["lms_id"], unique=False
)
op.create_table(
"lms_segment_membership",
sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
sa.Column("lms_segment_id", sa.Integer(), nullable=False),
sa.Column("lms_user_id", sa.Integer(), nullable=False),
sa.Column("lti_role_id", sa.Integer(), nullable=False),
sa.Column(
"created", sa.DateTime(), server_default=sa.text("now()"), nullable=False
),
sa.Column(
"updated", sa.DateTime(), server_default=sa.text("now()"), nullable=False
),
sa.ForeignKeyConstraint(
["lms_segment_id"],
["lms_segment.id"],
name=op.f("fk__lms_segment_membership__lms_segment_id__lms_segment"),
ondelete="cascade",
),
sa.ForeignKeyConstraint(
["lms_user_id"],
["lms_user.id"],
name=op.f("fk__lms_segment_membership__lms_user_id__lms_user"),
ondelete="cascade",
),
sa.ForeignKeyConstraint(
["lti_role_id"],
["lti_role.id"],
name=op.f("fk__lms_segment_membership__lti_role_id__lti_role"),
ondelete="cascade",
),
sa.PrimaryKeyConstraint("id", name=op.f("pk__lms_segment_membership")),
sa.UniqueConstraint(
"lms_segment_id",
"lms_user_id",
"lti_role_id",
name=op.f("uq__lms_segment_membership__lms_segment_id"),
),
)
op.create_index(
op.f("ix__lms_segment_membership_lms_segment_id"),
"lms_segment_membership",
["lms_segment_id"],
unique=False,
)
op.create_index(
op.f("ix__lms_segment_membership_lms_user_id"),
"lms_segment_membership",
["lms_user_id"],
unique=False,
)
op.create_index(
op.f("ix__lms_segment_membership_lti_role_id"),
"lms_segment_membership",
["lti_role_id"],
unique=False,
)
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(
op.f("ix__lms_segment_membership_lti_role_id"),
table_name="lms_segment_membership",
)
op.drop_index(
op.f("ix__lms_segment_membership_lms_user_id"),
table_name="lms_segment_membership",
)
op.drop_index(
op.f("ix__lms_segment_membership_lms_segment_id"),
table_name="lms_segment_membership",
)
op.drop_table("lms_segment_membership")
op.drop_index(op.f("ix__lms_segment_lms_id"), table_name="lms_segment")
op.drop_index(op.f("ix__lms_segment_lms_group_set_id"), table_name="lms_segment")
op.drop_index(
op.f("ix__lms_segment_h_authority_provided_id"), table_name="lms_segment"
)
op.drop_table("lms_segment")

0 comments on commit 5f2e583

Please sign in to comment.