diff --git a/Makefile b/Makefile index c6a2d1c..8a826f9 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,10 @@ format: autoflake -r --in-place --remove-all-unused-imports ./rating_api isort ./rating_api black ./rating_api - + autoflake -r --in-place --remove-all-unused-imports ./migrations + isort ./migrations + black ./migrations + db: docker run -d -p 5432:5432 -e POSTGRES_HOST_AUTH_METHOD=trust --name db-rating_api postgres:15 diff --git a/migrations/versions/20181e0d6aab_make_nullable_timetable_id.py b/migrations/versions/20181e0d6aab_make_nullable_timetable_id.py new file mode 100644 index 0000000..efdfd17 --- /dev/null +++ b/migrations/versions/20181e0d6aab_make_nullable_timetable_id.py @@ -0,0 +1,24 @@ +"""make nullable timetable_id + +Revision ID: 20181e0d6aab +Revises: edcc1a448ffb +Create Date: 2024-11-30 18:45:08.527638 + +""" + +from alembic import op + + +# revision identifiers, used by Alembic. +revision = '20181e0d6aab' +down_revision = 'edcc1a448ffb' +branch_labels = None +depends_on = None + + +def upgrade(): + op.drop_constraint('lecturer_timetable_id_key', 'lecturer', type_='unique') + + +def downgrade(): + op.create_unique_constraint('lecturer_timetable_id_key', 'lecturer', ['timetable_id']) diff --git a/rating_api/models/db.py b/rating_api/models/db.py index 1c0e1b8..b36f783 100644 --- a/rating_api/models/db.py +++ b/rating_api/models/db.py @@ -33,7 +33,7 @@ class Lecturer(BaseDbModel): last_name: Mapped[str] = mapped_column(String, nullable=False) middle_name: Mapped[str] = mapped_column(String, nullable=False) avatar_link: Mapped[str] = mapped_column(String, nullable=True) - timetable_id: Mapped[int] = mapped_column(Integer, unique=True, nullable=False) + timetable_id: Mapped[int] comments: Mapped[list[Comment]] = relationship("Comment", back_populates="lecturer") is_deleted: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False) diff --git a/rating_api/schemas/models.py b/rating_api/schemas/models.py index 2e2cc1e..6cd1ac5 100644 --- a/rating_api/schemas/models.py +++ b/rating_api/schemas/models.py @@ -78,7 +78,7 @@ class LecturerPost(Base): last_name: str middle_name: str avatar_link: str | None = None - timetable_id: int + timetable_id: int | None = None class LecturerPatch(Base):