From 94f39b2bfb38d77b0fbb9196792ad7c38ca9d9a6 Mon Sep 17 00:00:00 2001 From: Dyakov Roman Date: Mon, 20 Mar 2023 17:11:11 +0300 Subject: [PATCH] Building url (#87) --- calendar_backend/models/db.py | 19 +++++++-------- calendar_backend/routes/models/base.py | 1 + calendar_backend/routes/models/room.py | 2 ++ .../versions/3948c45f9977_building_url.py | 23 +++++++++++++++++++ 4 files changed, 36 insertions(+), 9 deletions(-) create mode 100644 migrations/versions/3948c45f9977_building_url.py diff --git a/calendar_backend/models/db.py b/calendar_backend/models/db.py index 93776187..c31cb836 100644 --- a/calendar_backend/models/db.py +++ b/calendar_backend/models/db.py @@ -32,10 +32,11 @@ class Direction(str, Enum): class Room(BaseDbModel): - name: Mapped[int] = mapped_column(String, nullable=False, unique=True) - direction: Mapped[int] = mapped_column(DbEnum(Direction, native_enum=False), nullable=True) - building: Mapped[int] = mapped_column(String) - is_deleted: Mapped[int] = mapped_column(Boolean, default=False) + name: Mapped[str] = mapped_column(String, nullable=False, unique=True) + direction: Mapped[Direction] = mapped_column(DbEnum(Direction, native_enum=False), nullable=True) + building: Mapped[str] = mapped_column(String, nullable=True) + building_url: Mapped[str] = mapped_column(String, nullable=True) + is_deleted: Mapped[bool] = mapped_column(Boolean, default=False) events: Mapped[list[Event]] = relationship( "Event", @@ -47,12 +48,12 @@ class Room(BaseDbModel): class Lecturer(BaseDbModel): - first_name: Mapped[int] = mapped_column(String, nullable=False) - middle_name: Mapped[int] = mapped_column(String, nullable=False) - last_name: Mapped[int] = mapped_column(String, nullable=False) + first_name: Mapped[str] = mapped_column(String, nullable=False) + middle_name: Mapped[str] = mapped_column(String, nullable=False) + last_name: Mapped[str] = mapped_column(String, nullable=False) avatar_id: Mapped[int] = mapped_column(Integer, ForeignKey("photo.id")) - description: Mapped[int] = mapped_column(Text, nullable=True) - is_deleted: Mapped[int] = mapped_column(Boolean, default=False) + description: Mapped[str] = mapped_column(Text, nullable=True) + is_deleted: Mapped[bool] = mapped_column(Boolean, default=False) avatar: Mapped[Photo] = relationship( "Photo", diff --git a/calendar_backend/routes/models/base.py b/calendar_backend/routes/models/base.py index 3858b0b0..b0602ba8 100644 --- a/calendar_backend/routes/models/base.py +++ b/calendar_backend/routes/models/base.py @@ -61,6 +61,7 @@ class RoomGet(Base): id: int name: str building: str | None + building_url: str | None direction: str | None def __repr__(self): diff --git a/calendar_backend/routes/models/room.py b/calendar_backend/routes/models/room.py index cdae4f7c..6ab0e83d 100644 --- a/calendar_backend/routes/models/room.py +++ b/calendar_backend/routes/models/room.py @@ -6,6 +6,7 @@ class RoomPatch(Base): name: str | None building: str | None + building_url: str | None direction: Direction | None def __repr__(self): @@ -15,6 +16,7 @@ def __repr__(self): class RoomPost(Base): name: str building: str | None + building_url: str | None direction: Direction | None diff --git a/migrations/versions/3948c45f9977_building_url.py b/migrations/versions/3948c45f9977_building_url.py new file mode 100644 index 00000000..75e4f0d8 --- /dev/null +++ b/migrations/versions/3948c45f9977_building_url.py @@ -0,0 +1,23 @@ +"""Building url + +Revision ID: 3948c45f9977 +Revises: 63263ee9e08e +Create Date: 2023-03-20 16:42:54.345727 + +""" +from alembic import op +import sqlalchemy as sa + +# revision identifiers, used by Alembic. +revision = '3948c45f9977' +down_revision = '63263ee9e08e' +branch_labels = None +depends_on = None + + +def upgrade(): + op.add_column('room', sa.Column('building_url', sa.String(), nullable=True)) + + +def downgrade(): + op.drop_column('room', 'building_url')