From 6041c6179dc3685252d3c8ebe12a4e1213f2f7ba Mon Sep 17 00:00:00 2001 From: Sovraska Date: Sat, 16 Dec 2023 22:10:09 +0300 Subject: [PATCH] fix after merge --- .../2348e4831674_fix_models_relationships.py | 28 ---- alembic/versions/f880265a392e_models.py | 156 ------------------ app/api/endpoints/course.py | 2 +- app/api/endpoints/profile.py | 2 +- app/schemas/profile.py | 1 + app/schemas/tariff.py | 4 +- 6 files changed, 5 insertions(+), 188 deletions(-) delete mode 100644 alembic/versions/2348e4831674_fix_models_relationships.py delete mode 100644 alembic/versions/f880265a392e_models.py diff --git a/alembic/versions/2348e4831674_fix_models_relationships.py b/alembic/versions/2348e4831674_fix_models_relationships.py deleted file mode 100644 index 2974382..0000000 --- a/alembic/versions/2348e4831674_fix_models_relationships.py +++ /dev/null @@ -1,28 +0,0 @@ -"""fix models relationships - -Revision ID: 2348e4831674 -Revises: f880265a392e -Create Date: 2023-12-11 13:25:35.014265 - -""" -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '2348e4831674' -down_revision = 'f880265a392e' -branch_labels = None -depends_on = None - - -def upgrade(): - # ### commands auto generated by Alembic - please adjust! ### - pass - # ### end Alembic commands ### - - -def downgrade(): - # ### commands auto generated by Alembic - please adjust! ### - pass - # ### end Alembic commands ### diff --git a/alembic/versions/f880265a392e_models.py b/alembic/versions/f880265a392e_models.py deleted file mode 100644 index 42e7f14..0000000 --- a/alembic/versions/f880265a392e_models.py +++ /dev/null @@ -1,156 +0,0 @@ -"""models - -Revision ID: f880265a392e -Revises: 4098f76764d4 -Create Date: 2023-12-09 05:40:57.506690 - -""" -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = 'f880265a392e' -down_revision = '4098f76764d4' -branch_labels = None -depends_on = None - - -def upgrade(): - # ### commands auto generated by Alembic - please adjust! ### - op.create_table('achievement', - sa.Column('name', sa.String(length=100), nullable=False), - sa.Column('description', sa.Text(), nullable=True), - sa.Column('id', sa.Integer(), nullable=False), - sa.PrimaryKeyConstraint('id'), - sa.UniqueConstraint('name') - ) - op.create_table('course', - sa.Column('name', sa.String(length=100), nullable=False), - sa.Column('description', sa.Text(), nullable=True), - sa.Column('id', sa.Integer(), nullable=False), - sa.PrimaryKeyConstraint('id'), - sa.UniqueConstraint('name') - ) - op.create_table('examination', - sa.Column('name', sa.String(length=100), nullable=False), - sa.Column('description', sa.Text(), nullable=True), - sa.Column('id', sa.Integer(), nullable=False), - sa.PrimaryKeyConstraint('id'), - sa.UniqueConstraint('name') - ) - op.create_table('group', - sa.Column('name', sa.String(length=100), nullable=False), - sa.Column('description', sa.Text(), nullable=True), - sa.Column('id', sa.Integer(), nullable=False), - sa.PrimaryKeyConstraint('id'), - sa.UniqueConstraint('name') - ) - op.create_table('notification', - sa.Column('id', sa.Integer(), nullable=False), - sa.PrimaryKeyConstraint('id') - ) - op.create_table('tariff', - sa.Column('name', sa.String(length=100), nullable=False), - sa.Column('description', sa.Text(), nullable=True), - sa.Column('id', sa.Integer(), nullable=False), - sa.PrimaryKeyConstraint('id'), - sa.UniqueConstraint('name') - ) - op.create_table('task', - sa.Column('name', sa.String(length=100), nullable=False), - sa.Column('description', sa.Text(), nullable=True), - sa.Column('id', sa.Integer(), nullable=False), - sa.PrimaryKeyConstraint('id'), - sa.UniqueConstraint('name') - ) - op.create_table('course_tariff_association', - sa.Column('course_id', sa.Integer(), nullable=True), - sa.Column('tariff_id', sa.Integer(), nullable=True), - sa.ForeignKeyConstraint(['course_id'], ['course.id'], ), - sa.ForeignKeyConstraint(['tariff_id'], ['tariff.id'], ) - ) - op.create_table('course_task_association', - sa.Column('course_id', sa.Integer(), nullable=True), - sa.Column('task_id', sa.Integer(), nullable=True), - sa.ForeignKeyConstraint(['course_id'], ['course.id'], ), - sa.ForeignKeyConstraint(['task_id'], ['task.id'], ) - ) - op.create_table('group_user_association', - sa.Column('user_id', sa.Integer(), nullable=True), - sa.Column('group_id', sa.Integer(), nullable=True), - sa.ForeignKeyConstraint(['group_id'], ['group.id'], ), - sa.ForeignKeyConstraint(['user_id'], ['user.id'], ) - ) - op.create_table('profile', - sa.Column('first_name', sa.String(length=100), nullable=True), - sa.Column('second_name', sa.String(length=100), nullable=True), - sa.Column('age', sa.SmallInteger(), nullable=True), - sa.Column('user_id', sa.Integer(), nullable=True), - sa.Column('id', sa.Integer(), nullable=False), - sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), - sa.PrimaryKeyConstraint('id') - ) - op.create_table('user_notification_association', - sa.Column('user_id', sa.Integer(), nullable=True), - sa.Column('notification_id', sa.Integer(), nullable=True), - sa.ForeignKeyConstraint(['notification_id'], ['notification.id'], ), - sa.ForeignKeyConstraint(['user_id'], ['user.id'], ) - ) - op.create_table('usercourse', - sa.Column('user_id', sa.Integer(), nullable=False), - sa.Column('course_id', sa.Integer(), nullable=False), - sa.Column('progress', sa.SmallInteger(), nullable=True), - sa.Column('id', sa.Integer(), nullable=False), - sa.ForeignKeyConstraint(['course_id'], ['course.id'], ), - sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), - sa.PrimaryKeyConstraint('user_id', 'course_id', 'id') - ) - op.create_table('userexamination', - sa.Column('user_id', sa.Integer(), nullable=False), - sa.Column('examination_id', sa.Integer(), nullable=False), - sa.Column('progress', sa.SmallInteger(), nullable=True), - sa.Column('id', sa.Integer(), nullable=False), - sa.ForeignKeyConstraint(['examination_id'], ['examination.id'], ), - sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), - sa.PrimaryKeyConstraint('user_id', 'examination_id', 'id') - ) - op.create_table('achievement_profile_association', - sa.Column('profile_id', sa.Integer(), nullable=True), - sa.Column('achievement_id', sa.Integer(), nullable=True), - sa.ForeignKeyConstraint(['achievement_id'], ['achievement.id'], ), - sa.ForeignKeyConstraint(['profile_id'], ['profile.id'], ) - ) - with op.batch_alter_table('user', schema=None) as batch_op: - batch_op.add_column(sa.Column('role', sa.Enum('user', 'manager', 'admin', name='userroleenum'), nullable=False)) - batch_op.add_column(sa.Column('username', sa.String(length=100), nullable=False)) - batch_op.add_column(sa.Column('tariff_id', sa.Integer(), nullable=True)) - batch_op.create_foreign_key('fk_user_tariff_id_tariff', 'tariff', ['tariff_id'], ['id']) - - # ### end Alembic commands ### - - -def downgrade(): - # ### commands auto generated by Alembic - please adjust! ### - with op.batch_alter_table('user', schema=None) as batch_op: - batch_op.drop_constraint(None, type_='foreignkey') - batch_op.drop_column('tariff_id') - batch_op.drop_column('username') - batch_op.drop_column('role') - - op.drop_table('achievement_profile_association') - op.drop_table('userexamination') - op.drop_table('usercourse') - op.drop_table('user_notification_association') - op.drop_table('profile') - op.drop_table('group_user_association') - op.drop_table('course_task_association') - op.drop_table('course_tariff_association') - op.drop_table('task') - op.drop_table('tariff') - op.drop_table('notification') - op.drop_table('group') - op.drop_table('examination') - op.drop_table('course') - op.drop_table('achievement') - # ### end Alembic commands ### diff --git a/app/api/endpoints/course.py b/app/api/endpoints/course.py index 87bcfda..ef3cd88 100644 --- a/app/api/endpoints/course.py +++ b/app/api/endpoints/course.py @@ -24,7 +24,7 @@ async def create_course( session: AsyncSession = Depends(get_async_session) ): """Создать Course""" - await check_name_duplicate(course.name, CourseCreate, session) + await check_name_duplicate(course.name, course_crud, session) return await course_crud.create( obj_in=course, session=session ) diff --git a/app/api/endpoints/profile.py b/app/api/endpoints/profile.py index 9027ec9..f387bf9 100644 --- a/app/api/endpoints/profile.py +++ b/app/api/endpoints/profile.py @@ -33,7 +33,7 @@ async def create_profile( obj_id=profile.user_id, crud=user_crud, session=session ) return await profile_crud.create( - obj_in=profile, session=session + obj_in=profile, user_id=profile.user_id, session=session ) diff --git a/app/schemas/profile.py b/app/schemas/profile.py index 9122095..fdfb04a 100644 --- a/app/schemas/profile.py +++ b/app/schemas/profile.py @@ -18,3 +18,4 @@ class ProfileCreate(BaseModel): first_name: Optional[str] last_name: Optional[str] age: Optional[int] + user_id: int diff --git a/app/schemas/tariff.py b/app/schemas/tariff.py index 0f755b3..25c584d 100644 --- a/app/schemas/tariff.py +++ b/app/schemas/tariff.py @@ -12,12 +12,12 @@ class Config: from_attributes = True -class TarifCreate(BaseModel): +class TariffCreate(BaseModel): name: str description: Optional[str] -class TariffCreated(TarifCreate): +class TariffCreated(TariffCreate): id: int class Config: