добавлен конфиг и внешние ключи
This commit is contained in:
parent
bf0205c91f
commit
3fd4c5ccca
19
db/config.py
Normal file
19
db/config.py
Normal file
@ -0,0 +1,19 @@
|
||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
DB_USER: str
|
||||
DB_PASSWORD: str
|
||||
DB_HOST: str
|
||||
DB_PORT: int
|
||||
DB_NAME: str
|
||||
|
||||
@property
|
||||
def db_url_asyncpg(self):
|
||||
# 'postgresql+asyncpg://username:password@localhost:5432/database_name'
|
||||
return f'postgresql+asyncpg://{self.DB_USER}:{self.DB_PASSWORD}@{self.DB_HOST}:{self.DB_PORT}/{self.DB_NAME}'
|
||||
|
||||
model_config = SettingsConfigDict(env_file='../.env')
|
||||
|
||||
|
||||
settings = Settings()
|
@ -1,7 +1,6 @@
|
||||
from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine, async_sessionmaker
|
||||
from config import settings
|
||||
|
||||
# Асинхронное подключение к PostgreSQL
|
||||
DATABASE_URL = 'postgresql+asyncpg://username:password@localhost:5432/database_name'
|
||||
engine = create_async_engine(DATABASE_URL, echo=True)
|
||||
engine = create_async_engine(url=settings.db_url_asyncpg, echo=True)
|
||||
|
||||
async_session = async_sessionmaker(engine)
|
||||
|
@ -2,7 +2,7 @@ from base import Base
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
class ExperimentData(Base):
|
||||
__tablename__ = 'ExperimentData'
|
||||
__tablename__ = 'experiment_data'
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
||||
direction: Mapped[float]
|
||||
|
@ -1,16 +1,20 @@
|
||||
from typing import Optional
|
||||
|
||||
from sqlalchemy import ForeignKey
|
||||
|
||||
from base import Base
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
class ExperimentParameters(Base):
|
||||
__tablename__ = 'ExperimentParameters'
|
||||
__tablename__ = 'experiment_parameters'
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
||||
outer_blades_count: Mapped[int]
|
||||
outer_blades_length: Mapped[float]
|
||||
outer_blades_angle: Mapped[float]
|
||||
middle_blades_count: Mapped[int]
|
||||
load_id: Mapped[int]
|
||||
recycling_id: Mapped[int]
|
||||
load_id: Mapped[Optional[int]] = mapped_column(ForeignKey('load_parameters.id', ondelete='SET NULL'))
|
||||
recycling_id: Mapped[Optional[int]] = mapped_column(ForeignKey('recycling_parameters.id', ondelete='SET NULL'))
|
||||
experiment_hash: Mapped[str]
|
||||
|
||||
def __repr__(self):
|
||||
|
@ -2,7 +2,7 @@ from base import Base
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
class LoadParameters(Base):
|
||||
__tablename__ = 'LoadParameters'
|
||||
__tablename__ = 'load_parameters'
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
||||
load: Mapped[int]
|
||||
|
@ -1,11 +1,15 @@
|
||||
from typing import Optional
|
||||
|
||||
from sqlalchemy import ForeignKey
|
||||
|
||||
from base import Base
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
class RecyclingParameters(Base):
|
||||
__tablename__ = 'RecyclingParameters'
|
||||
__tablename__ = 'recycling_parameters'
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
||||
load_id: Mapped[int]
|
||||
load_id: Mapped[Optional[int]] = mapped_column(ForeignKey('load_parameters.id', ondelete='SET NULL'))
|
||||
recycling_level: Mapped[int]
|
||||
co2: Mapped[float]
|
||||
n2: Mapped[float]
|
||||
|
Loading…
Reference in New Issue
Block a user