File tree Expand file tree Collapse file tree 2 files changed +8
-2
lines changed
apps/dashboard_app/app/models Expand file tree Collapse file tree 2 files changed +8
-2
lines changed Original file line number Diff line number Diff line change
1
+ from re import sub
1
2
from sqlalchemy .dialects .postgresql import UUID as PG_UUID
2
3
from uuid import uuid4 , UUID
3
- from sqlalchemy .orm import DeclarativeBase , Mapped
4
+ from sqlalchemy .orm import DeclarativeBase , Mapped , declared_attr
4
5
from sqlalchemy import Column , MetaData
5
6
7
+
6
8
class Base (DeclarativeBase ):
7
9
id : Mapped [UUID ] = Column (PG_UUID (as_uuid = True ), default = uuid4 , primary_key = True )
8
10
metadata = MetaData ()
11
+
12
+ @classmethod
13
+ @declared_attr .directive
14
+ def __tablename__ (cls ) -> str :
15
+ return sub (r"(?<!^)(?=[A-Z])" , "_" , cls .__name__ ).lower ()
Original file line number Diff line number Diff line change @@ -27,7 +27,6 @@ class NotificationData(Base):
27
27
)
28
28
29
29
class TelegramLog (Base ):
30
- __tablename__ = "telegram_log"
31
30
32
31
sent_at : Mapped [datetime ] = mapped_column (DateTime , default = datetime .now , nullable = False )
33
32
notification_data_id : Mapped [str ] = mapped_column (ForeignKey (NotificationData .id ), nullable = False )
You can’t perform that action at this time.
0 commit comments