1
0
mirror of https://gitlab.com/MoonTestUse1/AdministrationItDepartmens.git synced 2025-08-14 00:25:46 +02:00

Fix database

This commit is contained in:
MoonTestUse1
2025-01-07 05:44:30 +06:00
parent 3299e846f5
commit 51f7a388f6
4 changed files with 28 additions and 20 deletions

View File

@@ -1,22 +1,16 @@
"""Database configuration"""
import os
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
from sqlalchemy.orm import sessionmaker, declarative_base
# Определяем URL базы данных в зависимости от окружения
if os.getenv("TESTING"):
SQLALCHEMY_DATABASE_URL = "sqlite:///:memory:"
engine = create_engine(
SQLALCHEMY_DATABASE_URL,
connect_args={"check_same_thread": False}
)
else:
SQLALCHEMY_DATABASE_URL = "postgresql://postgres:postgres@postgres:5432/app"
engine = create_engine(SQLALCHEMY_DATABASE_URL)
from .core.config import settings
# Создаем движок базы данных
engine = create_engine(settings.get_database_url())
# Создаем фабрику сессий
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
# Создаем базовый класс для моделей
Base = declarative_base()
def get_db():