@@ -16,7 +16,7 @@ def override(func): # noqa: ANN001, ANN201
1616
1717
1818try :
19- from sqlalchemy import JSON , Dialect , String
19+ from sqlalchemy import JSON , Dialect , LargeBinary , String
2020 from sqlalchemy .orm import (
2121 DeclarativeBase ,
2222 Mapped ,
@@ -208,3 +208,58 @@ class TaskModel(TaskMixin, Base):
208208 """Default task model with standard table name."""
209209
210210 __tablename__ = 'tasks'
211+
212+
213+ # PushNotificationConfigMixin that can be used with any table name
214+ class PushNotificationConfigMixin :
215+ """Mixin providing standard push notification config columns."""
216+
217+ task_id : Mapped [str ] = mapped_column (String (36 ), primary_key = True )
218+ config_id : Mapped [str ] = mapped_column (String (255 ), primary_key = True )
219+ config_data : Mapped [bytes ] = mapped_column (LargeBinary , nullable = False )
220+
221+ @override
222+ def __repr__ (self ) -> str :
223+ """Return a string representation of the push notification config."""
224+ repr_template = '<{CLS}(task_id="{TID}", config_id="{CID}")>'
225+ return repr_template .format (
226+ CLS = self .__class__ .__name__ ,
227+ TID = self .task_id ,
228+ CID = self .config_id ,
229+ )
230+
231+
232+ def create_push_notification_config_model (
233+ table_name : str = 'push_notification_configs' ,
234+ base : type [DeclarativeBase ] = Base ,
235+ ) -> type :
236+ """Create a PushNotificationConfigModel class with a configurable table name."""
237+
238+ class PushNotificationConfigModel (PushNotificationConfigMixin , base ):
239+ __tablename__ = table_name
240+
241+ @override
242+ def __repr__ (self ) -> str :
243+ """Return a string representation of the push notification config."""
244+ repr_template = '<PushNotificationConfigModel[{TABLE}](task_id="{TID}", config_id="{CID}")>'
245+ return repr_template .format (
246+ TABLE = table_name ,
247+ TID = self .task_id ,
248+ CID = self .config_id ,
249+ )
250+
251+ PushNotificationConfigModel .__name__ = (
252+ f'PushNotificationConfigModel_{ table_name } '
253+ )
254+ PushNotificationConfigModel .__qualname__ = (
255+ f'PushNotificationConfigModel_{ table_name } '
256+ )
257+
258+ return PushNotificationConfigModel
259+
260+
261+ # Default PushNotificationConfigModel for backward compatibility
262+ class PushNotificationConfigModel (PushNotificationConfigMixin , Base ):
263+ """Default push notification config model with standard table name."""
264+
265+ __tablename__ = 'push_notification_configs'
0 commit comments