[rewrite] Minor fixes to models, session generator and example .env
This commit is contained in:
parent
71e916586e
commit
272e765ca8
@ -30,8 +30,10 @@ SMTP_HOST=
|
||||
SMTP_PORT=587
|
||||
SMTP_USER=
|
||||
SMTP_PASSWORD=
|
||||
SMTP_TLS=True # Use TLS for email security
|
||||
SMTP_SSL=False # Set to True if using SSL instead of TLS
|
||||
# Use TLS for email security
|
||||
SMTP_TLS=True
|
||||
# Set to True if using SSL instead of TLS
|
||||
SMTP_SSL=False
|
||||
|
||||
# Email sender information
|
||||
EMAILS_FROM_EMAIL=
|
||||
|
@ -1,8 +1,12 @@
|
||||
import logging
|
||||
|
||||
from sqlmodel import select
|
||||
|
||||
from fastapi import APIRouter
|
||||
from app.api.dependencies import SessionDep
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
router = APIRouter(prefix="/utils", tags=["utils"])
|
||||
|
||||
|
||||
@ -10,11 +14,12 @@ router = APIRouter(prefix="/utils", tags=["utils"])
|
||||
async def health_check() -> bool:
|
||||
return True
|
||||
|
||||
|
||||
@router.get("/test-db/")
|
||||
async def test_db(session: SessionDep) -> bool:
|
||||
try:
|
||||
with session:
|
||||
session.exec(select(1))
|
||||
return True
|
||||
except Exception:
|
||||
except Exception as e:
|
||||
logger.error(e)
|
||||
return False
|
||||
|
@ -9,7 +9,7 @@ from app.core.config import settings
|
||||
|
||||
from app.database.exceptions import DatabaseError
|
||||
|
||||
import app.database.models
|
||||
import app.database.models # pylint: disable=unused-import
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@ -34,7 +34,6 @@ def cleanup() -> None:
|
||||
engine.dispose()
|
||||
|
||||
|
||||
@contextmanager
|
||||
def get_session() -> Generator[Session, None, None]:
|
||||
with Session(engine) as session:
|
||||
yield session
|
||||
|
@ -26,7 +26,7 @@ class User(SQLModel, table=True):
|
||||
owned_shops: List["Shop"] = Relationship(back_populates="owner")
|
||||
registered_shop: List["Shop"] = Relationship(back_populates="registered_users")
|
||||
|
||||
role: Optional["UserRole"] = Relationship(back_populates="users")
|
||||
user_assigned_role: Optional["UserRole"] = Relationship(back_populates="role_users", sa_relationship_kwargs={"foreign_keys": "[User.user_role_id]"})
|
||||
preferences: Optional["UserPreferences"] = Relationship(back_populates="user")
|
||||
statistics: Optional["UserStatistics"] = Relationship(back_populates="user_statistics")
|
||||
|
||||
@ -45,7 +45,7 @@ class UserRole(SQLModel, table=True):
|
||||
id: int = Field(primary_key=True)
|
||||
name: str = Field(nullable=False, unique=True, max_length=50)
|
||||
|
||||
users = Relationship(back_populates="role")
|
||||
role_users: List["User"] = Relationship(back_populates="user_assigned_role")
|
||||
|
||||
|
||||
class UserStatistics(SQLModel, table=True):
|
||||
|
Loading…
x
Reference in New Issue
Block a user