создал миграции, исправил связи
This commit is contained in:
parent
9b5b9516cc
commit
c0f0293ce7
1
.gitignore
vendored
1
.gitignore
vendored
@ -4,3 +4,4 @@ API/.idea
|
|||||||
|
|
||||||
API/.venv/
|
API/.venv/
|
||||||
API/.idea/
|
API/.idea/
|
||||||
|
API/.env
|
||||||
|
|||||||
@ -0,0 +1,169 @@
|
|||||||
|
"""0001_инициализация
|
||||||
|
|
||||||
|
Revision ID: d53be3a35511
|
||||||
|
Revises:
|
||||||
|
Create Date: 2025-04-13 13:16:29.461322
|
||||||
|
|
||||||
|
"""
|
||||||
|
from typing import Sequence, Union
|
||||||
|
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
from sqlalchemy.dialects import mysql
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision: str = 'd53be3a35511'
|
||||||
|
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:
|
||||||
|
"""Upgrade schema."""
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.create_table('contest_statuses',
|
||||||
|
sa.Column('title', sa.VARCHAR(length=150), nullable=False),
|
||||||
|
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||||||
|
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
|
||||||
|
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
|
||||||
|
sa.PrimaryKeyConstraint('id'),
|
||||||
|
sa.UniqueConstraint('title')
|
||||||
|
)
|
||||||
|
op.create_table('projects',
|
||||||
|
sa.Column('description', sa.VARCHAR(length=150), nullable=True),
|
||||||
|
sa.Column('repository_url', sa.String(), nullable=False),
|
||||||
|
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||||||
|
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
|
||||||
|
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
|
||||||
|
sa.PrimaryKeyConstraint('id')
|
||||||
|
)
|
||||||
|
op.create_table('roles',
|
||||||
|
sa.Column('title', mysql.VARCHAR(length=150), nullable=False),
|
||||||
|
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||||||
|
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
|
||||||
|
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
|
||||||
|
sa.PrimaryKeyConstraint('id'),
|
||||||
|
sa.UniqueConstraint('title')
|
||||||
|
)
|
||||||
|
op.create_table('teams',
|
||||||
|
sa.Column('title', sa.VARCHAR(length=150), nullable=False),
|
||||||
|
sa.Column('description', sa.VARCHAR(length=150), nullable=True),
|
||||||
|
sa.Column('logo', sa.String(), nullable=True),
|
||||||
|
sa.Column('git_url', sa.String(), nullable=True),
|
||||||
|
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||||||
|
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
|
||||||
|
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
|
||||||
|
sa.PrimaryKeyConstraint('id')
|
||||||
|
)
|
||||||
|
op.create_table('contests',
|
||||||
|
sa.Column('title', sa.VARCHAR(length=150), nullable=False),
|
||||||
|
sa.Column('description', sa.String(), nullable=True),
|
||||||
|
sa.Column('web_url', sa.String(), nullable=False),
|
||||||
|
sa.Column('photo', sa.String(), nullable=True),
|
||||||
|
sa.Column('results', sa.String(), nullable=True),
|
||||||
|
sa.Column('is_win', sa.Boolean(), nullable=True),
|
||||||
|
sa.Column('project_id', sa.Integer(), nullable=False),
|
||||||
|
sa.Column('status_id', sa.Integer(), nullable=False),
|
||||||
|
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||||||
|
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
|
||||||
|
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
|
||||||
|
sa.ForeignKeyConstraint(['project_id'], ['projects.id'], ),
|
||||||
|
sa.ForeignKeyConstraint(['status_id'], ['contest_statuses.id'], ),
|
||||||
|
sa.PrimaryKeyConstraint('id'),
|
||||||
|
sa.UniqueConstraint('title')
|
||||||
|
)
|
||||||
|
op.create_table('profiles',
|
||||||
|
sa.Column('first_name', sa.VARCHAR(length=150), nullable=False),
|
||||||
|
sa.Column('last_name', sa.VARCHAR(length=150), nullable=False),
|
||||||
|
sa.Column('patronymic', sa.VARCHAR(length=150), nullable=True),
|
||||||
|
sa.Column('birthday', sa.Date(), nullable=False),
|
||||||
|
sa.Column('email', sa.VARCHAR(length=150), nullable=True),
|
||||||
|
sa.Column('phone', sa.VARCHAR(length=28), nullable=True),
|
||||||
|
sa.Column('role_id', sa.Integer(), nullable=False),
|
||||||
|
sa.Column('team_id', sa.Integer(), nullable=False),
|
||||||
|
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||||||
|
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
|
||||||
|
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
|
||||||
|
sa.ForeignKeyConstraint(['role_id'], ['roles.id'], ),
|
||||||
|
sa.ForeignKeyConstraint(['team_id'], ['teams.id'], ),
|
||||||
|
sa.PrimaryKeyConstraint('id')
|
||||||
|
)
|
||||||
|
op.create_table('project_files',
|
||||||
|
sa.Column('file_path', sa.String(), nullable=False),
|
||||||
|
sa.Column('project_id', sa.Integer(), nullable=False),
|
||||||
|
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||||||
|
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
|
||||||
|
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
|
||||||
|
sa.ForeignKeyConstraint(['project_id'], ['projects.id'], ),
|
||||||
|
sa.PrimaryKeyConstraint('id'),
|
||||||
|
sa.UniqueConstraint('file_path')
|
||||||
|
)
|
||||||
|
op.create_table('contest_carousel_photos',
|
||||||
|
sa.Column('file_path', sa.String(), nullable=False),
|
||||||
|
sa.Column('number', sa.Integer(), nullable=False),
|
||||||
|
sa.Column('contest_id', sa.Integer(), nullable=False),
|
||||||
|
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||||||
|
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
|
||||||
|
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
|
||||||
|
sa.ForeignKeyConstraint(['contest_id'], ['contests.id'], ),
|
||||||
|
sa.PrimaryKeyConstraint('id')
|
||||||
|
)
|
||||||
|
op.create_table('contest_files',
|
||||||
|
sa.Column('file_path', sa.String(), nullable=False),
|
||||||
|
sa.Column('contest_id', sa.Integer(), nullable=False),
|
||||||
|
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||||||
|
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
|
||||||
|
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
|
||||||
|
sa.ForeignKeyConstraint(['contest_id'], ['contests.id'], ),
|
||||||
|
sa.PrimaryKeyConstraint('id')
|
||||||
|
)
|
||||||
|
op.create_table('profile_photos',
|
||||||
|
sa.Column('file_path', sa.String(), nullable=False),
|
||||||
|
sa.Column('profile_id', sa.Integer(), nullable=False),
|
||||||
|
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||||||
|
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
|
||||||
|
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
|
||||||
|
sa.ForeignKeyConstraint(['profile_id'], ['profiles.id'], ),
|
||||||
|
sa.PrimaryKeyConstraint('id')
|
||||||
|
)
|
||||||
|
op.create_table('project_members',
|
||||||
|
sa.Column('description', sa.String(), nullable=True),
|
||||||
|
sa.Column('project_id', sa.Integer(), nullable=False),
|
||||||
|
sa.Column('profile_id', sa.Integer(), nullable=False),
|
||||||
|
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||||||
|
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
|
||||||
|
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
|
||||||
|
sa.ForeignKeyConstraint(['profile_id'], ['profiles.id'], ),
|
||||||
|
sa.ForeignKeyConstraint(['project_id'], ['projects.id'], ),
|
||||||
|
sa.PrimaryKeyConstraint('id')
|
||||||
|
)
|
||||||
|
op.create_table('users',
|
||||||
|
sa.Column('login', sa.VARCHAR(length=150), nullable=False),
|
||||||
|
sa.Column('password', sa.VARCHAR(length=150), nullable=False),
|
||||||
|
sa.Column('profile_id', sa.Integer(), nullable=False),
|
||||||
|
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||||||
|
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
|
||||||
|
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
|
||||||
|
sa.ForeignKeyConstraint(['profile_id'], ['profiles.id'], ),
|
||||||
|
sa.PrimaryKeyConstraint('id'),
|
||||||
|
sa.UniqueConstraint('login')
|
||||||
|
)
|
||||||
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade() -> None:
|
||||||
|
"""Downgrade schema."""
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.drop_table('users')
|
||||||
|
op.drop_table('project_members')
|
||||||
|
op.drop_table('profile_photos')
|
||||||
|
op.drop_table('contest_files')
|
||||||
|
op.drop_table('contest_carousel_photos')
|
||||||
|
op.drop_table('project_files')
|
||||||
|
op.drop_table('profiles')
|
||||||
|
op.drop_table('contests')
|
||||||
|
op.drop_table('teams')
|
||||||
|
op.drop_table('roles')
|
||||||
|
op.drop_table('projects')
|
||||||
|
op.drop_table('contest_statuses')
|
||||||
|
# ### end Alembic commands ###
|
||||||
@ -1,3 +1,16 @@
|
|||||||
from sqlalchemy.ext.declarative import declarative_base
|
from sqlalchemy.ext.declarative import declarative_base
|
||||||
|
|
||||||
Base = declarative_base()
|
Base = declarative_base()
|
||||||
|
|
||||||
|
from app.domain.models.contest_carousel_photos import ContestCarouselPhoto
|
||||||
|
from app.domain.models.contest_files import ContestFile
|
||||||
|
from app.domain.models.contests import Contest
|
||||||
|
from app.domain.models.contest_statuses import ContestStatus
|
||||||
|
from app.domain.models.projects import Project
|
||||||
|
from app.domain.models.project_files import ProjectFile
|
||||||
|
from app.domain.models.users import User
|
||||||
|
from app.domain.models.profiles import Profile
|
||||||
|
from app.domain.models.roles import Role
|
||||||
|
from app.domain.models.teams import Team
|
||||||
|
from app.domain.models.project_members import ProjectMember
|
||||||
|
from app.domain.models.profile_photos import ProfilePhoto
|
||||||
|
|||||||
@ -15,7 +15,7 @@ class Contest(AdvancedBaseModel):
|
|||||||
is_win = Column(Boolean)
|
is_win = Column(Boolean)
|
||||||
|
|
||||||
project_id = Column(Integer, ForeignKey('projects.id'), nullable=False)
|
project_id = Column(Integer, ForeignKey('projects.id'), nullable=False)
|
||||||
status_id = Column(Integer, ForeignKey('contest_status.id'), nullable=False)
|
status_id = Column(Integer, ForeignKey('contest_statuses.id'), nullable=False)
|
||||||
|
|
||||||
project = relationship('Project', back_populates='contests')
|
project = relationship('Project', back_populates='contests')
|
||||||
status = relationship('ContestStatus', back_populates='contests')
|
status = relationship('ContestStatus', back_populates='contests')
|
||||||
|
|||||||
14
API/app/domain/models/profile_photos.py
Normal file
14
API/app/domain/models/profile_photos.py
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
from sqlalchemy import Column, String, Integer, ForeignKey
|
||||||
|
from sqlalchemy.orm import relationship
|
||||||
|
|
||||||
|
from app.domain.models.base import AdvancedBaseModel
|
||||||
|
|
||||||
|
|
||||||
|
class ProfilePhoto(AdvancedBaseModel):
|
||||||
|
__tablename__ = 'profile_photos'
|
||||||
|
|
||||||
|
file_path = Column(String, nullable=False)
|
||||||
|
|
||||||
|
profile_id = Column(Integer, ForeignKey('profiles.id'), nullable=False)
|
||||||
|
|
||||||
|
profile = relationship('Profile', back_populates='photos')
|
||||||
@ -21,3 +21,5 @@ class Profile(AdvancedBaseModel):
|
|||||||
team = relationship('Team', back_populates='profiles')
|
team = relationship('Team', back_populates='profiles')
|
||||||
|
|
||||||
user = relationship('User', back_populates='profile')
|
user = relationship('User', back_populates='profile')
|
||||||
|
profile_photo = relationship('ProfilePhoto', back_populates='profile')
|
||||||
|
projects = relationship('ProjectMember', back_populates='profile')
|
||||||
|
|||||||
16
API/app/domain/models/project_members.py
Normal file
16
API/app/domain/models/project_members.py
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
from sqlalchemy import Column, Integer, ForeignKey, String
|
||||||
|
from sqlalchemy.orm import relationship
|
||||||
|
|
||||||
|
from app.domain.models.base import AdvancedBaseModel
|
||||||
|
|
||||||
|
|
||||||
|
class ProjectMember(AdvancedBaseModel):
|
||||||
|
__tablename__ = 'project_members'
|
||||||
|
|
||||||
|
description = Column(String)
|
||||||
|
|
||||||
|
project_id = Column(Integer, ForeignKey('projects.id'), nullable=False)
|
||||||
|
profile_id = Column(Integer, ForeignKey('profiles.id'), nullable=False)
|
||||||
|
|
||||||
|
project = relationship('Project', back_populates='members')
|
||||||
|
profile = relationship('Profile', back_populates='projects')
|
||||||
@ -12,3 +12,4 @@ class Project(AdvancedBaseModel):
|
|||||||
|
|
||||||
contest = relationship("Contest", back_populates="project")
|
contest = relationship("Contest", back_populates="project")
|
||||||
files = relationship("ProjectFile", back_populates="project")
|
files = relationship("ProjectFile", back_populates="project")
|
||||||
|
members = relationship("ProjectMember", back_populates="project")
|
||||||
|
|||||||
@ -3,11 +3,7 @@ from pydantic_settings import BaseSettings
|
|||||||
|
|
||||||
class Settings(BaseSettings):
|
class Settings(BaseSettings):
|
||||||
DATABASE_URL: str
|
DATABASE_URL: str
|
||||||
LOG_LEVEL: str
|
|
||||||
LOG_FILE: str
|
|
||||||
SECRET_KEY: str
|
SECRET_KEY: str
|
||||||
ALGORITHM: str
|
|
||||||
APP_PREFIX: str
|
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
env_file = '.env'
|
env_file = '.env'
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user