mirror of https://github.com/stijndcl/didier
Create ufora-related revision
parent
b23160b8e2
commit
eb71470edc
|
@ -0,0 +1,52 @@
|
|||
"""Initial migration: Ufora announcements
|
||||
|
||||
Revision ID: 9e8ce58c0a26
|
||||
Revises:
|
||||
Create Date: 2022-06-17 01:36:02.767151
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '9e8ce58c0a26'
|
||||
down_revision = None
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_table('ufora_courses',
|
||||
sa.Column('course_id', sa.Integer(), nullable=False),
|
||||
sa.Column('name', sa.Text(), nullable=False),
|
||||
sa.Column('code', sa.Text(), nullable=False),
|
||||
sa.Column('year', sa.Integer(), nullable=False),
|
||||
sa.PrimaryKeyConstraint('course_id'),
|
||||
sa.UniqueConstraint('code'),
|
||||
sa.UniqueConstraint('name')
|
||||
)
|
||||
op.create_table('ufora_announcements',
|
||||
sa.Column('announcement_id', sa.Integer(), nullable=False),
|
||||
sa.Column('course_id', sa.Integer(), nullable=True),
|
||||
sa.ForeignKeyConstraint(['course_id'], ['ufora_courses.course_id'], ),
|
||||
sa.PrimaryKeyConstraint('announcement_id')
|
||||
)
|
||||
op.create_table('ufora_course_aliases',
|
||||
sa.Column('alias_id', sa.Integer(), nullable=False),
|
||||
sa.Column('alias', sa.Text(), nullable=False),
|
||||
sa.Column('course_id', sa.Integer(), nullable=True),
|
||||
sa.ForeignKeyConstraint(['course_id'], ['ufora_courses.course_id'], ),
|
||||
sa.PrimaryKeyConstraint('alias_id'),
|
||||
sa.UniqueConstraint('alias')
|
||||
)
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_table('ufora_course_aliases')
|
||||
op.drop_table('ufora_announcements')
|
||||
op.drop_table('ufora_courses')
|
||||
# ### end Alembic commands ###
|
|
@ -1,5 +1,47 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from sqlalchemy.orm import declarative_base
|
||||
from sqlalchemy import Column, Integer, Text, ForeignKey
|
||||
from sqlalchemy.orm import declarative_base, relationship
|
||||
|
||||
Base = declarative_base()
|
||||
|
||||
|
||||
class UforaCourse(Base):
|
||||
"""A course on Ufora"""
|
||||
|
||||
__tablename__ = "ufora_courses"
|
||||
|
||||
course_id: int = Column(Integer, primary_key=True)
|
||||
name: str = Column(Text, nullable=False, unique=True)
|
||||
code: str = Column(Text, nullable=False, unique=True)
|
||||
year: int = Column(Integer, nullable=False)
|
||||
|
||||
announcements: list[UforaAnnouncement] = relationship(
|
||||
"UforaAnnouncement", back_populates="course", cascade="all, delete-orphan"
|
||||
)
|
||||
aliases: list[UforaCourseAlias] = relationship(
|
||||
"UforaCourseAlias", back_populates="course", cascade="all, delete-orphan"
|
||||
)
|
||||
|
||||
|
||||
class UforaCourseAlias(Base):
|
||||
"""An alias for a course on Ufora that we use to refer to them"""
|
||||
|
||||
__tablename__ = "ufora_course_aliases"
|
||||
|
||||
alias_id: int = Column(Integer, primary_key=True)
|
||||
alias: str = Column(Text, nullable=False, unique=True)
|
||||
course_id: int = Column(Integer, ForeignKey("ufora_courses.course_id"))
|
||||
|
||||
course: UforaCourse = relationship("UforaCourse", back_populates="aliases", uselist=False)
|
||||
|
||||
|
||||
class UforaAnnouncement(Base):
|
||||
"""An announcement sent on Ufora"""
|
||||
|
||||
__tablename__ = "ufora_announcements"
|
||||
|
||||
announcement_id = Column(Integer, primary_key=True)
|
||||
course_id = Column(Integer, ForeignKey("ufora_courses.course_id"))
|
||||
|
||||
course = relationship("UforaCourse", back_populates="announcements", uselist=False)
|
||||
|
|
|
@ -15,8 +15,6 @@ def tables():
|
|||
Starts from an empty database and runs through all the migrations to check those as well
|
||||
while we're at it
|
||||
"""
|
||||
print("CWD: ", os.getcwd())
|
||||
print("Contents: ", list(os.listdir(os.getcwd())))
|
||||
alembic_config = config.Config("alembic.ini")
|
||||
command.upgrade(alembic_config, "head")
|
||||
yield
|
||||
|
|
Loading…
Reference in New Issue