создал несколько таблиц
This commit is contained in:
parent
74787e7e44
commit
fc63f9e167
@ -1,6 +1,6 @@
|
||||
from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
from app.config import settings
|
||||
from app.settings import settings
|
||||
|
||||
engine = create_async_engine(settings.DATABASE_URL, echo=True)
|
||||
|
||||
|
||||
30
api/app/domain/models/lens.py
Normal file
30
api/app/domain/models/lens.py
Normal file
@ -0,0 +1,30 @@
|
||||
from enum import Enum as PyEnum
|
||||
from sqlalchemy import Column, Integer, ForeignKey, Float, Enum
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from app.domain.models import Base
|
||||
|
||||
|
||||
class SideEnum(PyEnum):
|
||||
LEFT = 'левая'
|
||||
RIGHT = 'правая'
|
||||
|
||||
|
||||
class Lens(Base):
|
||||
__tablename__ = 'lens'
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
tor = Column(Float, nullable=False)
|
||||
trial = Column(Float, nullable=False)
|
||||
esa = Column(Float, nullable=False)
|
||||
fvc = Column(Float, nullable=False) # ПЦК
|
||||
preset_refraction = Column(Float, nullable=False)
|
||||
diameter = Column(Float, nullable=False)
|
||||
periphery_toricity = Column(Float, nullable=False) # Торичность перефирии
|
||||
side = Column(Enum(SideEnum), nullable=False)
|
||||
|
||||
type_id = Column(Integer, ForeignKey('lenses_types.id'), nullable=False)
|
||||
|
||||
type = relationship('LensesType', back_populates='lenses')
|
||||
|
||||
set = relationship('SetLens', back_populates='lens')
|
||||
@ -1,4 +1,4 @@
|
||||
from sqlalchemy import Column, Integer, VARCHAR, ForeignKey
|
||||
from sqlalchemy import Column, Integer, VARCHAR
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from app.domain.models import Base
|
||||
@ -9,3 +9,5 @@ class LensesType(Base):
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
title = Column(VARCHAR(150), nullable=False, unique=True)
|
||||
|
||||
lenses = relationship('Lens', back_populates='type')
|
||||
|
||||
13
api/app/domain/models/roles.py
Normal file
13
api/app/domain/models/roles.py
Normal file
@ -0,0 +1,13 @@
|
||||
from sqlalchemy import Column, Integer, VARCHAR
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from app.domain.models import Base
|
||||
|
||||
|
||||
class Role(Base):
|
||||
__tablename__ = 'roles'
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
title = Column(VARCHAR(150), nullable=False, unique=True)
|
||||
|
||||
users = relationship('User', back_populates='role')
|
||||
16
api/app/domain/models/set_lens.py
Normal file
16
api/app/domain/models/set_lens.py
Normal file
@ -0,0 +1,16 @@
|
||||
from sqlalchemy import Column, Integer, ForeignKey
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from app.domain.models import Base
|
||||
|
||||
|
||||
class SetLens(Base):
|
||||
__tablename__ = 'set_lens'
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
|
||||
set_id = Column(Integer, ForeignKey('sets.id'), nullable=False)
|
||||
lens_id = Column(Integer, ForeignKey('lens.id'), nullable=False, unique=True)
|
||||
|
||||
set = relationship('Set', back_populates='lens')
|
||||
lens = relationship('Lens', back_populates='set')
|
||||
14
api/app/domain/models/sets.py
Normal file
14
api/app/domain/models/sets.py
Normal file
@ -0,0 +1,14 @@
|
||||
from sqlalchemy import Column, Integer, VARCHAR
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from app.domain.models import Base
|
||||
|
||||
|
||||
class Set(Base):
|
||||
__tablename__ = 'sets'
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
title = Column(VARCHAR(150), nullable=False, unique=True)
|
||||
count = Column(Integer, nullable=False)
|
||||
|
||||
lens = relationship('SetLens', back_populates='set')
|
||||
19
api/app/domain/models/users.py
Normal file
19
api/app/domain/models/users.py
Normal file
@ -0,0 +1,19 @@
|
||||
from sqlalchemy import Column, Integer, VARCHAR, ForeignKey, String
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from app.domain.models import Base
|
||||
|
||||
|
||||
class User(Base):
|
||||
__tablename__ = 'users'
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
first_name = Column(VARCHAR(200), nullable=False)
|
||||
last_name = Column(VARCHAR(200), nullable=False)
|
||||
patronymic = Column(VARCHAR(200))
|
||||
login = Column(String, nullable=False, unique=True)
|
||||
password = Column(String, nullable=False)
|
||||
|
||||
role_id = Column(Integer, ForeignKey('roles.id'), nullable=False)
|
||||
|
||||
role = relationship('Role', back_populates='users')
|
||||
17
api/app/infrastructure/logger.py
Normal file
17
api/app/infrastructure/logger.py
Normal file
@ -0,0 +1,17 @@
|
||||
import logging
|
||||
from app.settings import settings
|
||||
import os
|
||||
|
||||
log_dir = os.path.dirname(settings.LOG_FILE)
|
||||
os.makedirs(log_dir, exist_ok=True)
|
||||
|
||||
logging.basicConfig(
|
||||
level=settings.LOG_LEVEL.upper(),
|
||||
format="%(asctime)s - %(levelname)s - %(message)s",
|
||||
handlers=[
|
||||
logging.FileHandler(settings.LOG_FILE, encoding="utf-8"),
|
||||
logging.StreamHandler()
|
||||
]
|
||||
)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
14
api/app/settings.py
Normal file
14
api/app/settings.py
Normal file
@ -0,0 +1,14 @@
|
||||
from pydantic_settings import BaseSettings
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
DATABASE_URL: str
|
||||
LOG_LEVEL: str = "info"
|
||||
LOG_FILE: str = "logs/app.log"
|
||||
|
||||
class Config:
|
||||
env_file = ".env"
|
||||
env_file_encoding = "utf-8"
|
||||
|
||||
|
||||
settings = Settings()
|
||||
Loading…
x
Reference in New Issue
Block a user