From 5b1f533f534e46528d2a79b183144061c85e625b Mon Sep 17 00:00:00 2001 From: codEnjoyer Date: Thu, 2 Nov 2023 17:33:50 +0500 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D1=8F?= =?UTF-8?q?=D0=B5=D1=82=20=D0=B2=D0=BD=D0=B5=D1=88=D0=BD=D0=B8=D0=B5=20?= =?UTF-8?q?=D0=BA=D0=BB=D1=8E=D1=87=D0=B8=20=D0=BA=20=D1=82=D0=B0=D0=B1?= =?UTF-8?q?=D0=BB=D0=B8=D1=86=D0=B0=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...20\272\320\273\321\216\321\207\320\270.py" | 48 +++++++++++++++++++ backend/src/game/levels/models.py | 3 +- backend/src/game/modules/models.py | 6 ++- backend/src/game/units/tasks/models.py | 1 + backend/src/game/units/theory/models.py | 3 +- backend/src/users/employees/models.py | 3 +- 6 files changed, 59 insertions(+), 5 deletions(-) create mode 100644 "backend/migrations/versions/2023_11_02_1733-5aa9681ef1db_\320\264\320\276\320\261\320\260\320\262\320\273\321\217\320\265\321\202_\320\262\320\275\320\265\321\210\320\275\320\270\320\265_\320\272\320\273\321\216\321\207\320\270.py" diff --git "a/backend/migrations/versions/2023_11_02_1733-5aa9681ef1db_\320\264\320\276\320\261\320\260\320\262\320\273\321\217\320\265\321\202_\320\262\320\275\320\265\321\210\320\275\320\270\320\265_\320\272\320\273\321\216\321\207\320\270.py" "b/backend/migrations/versions/2023_11_02_1733-5aa9681ef1db_\320\264\320\276\320\261\320\260\320\262\320\273\321\217\320\265\321\202_\320\262\320\275\320\265\321\210\320\275\320\270\320\265_\320\272\320\273\321\216\321\207\320\270.py" new file mode 100644 index 0000000..314852b --- /dev/null +++ "b/backend/migrations/versions/2023_11_02_1733-5aa9681ef1db_\320\264\320\276\320\261\320\260\320\262\320\273\321\217\320\265\321\202_\320\262\320\275\320\265\321\210\320\275\320\270\320\265_\320\272\320\273\321\216\321\207\320\270.py" @@ -0,0 +1,48 @@ +"""Добавляет внешние ключи + +Revision ID: 5aa9681ef1db +Revises: 6e79091c3fb1 +Create Date: 2023-11-02 17:33:20.640710 + +""" +from typing import Sequence, Union + +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision: str = '5aa9681ef1db' +down_revision: Union[str, None] = '6e79091c3fb1' +branch_labels: Union[str, Sequence[str], None] = None +depends_on: Union[str, Sequence[str], None] = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.add_column('employees', sa.Column('tutor_id', sa.UUID(), nullable=False)) + op.create_foreign_key(None, 'employees', 'tutors', ['tutor_id'], ['id']) + op.add_column('levels', sa.Column('module_id', sa.UUID(), nullable=False)) + op.create_foreign_key(None, 'levels', 'modules', ['module_id'], ['id']) + op.add_column('modules', sa.Column('previous_module_id', sa.UUID(), nullable=False)) + op.add_column('modules', sa.Column('next_module_id', sa.UUID(), nullable=False)) + op.create_foreign_key(None, 'modules', 'modules', ['next_module_id'], ['id']) + op.create_foreign_key(None, 'modules', 'modules', ['previous_module_id'], ['id']) + op.add_column('theory_videos', sa.Column('theory_id', sa.UUID(), nullable=False)) + op.create_foreign_key(None, 'theory_videos', 'theory_blocks', ['theory_id'], ['id']) + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.drop_constraint(None, 'theory_videos', type_='foreignkey') + op.drop_column('theory_videos', 'theory_id') + op.drop_constraint(None, 'modules', type_='foreignkey') + op.drop_constraint(None, 'modules', type_='foreignkey') + op.drop_column('modules', 'next_module_id') + op.drop_column('modules', 'previous_module_id') + op.drop_constraint(None, 'levels', type_='foreignkey') + op.drop_column('levels', 'module_id') + op.drop_constraint(None, 'employees', type_='foreignkey') + op.drop_column('employees', 'tutor_id') + # ### end Alembic commands ### diff --git a/backend/src/game/levels/models.py b/backend/src/game/levels/models.py index 3245f55..6487f3f 100644 --- a/backend/src/game/levels/models.py +++ b/backend/src/game/levels/models.py @@ -1,7 +1,7 @@ import typing import uuid -from sqlalchemy import String, Boolean, UUID +from sqlalchemy import String, Boolean, UUID, ForeignKey from sqlalchemy.orm import Mapped, mapped_column, relationship from database import BaseModel @@ -16,6 +16,7 @@ class Level(BaseModel): __tablename__ = 'levels' id: Mapped[uuid.UUID] = mapped_column(UUID, primary_key=True, default=uuid.uuid4) + module_id: Mapped[uuid.UUID] = mapped_column(UUID, ForeignKey('modules.id'), nullable=False) name: Mapped[str] = mapped_column(String(length=255), nullable=False) is_accomplished: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False) diff --git a/backend/src/game/modules/models.py b/backend/src/game/modules/models.py index 39dfd36..f91183e 100644 --- a/backend/src/game/modules/models.py +++ b/backend/src/game/modules/models.py @@ -1,7 +1,7 @@ import typing import uuid -from sqlalchemy import String, UUID +from sqlalchemy import String, UUID, ForeignKey from sqlalchemy.orm import Mapped, mapped_column, relationship from database import BaseModel @@ -14,8 +14,10 @@ class Module(BaseModel): __tablename__ = 'modules' id: Mapped[uuid.UUID] = mapped_column(UUID, primary_key=True, default=uuid.uuid4) + previous_module_id: Mapped[uuid.UUID] = mapped_column(UUID, ForeignKey('modules.id'), nullable=False) + next_module_id: Mapped[uuid.UUID] = mapped_column(UUID, ForeignKey('modules.id'), nullable=False) name: Mapped[str] = mapped_column(String(length=255), nullable=False) levels: Mapped[list["Level"]] = relationship(back_populates='module') - previous_module: Mapped["Module"] = relationship(back_populates='next_module') next_module: Mapped["Module"] = relationship(back_populates='previous_module') + previous_module: Mapped["Module"] = relationship(back_populates='next_module') diff --git a/backend/src/game/units/tasks/models.py b/backend/src/game/units/tasks/models.py index d2656d5..017f358 100644 --- a/backend/src/game/units/tasks/models.py +++ b/backend/src/game/units/tasks/models.py @@ -11,6 +11,7 @@ class Task(BaseModel): id: Mapped[uuid.UUID] = mapped_column(UUID, primary_key=True, default=uuid.uuid4) is_accomplished: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False) + # TODO: Задание не может быть выполнено глобально, нужна таблица для выполненных заданий пользователями # requires_review: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False) score_reward: Mapped[int] = mapped_column(Integer, nullable=False, default=1) content: Mapped[str] = mapped_column(Text, nullable=False, default="Текст задания") diff --git a/backend/src/game/units/theory/models.py b/backend/src/game/units/theory/models.py index dcc2ee1..839457f 100644 --- a/backend/src/game/units/theory/models.py +++ b/backend/src/game/units/theory/models.py @@ -1,6 +1,6 @@ import uuid -from sqlalchemy import UUID, Text, String, URL +from sqlalchemy import UUID, Text, String, URL, ForeignKey from sqlalchemy.orm import Mapped, mapped_column, relationship from sqlalchemy_utils import URLType @@ -21,6 +21,7 @@ class TheoryVideo(BaseModel): __tablename__ = 'theory_videos' id: Mapped[uuid.UUID] = mapped_column(UUID, primary_key=True, default=uuid.uuid4) + theory_id: Mapped[uuid.UUID] = mapped_column(UUID, ForeignKey('theory_blocks.id'), nullable=False) url: Mapped[URL] = mapped_column(URLType, nullable=False) theory: Mapped["Theory"] = relationship(back_populates="theory_video") diff --git a/backend/src/users/employees/models.py b/backend/src/users/employees/models.py index f7f1ba7..5f9c8f4 100644 --- a/backend/src/users/employees/models.py +++ b/backend/src/users/employees/models.py @@ -3,7 +3,7 @@ import datetime from pydantic import EmailStr -from sqlalchemy import UUID, String, Date, func +from sqlalchemy import UUID, String, Date, func, ForeignKey from sqlalchemy.orm import Mapped, mapped_column, relationship from database import BaseModel @@ -16,6 +16,7 @@ class Employee(BaseModel): __tablename__ = "employees" id: Mapped[uuid.UUID] = mapped_column(UUID, primary_key=True, default=uuid.uuid4) + tutor_id: Mapped[uuid.UUID] = mapped_column(UUID, ForeignKey('tutors.id'), nullable=False) name: Mapped[str] = mapped_column(String(length=255), nullable=False) last_name: Mapped[str] = mapped_column(String(length=255), nullable=False) email: Mapped[EmailStr] = mapped_column(String(length=255), nullable=False, unique=True)