Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 39 additions & 39 deletions calendar_backend/models/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ class Credentials(BaseDbModel):
"""User credentials"""

id: Mapped[int] = mapped_column(Integer, primary_key=True)
group: Mapped[int] = mapped_column(String, nullable=False)
email: Mapped[int] = mapped_column(String, nullable=False)
scope: Mapped[int] = mapped_column(JSON, nullable=False)
token: Mapped[int] = mapped_column(JSON, nullable=False)
create_ts: Mapped[int] = mapped_column(DateTime, nullable=False, default=datetime.utcnow)
update_ts: Mapped[int] = mapped_column(DateTime, nullable=False, default=datetime.utcnow, onupdate=datetime.utcnow)
group: Mapped[str] = mapped_column(String, nullable=False)
email: Mapped[str] = mapped_column(String, nullable=False)
scope: Mapped[JSON] = mapped_column(JSON, nullable=False)
token: Mapped[JSON] = mapped_column(JSON, nullable=False)
create_ts: Mapped[datetime] = mapped_column(DateTime, nullable=False, default=datetime.utcnow)
update_ts: Mapped[datetime] = mapped_column(DateTime, nullable=False, default=datetime.utcnow, onupdate=datetime.utcnow)


class Direction(str, Enum):
Expand All @@ -36,7 +36,7 @@ class Room(BaseDbModel):
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)
is_deleted: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False)

events: Mapped[list[Event]] = relationship(
"Event",
Expand All @@ -51,9 +51,9 @@ class Lecturer(BaseDbModel):
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"))
avatar_id: Mapped[int] = mapped_column(Integer, ForeignKey("photo.id"), nullable=True)
description: Mapped[str] = mapped_column(Text, nullable=True)
is_deleted: Mapped[bool] = mapped_column(Boolean, default=False)
is_deleted: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False)

avatar: Mapped[Photo] = relationship(
"Photo",
Expand Down Expand Up @@ -98,9 +98,9 @@ def last_photo(self) -> Photo | None:


class Group(BaseDbModel):
name: Mapped[int] = mapped_column(String, nullable=False)
number: Mapped[int] = mapped_column(String, nullable=False, unique=True)
is_deleted: Mapped[int] = mapped_column(Boolean, default=False)
name: Mapped[str] = mapped_column(String, nullable=False)
number: Mapped[str] = mapped_column(String, nullable=False, unique=True)
is_deleted: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False)

events: Mapped[list[Event]] = relationship(
"Event",
Expand All @@ -111,11 +111,11 @@ class Group(BaseDbModel):


class Event(BaseDbModel):
name: Mapped[int] = mapped_column(String, nullable=False)
group_id: Mapped[int] = mapped_column(Integer, ForeignKey("group.id"))
start_ts: Mapped[int] = mapped_column(DateTime, nullable=False)
end_ts: Mapped[int] = mapped_column(DateTime, nullable=False)
is_deleted: Mapped[int] = mapped_column(Boolean, default=False)
name: Mapped[str] = mapped_column(String, nullable=False)
group_id: Mapped[int] = mapped_column(Integer, ForeignKey("group.id"), nullable=True)
start_ts: Mapped[datetime] = mapped_column(DateTime, nullable=False)
end_ts: Mapped[datetime] = mapped_column(DateTime, nullable=False)
is_deleted: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False)

room: Mapped[list[Room]] = relationship(
"Room",
Expand Down Expand Up @@ -144,20 +144,20 @@ class Event(BaseDbModel):


class EventsLecturers(BaseDbModel):
event_id: Mapped[int] = mapped_column(Integer, ForeignKey("event.id"))
lecturer_id: Mapped[int] = mapped_column(Integer, ForeignKey("lecturer.id"))
event_id: Mapped[int] = mapped_column(Integer, ForeignKey("event.id"), nullable=False)
lecturer_id: Mapped[int] = mapped_column(Integer, ForeignKey("lecturer.id"), nullable=False)


class EventsRooms(BaseDbModel):
event_id: Mapped[int] = mapped_column(Integer, ForeignKey("event.id"))
room_id: Mapped[int] = mapped_column(Integer, ForeignKey("room.id"))
event_id: Mapped[int] = mapped_column(Integer, ForeignKey("event.id"), nullable=False)
room_id: Mapped[int] = mapped_column(Integer, ForeignKey("room.id"), nullable=False)


class Photo(BaseDbModel):
lecturer_id: Mapped[int] = mapped_column(Integer, ForeignKey("lecturer.id"))
link: Mapped[int] = mapped_column(String, unique=True)
approve_status: Mapped[int] = mapped_column(DbEnum(ApproveStatuses, native_enum=False), nullable=False)
is_deleted: Mapped[int] = mapped_column(Boolean, default=False)
lecturer_id: Mapped[int] = mapped_column(Integer, ForeignKey("lecturer.id"), nullable=False)
link: Mapped[str] = mapped_column(String, unique=True, nullable=False)
approve_status: Mapped[ApproveStatuses] = mapped_column(DbEnum(ApproveStatuses, native_enum=False), nullable=False)
is_deleted: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False)

lecturer: Mapped[Lecturer] = relationship(
"Lecturer",
Expand All @@ -169,13 +169,13 @@ class Photo(BaseDbModel):


class CommentLecturer(BaseDbModel):
lecturer_id: Mapped[int] = mapped_column(Integer, ForeignKey("lecturer.id"))
author_name: Mapped[int] = mapped_column(String, nullable=False)
text: Mapped[int] = mapped_column(String, nullable=False)
approve_status: Mapped[int] = mapped_column(DbEnum(ApproveStatuses, native_enum=False), nullable=False)
create_ts: Mapped[int] = mapped_column(DateTime, default=datetime.utcnow())
update_ts: Mapped[int] = mapped_column(DateTime, default=datetime.utcnow(), onupdate=datetime.utcnow())
is_deleted: Mapped[int] = mapped_column(Boolean, default=False)
lecturer_id: Mapped[int] = mapped_column(Integer, ForeignKey("lecturer.id"), nullable=False)
author_name: Mapped[str] = mapped_column(String, nullable=False)
text: Mapped[str] = mapped_column(String, nullable=False)
approve_status: Mapped[ApproveStatuses] = mapped_column(DbEnum(ApproveStatuses, native_enum=False), nullable=False)
create_ts: Mapped[datetime] = mapped_column(DateTime, nullable=False, default=datetime.utcnow())
update_ts: Mapped[datetime] = mapped_column(DateTime, nullable=False, default=datetime.utcnow(), onupdate=datetime.utcnow())
is_deleted: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False)

lecturer: Mapped[Lecturer] = relationship(
"Lecturer",
Expand All @@ -186,13 +186,13 @@ class CommentLecturer(BaseDbModel):


class CommentEvent(BaseDbModel):
event_id: Mapped[int] = mapped_column(Integer, ForeignKey("event.id"))
author_name: Mapped[int] = mapped_column(String, nullable=False)
text: Mapped[int] = mapped_column(String, nullable=False)
approve_status: Mapped[int] = mapped_column(DbEnum(ApproveStatuses, native_enum=False), nullable=False)
create_ts: Mapped[int] = mapped_column(DateTime, default=datetime.utcnow())
update_ts: Mapped[int] = mapped_column(DateTime, default=datetime.utcnow(), onupdate=datetime.utcnow())
is_deleted: Mapped[int] = mapped_column(Boolean, default=False)
event_id: Mapped[int] = mapped_column(Integer, ForeignKey("event.id"), nullable=False)
author_name: Mapped[str] = mapped_column(String, nullable=False)
text: Mapped[str] = mapped_column(String, nullable=False)
approve_status: Mapped[ApproveStatuses] = mapped_column(DbEnum(ApproveStatuses, native_enum=False), nullable=False)
create_ts: Mapped[datetime] = mapped_column(DateTime, nullable=False, default=datetime.utcnow())
update_ts: Mapped[datetime] = mapped_column(DateTime, nullable=False, default=datetime.utcnow(), onupdate=datetime.utcnow())
is_deleted: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False)

event: Mapped[Event] = relationship(
"Event",
Expand Down
60 changes: 60 additions & 0 deletions migrations/versions/fe04c8baa5ab_fix_sa20.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
"""Fix sa20

Revision ID: fe04c8baa5ab
Revises: 3948c45f9977
Create Date: 2023-03-20 18:10:29.098467

"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = 'fe04c8baa5ab'
down_revision = '3948c45f9977'
branch_labels = None
depends_on = None


def upgrade():
op.alter_column('comment_event', 'event_id', existing_type=sa.INTEGER(), nullable=False)
op.alter_column('comment_event', 'create_ts', existing_type=postgresql.TIMESTAMP(), nullable=False)
op.alter_column('comment_event', 'update_ts', existing_type=postgresql.TIMESTAMP(), nullable=False)
op.alter_column('comment_event', 'is_deleted', existing_type=sa.BOOLEAN(), nullable=False)
op.alter_column('comment_lecturer', 'lecturer_id', existing_type=sa.INTEGER(), nullable=False)
op.alter_column('comment_lecturer', 'create_ts', existing_type=postgresql.TIMESTAMP(), nullable=False)
op.alter_column('comment_lecturer', 'update_ts', existing_type=postgresql.TIMESTAMP(), nullable=False)
op.alter_column('comment_lecturer', 'is_deleted', existing_type=sa.BOOLEAN(), nullable=False)
op.alter_column('event', 'is_deleted', existing_type=sa.BOOLEAN(), nullable=False)
op.alter_column('events_lecturers', 'event_id', existing_type=sa.INTEGER(), nullable=False)
op.alter_column('events_lecturers', 'lecturer_id', existing_type=sa.INTEGER(), nullable=False)
op.alter_column('events_rooms', 'event_id', existing_type=sa.INTEGER(), nullable=False)
op.alter_column('events_rooms', 'room_id', existing_type=sa.INTEGER(), nullable=False)
op.alter_column('group', 'is_deleted', existing_type=sa.BOOLEAN(), nullable=False)
op.alter_column('lecturer', 'is_deleted', existing_type=sa.BOOLEAN(), nullable=False)
op.alter_column('photo', 'lecturer_id', existing_type=sa.INTEGER(), nullable=False)
op.alter_column('photo', 'link', existing_type=sa.VARCHAR(), nullable=False)
op.alter_column('photo', 'is_deleted', existing_type=sa.BOOLEAN(), nullable=False)
op.alter_column('room', 'is_deleted', existing_type=sa.BOOLEAN(), nullable=False)


def downgrade():
op.alter_column('room', 'is_deleted', existing_type=sa.BOOLEAN(), nullable=True)
op.alter_column('photo', 'is_deleted', existing_type=sa.BOOLEAN(), nullable=True)
op.alter_column('photo', 'link', existing_type=sa.VARCHAR(), nullable=True)
op.alter_column('photo', 'lecturer_id', existing_type=sa.INTEGER(), nullable=True)
op.alter_column('lecturer', 'is_deleted', existing_type=sa.BOOLEAN(), nullable=True)
op.alter_column('group', 'is_deleted', existing_type=sa.BOOLEAN(), nullable=True)
op.alter_column('events_rooms', 'room_id', existing_type=sa.INTEGER(), nullable=True)
op.alter_column('events_rooms', 'event_id', existing_type=sa.INTEGER(), nullable=True)
op.alter_column('events_lecturers', 'lecturer_id', existing_type=sa.INTEGER(), nullable=True)
op.alter_column('events_lecturers', 'event_id', existing_type=sa.INTEGER(), nullable=True)
op.alter_column('event', 'is_deleted', existing_type=sa.BOOLEAN(), nullable=True)
op.alter_column('comment_lecturer', 'is_deleted', existing_type=sa.BOOLEAN(), nullable=True)
op.alter_column('comment_lecturer', 'update_ts', existing_type=postgresql.TIMESTAMP(), nullable=True)
op.alter_column('comment_lecturer', 'create_ts', existing_type=postgresql.TIMESTAMP(), nullable=True)
op.alter_column('comment_lecturer', 'lecturer_id', existing_type=sa.INTEGER(), nullable=True)
op.alter_column('comment_event', 'is_deleted', existing_type=sa.BOOLEAN(), nullable=True)
op.alter_column('comment_event', 'update_ts', existing_type=postgresql.TIMESTAMP(), nullable=True)
op.alter_column('comment_event', 'create_ts', existing_type=postgresql.TIMESTAMP(), nullable=True)
op.alter_column('comment_event', 'event_id', existing_type=sa.INTEGER(), nullable=True)