diff --git a/alembic/versions/2c332002ee3f_remove_unitchanges.py b/alembic/versions/2c332002ee3f_remove_unitchanges.py new file mode 100644 index 0000000..2fdf2fa --- /dev/null +++ b/alembic/versions/2c332002ee3f_remove_unitchanges.py @@ -0,0 +1,42 @@ +"""remove unitchanges + +Revision ID: 2c332002ee3f +Revises: 3b1a337a1fe5 +Create Date: 2026-03-02 17:17:30.233013 + +""" + +from typing import Sequence, Union + +import sqlalchemy as sa +from sqlalchemy.dialects import sqlite + +from alembic import op + +# revision identifiers, used by Alembic. +revision: str = "2c332002ee3f" +down_revision: Union[str, Sequence[str], None] = "3b1a337a1fe5" +branch_labels: Union[str, Sequence[str], None] = None +depends_on: Union[str, Sequence[str], None] = None + + +def upgrade() -> None: + """Upgrade schema.""" + # ### commands auto generated by Alembic - please adjust! ### + op.drop_table("unitchanges") + op.execute("VACUUM") + # ### end Alembic commands ### + + +def downgrade() -> None: + """Downgrade schema.""" + # ### commands auto generated by Alembic - please adjust! ### + op.create_table( + "unitchanges", + sa.Column("id", sa.INTEGER(), nullable=False), + sa.Column("unit_id", sa.INTEGER(), nullable=False), + sa.Column("changes", sqlite.JSON(), nullable=True), + sa.Column("scraped_at", sa.INTEGER(), nullable=False), + sa.PrimaryKeyConstraint("id"), + ) + # ### end Alembic commands ### diff --git a/api/models.py b/api/models.py index 56e7861..f918bff 100644 --- a/api/models.py +++ b/api/models.py @@ -517,17 +517,6 @@ def search_query(self) -> str: """ -# TODO: REMOVE -class UnitChanges(BaseModel, table=True): - """We keep track of changes that get applied to learning units""" - - id: int | None = Field(default=None, primary_key=True) - unit_id: int - changes: dict[str, object] = Field(sa_column=Column(JSON())) - scraped_at: int - """The scraped_at before the changes were applied""" - - # TODO: move to metadata db class FinishedScrapingSemester(BaseModel, table=True): """Keeps track of which semesters have been fully scraped already.""" diff --git a/api/routers/v1/units.py b/api/routers/v1/units.py index 88af1fd..5eb8f7e 100644 --- a/api/routers/v1/units.py +++ b/api/routers/v1/units.py @@ -10,7 +10,6 @@ LearningUnit, Level, Periodicity, - UnitChanges, UnitExaminerLink, UnitLecturerLink, ) @@ -67,37 +66,6 @@ async def get_unit_lecturers( return results -@router.get( - "/{unit_id}/changes", - response_model=Sequence[UnitChanges], - description="WILL BE REMOVED BEGINNING OF MARCH 2026. It's too broken.\n" - + "Get a list of changes that the course details have undergone. " - + "Changes are a JSON object that describe what the values were before they " - + "got updated to either the next change or whatever the model currently has.", - deprecated=True, -) -async def get_unit_changes( - unit_id: int, - session: Annotated[AsyncSession, Depends(aget_session)], - limit: Annotated[int, Query(gt=0, le=1000)] = 100, - offset: Annotated[int, Query(ge=0)] = 0, -) -> Sequence[UnitChanges]: - with tracer.start_as_current_span("get_unit_changes") as span: - span.set_attribute("unit_id", unit_id) - span.set_attribute("limit", limit) - span.set_attribute("offset", offset) - query = ( - select(UnitChanges) - .where(UnitChanges.unit_id == unit_id) - .order_by(col(UnitChanges.scraped_at).desc()) - .offset(offset) - .limit(limit) - ) - results = (await session.exec(query)).all() - span.set_attribute("result_count", len(results)) - return results - - @router.get("/{unit_id}/examiners", response_model=Sequence[int]) async def get_unit_examiners( unit_id: int,