diff --git a/.gitignore b/.gitignore index 2c014e8..444d245 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ API/.idea API/.venv/ API/.idea/ +API/.env diff --git a/API/app/database/migrations/versions/d53be3a35511_0001_инициализация.py b/API/app/database/migrations/versions/d53be3a35511_0001_инициализация.py new file mode 100644 index 0000000..62364e6 --- /dev/null +++ b/API/app/database/migrations/versions/d53be3a35511_0001_инициализация.py @@ -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 ### diff --git a/API/app/domain/models/__init__.py b/API/app/domain/models/__init__.py index 7c2377a..aa1f0b2 100644 --- a/API/app/domain/models/__init__.py +++ b/API/app/domain/models/__init__.py @@ -1,3 +1,16 @@ from sqlalchemy.ext.declarative import declarative_base -Base = declarative_base() \ No newline at end of file +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 diff --git a/API/app/domain/models/contests.py b/API/app/domain/models/contests.py index 5de4ff1..78375f7 100644 --- a/API/app/domain/models/contests.py +++ b/API/app/domain/models/contests.py @@ -15,7 +15,7 @@ class Contest(AdvancedBaseModel): is_win = Column(Boolean) 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') status = relationship('ContestStatus', back_populates='contests') diff --git a/API/app/domain/models/profile_photos.py b/API/app/domain/models/profile_photos.py new file mode 100644 index 0000000..1b20294 --- /dev/null +++ b/API/app/domain/models/profile_photos.py @@ -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') \ No newline at end of file diff --git a/API/app/domain/models/profiles.py b/API/app/domain/models/profiles.py index 8a4fdec..9c3b80b 100644 --- a/API/app/domain/models/profiles.py +++ b/API/app/domain/models/profiles.py @@ -21,3 +21,5 @@ class Profile(AdvancedBaseModel): team = relationship('Team', back_populates='profiles') user = relationship('User', back_populates='profile') + profile_photo = relationship('ProfilePhoto', back_populates='profile') + projects = relationship('ProjectMember', back_populates='profile') diff --git a/API/app/domain/models/project_members.py b/API/app/domain/models/project_members.py new file mode 100644 index 0000000..75e4e78 --- /dev/null +++ b/API/app/domain/models/project_members.py @@ -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') diff --git a/API/app/domain/models/projects.py b/API/app/domain/models/projects.py index 80ce895..577f48d 100644 --- a/API/app/domain/models/projects.py +++ b/API/app/domain/models/projects.py @@ -12,3 +12,4 @@ class Project(AdvancedBaseModel): contest = relationship("Contest", back_populates="project") files = relationship("ProjectFile", back_populates="project") + members = relationship("ProjectMember", back_populates="project") diff --git a/API/app/settings.py b/API/app/settings.py index 0929eab..c11c96a 100644 --- a/API/app/settings.py +++ b/API/app/settings.py @@ -3,11 +3,7 @@ from pydantic_settings import BaseSettings class Settings(BaseSettings): DATABASE_URL: str - LOG_LEVEL: str - LOG_FILE: str SECRET_KEY: str - ALGORITHM: str - APP_PREFIX: str class Config: env_file = '.env'