Skip to content

Commit

Permalink
Добавляет миграции, создающие основные таблицы
Browse files Browse the repository at this point in the history
  • Loading branch information
codEnjoyer committed Nov 2, 2023
1 parent 3164b94 commit baab615
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 1 deletion.
15 changes: 14 additions & 1 deletion backend/migrations/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,21 @@
# from myapp import mymodel
# target_metadata = mymodel.Base.metadata

from game.map.models import Map
from game.modules.models import Module
from game.levels.models import Level
from game.units.tasks.models import Task
from game.units.theory.models import Theory, TheoryVideo

from users.models import User
from users.tutors.models import Tutor
from users.employees.models import Employee

from database import BaseModel


# TODO: Добавить metadata из моделей
target_metadata = None
target_metadata = BaseModel.metadata


# other values from the config, defined by the needs of env.py,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
"""Добавляет таблицы пользователей
Revision ID: ea5f600c8967
Revises:
Create Date: 2023-11-02 17:07:33.234938
"""
from typing import Sequence, Union

import fastapi_users_db_sqlalchemy
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = 'ea5f600c8967'
down_revision: Union[str, None] = None
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.create_table('employees',
sa.Column('id', sa.UUID(), nullable=False),
sa.Column('name', sa.String(length=255), nullable=False),
sa.Column('last_name', sa.String(length=255), nullable=False),
sa.Column('email', sa.String(length=255), nullable=False),
sa.Column('hired_at', sa.Date(), server_default=sa.text('CURRENT_DATE'), nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('email')
)
op.create_table('tutors',
sa.Column('id', sa.UUID(), nullable=False),
sa.Column('name', sa.String(length=255), nullable=False),
sa.Column('last_name', sa.String(length=255), nullable=False),
sa.Column('email', sa.String(length=255), nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('email')
)
op.create_table('users',
sa.Column('role', sa.Enum(name='user_roles'), nullable=False),
sa.Column('id', fastapi_users_db_sqlalchemy.generics.GUID(), nullable=False),
sa.Column('email', sa.String(length=320), nullable=False),
sa.Column('hashed_password', sa.String(length=1024), nullable=False),
sa.Column('is_active', sa.Boolean(), nullable=False),
sa.Column('is_superuser', sa.Boolean(), nullable=False),
sa.Column('is_verified', sa.Boolean(), nullable=False),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_users_email'), 'users', ['email'], unique=True)
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(op.f('ix_users_email'), table_name='users')
op.drop_table('users')
op.drop_table('tutors')
op.drop_table('employees')
# ### end Alembic commands ###
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
"""Добавляет основу для заданий
Revision ID: 6e79091c3fb1
Revises: ea5f600c8967
Create Date: 2023-11-02 17:09:18.002665
"""
from typing import Sequence, Union

import sqlalchemy_utils
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = '6e79091c3fb1'
down_revision: Union[str, None] = 'ea5f600c8967'
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.create_table('levels',
sa.Column('id', sa.UUID(), nullable=False),
sa.Column('name', sa.String(length=255), nullable=False),
sa.Column('is_accomplished', sa.Boolean(), nullable=False),
sa.PrimaryKeyConstraint('id')
)
op.create_table('maps',
sa.Column('id', sa.UUID(), nullable=False),
sa.Column('name', sa.String(length=255), nullable=False),
sa.PrimaryKeyConstraint('id')
)
op.create_table('modules',
sa.Column('id', sa.UUID(), nullable=False),
sa.Column('name', sa.String(length=255), nullable=False),
sa.PrimaryKeyConstraint('id')
)
op.create_table('tasks',
sa.Column('id', sa.UUID(), nullable=False),
sa.Column('is_accomplished', sa.Boolean(), nullable=False),
sa.Column('score_reward', sa.Integer(), nullable=False),
sa.Column('content', sa.Text(), nullable=False),
sa.PrimaryKeyConstraint('id')
)
op.create_table('theory_blocks',
sa.Column('id', sa.UUID(), nullable=False),
sa.Column('theme', sa.String(), nullable=False),
sa.Column('content', sa.Text(), nullable=False),
sa.PrimaryKeyConstraint('id')
)
op.create_table('theory_videos',
sa.Column('id', sa.UUID(), nullable=False),
sa.Column('url', sqlalchemy_utils.types.url.URLType(), nullable=False),
sa.PrimaryKeyConstraint('id')
)
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('theory_videos')
op.drop_table('theory_blocks')
op.drop_table('tasks')
op.drop_table('modules')
op.drop_table('maps')
op.drop_table('levels')
# ### end Alembic commands ###

0 comments on commit baab615

Please sign in to comment.