From ad1a250e62a76880f4839057136976da7527c38c Mon Sep 17 00:00:00 2001 From: Sebastiaan Date: Sun, 8 Jun 2025 14:07:30 +0200 Subject: [PATCH] Use snake case table names --- backend/app/models/base.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/backend/app/models/base.py b/backend/app/models/base.py index 3f85f26..fec1b00 100644 --- a/backend/app/models/base.py +++ b/backend/app/models/base.py @@ -1,8 +1,11 @@ +import re + from enum import Enum, IntFlag # Python 3.11 >= StrEnum from enum import auto as auto_enum from uuid import UUID as RowId from sqlmodel import SQLModel +from sqlalchemy.orm import declared_attr __all__ = [ "RowId", @@ -18,8 +21,12 @@ __all__ = [ class BaseSQLModel(SQLModel): - pass - + # Generate __tablename__ automatically with snake_case + # noinspection PyMethodParameters + @declared_attr # type: ignore + def __tablename__(cls) -> str: + rx = re.compile(r"(?<=.)(((?