Skip to content

Commit 56d126f

Browse files
committed
refactor: remove IdMixin from multiple models for cleaner inheritance
1 parent c927c54 commit 56d126f

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

app/db/models.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ class IdMixin:
6969
id: Mapped[int] = mapped_column(SqliteCompatibleBigInteger, primary_key=True, init=False, autoincrement=True)
7070

7171

72-
class CreatedAtUTCMixin:
72+
class CreatedAtUTCMixin(IdMixin):
7373
created_at: Mapped[dt] = mapped_column(DateTime(timezone=True), default_factory=lambda: dt.now(tz.utc), init=False)
7474

7575

76-
class Admin(Base, IdMixin, CreatedAtUTCMixin):
76+
class Admin(Base, CreatedAtUTCMixin):
7777
__tablename__ = "admins"
7878
username: Mapped[str] = mapped_column(String(34), unique=True, index=True)
7979
hashed_password: Mapped[str] = mapped_column(String(128))
@@ -179,7 +179,7 @@ class DataLimitResetStrategy(str, Enum):
179179
year = "year"
180180

181181

182-
class User(Base, IdMixin, CreatedAtUTCMixin):
182+
class User(Base, CreatedAtUTCMixin):
183183
__tablename__ = "users"
184184
username: Mapped[str] = mapped_column(CaseSensitiveString(128), unique=True, index=True)
185185
node_usages: Mapped[List["NodeUserUsage"]] = relationship(
@@ -363,7 +363,7 @@ def days_left(cls):
363363
return case((cls.expire.isnot(None), func.floor(DaysDiff())), else_=0)
364364

365365

366-
class UserSubscriptionUpdate(Base, IdMixin, CreatedAtUTCMixin):
366+
class UserSubscriptionUpdate(Base, CreatedAtUTCMixin):
367367
__tablename__ = "user_subscription_updates"
368368
user_id: Mapped[int] = fk_id_column("users.id", ondelete="CASCADE")
369369
user: Mapped["User"] = relationship(back_populates="subscription_updates", init=False)
@@ -372,7 +372,7 @@ class UserSubscriptionUpdate(Base, IdMixin, CreatedAtUTCMixin):
372372
hwid: Mapped[Optional[str]] = mapped_column(String(256), nullable=True, default=None)
373373

374374

375-
class UserHWID(Base, IdMixin, CreatedAtUTCMixin):
375+
class UserHWID(Base, CreatedAtUTCMixin):
376376
__tablename__ = "user_hwids"
377377
__table_args__ = (
378378
UniqueConstraint("user_id", "hwid"),
@@ -585,7 +585,7 @@ class NodeStatus(str, Enum):
585585
limited = "limited"
586586

587587

588-
class Node(Base, IdMixin, CreatedAtUTCMixin):
588+
class Node(Base, CreatedAtUTCMixin):
589589
__tablename__ = "nodes"
590590
name: Mapped[str] = mapped_column(CaseSensitiveString(256), unique=True)
591591
address: Mapped[str] = mapped_column(String(256), unique=False, nullable=False)
@@ -717,7 +717,7 @@ class NodeUsage(Base, IdMixin):
717717
downlink: Mapped[int] = mapped_column(BigInteger, default=0)
718718

719719

720-
class NodeUsageResetLogs(Base, IdMixin, CreatedAtUTCMixin):
720+
class NodeUsageResetLogs(Base, CreatedAtUTCMixin):
721721
__tablename__ = "node_usage_reset_logs"
722722
__table_args__ = (
723723
# Index for node-specific queries sorted by time
@@ -729,7 +729,7 @@ class NodeUsageResetLogs(Base, IdMixin, CreatedAtUTCMixin):
729729
downlink: Mapped[int] = mapped_column(BigInteger, nullable=False)
730730

731731

732-
class NotificationReminder(Base, IdMixin, CreatedAtUTCMixin):
732+
class NotificationReminder(Base, CreatedAtUTCMixin):
733733
__tablename__ = "notification_reminders"
734734
user_id: Mapped[int] = fk_id_column("users.id", ondelete="CASCADE")
735735
user: Mapped["User"] = relationship(back_populates="notification_reminders", init=False)
@@ -738,7 +738,7 @@ class NotificationReminder(Base, IdMixin, CreatedAtUTCMixin):
738738
expires_at: Mapped[Optional[dt]] = mapped_column(DateTime(timezone=True), default=None)
739739

740740

741-
class AdminNotificationReminder(Base, IdMixin, CreatedAtUTCMixin):
741+
class AdminNotificationReminder(Base, CreatedAtUTCMixin):
742742
__tablename__ = "admin_notification_reminders"
743743
__table_args__ = (Index("ix_admin_notification_reminders_admin_id_type", "admin_id", "type"),)
744744
admin_id: Mapped[int] = fk_id_column("admins.id", ondelete="CASCADE")
@@ -810,7 +810,7 @@ class CoreType(str, Enum):
810810
singbox = "singbox"
811811

812812

813-
class CoreConfig(Base, IdMixin, CreatedAtUTCMixin):
813+
class CoreConfig(Base, CreatedAtUTCMixin):
814814
__tablename__ = "core_configs"
815815
name: Mapped[str] = mapped_column(String(256))
816816
config: Mapped[Dict[str, Any]] = mapped_column(JSON(False))
@@ -833,7 +833,7 @@ class ClientTemplate(Base):
833833
is_system: Mapped[bool] = mapped_column(default=False, server_default="0")
834834

835835

836-
class NodeStat(Base, IdMixin, CreatedAtUTCMixin):
836+
class NodeStat(Base, CreatedAtUTCMixin):
837837
__tablename__ = "node_stats"
838838
node_id: Mapped[int] = fk_id_column("nodes.id")
839839
node: Mapped["Node"] = relationship(back_populates="stats", init=False)
@@ -856,7 +856,7 @@ class Settings(Base, IdMixin):
856856
general: Mapped[dict] = mapped_column(JSON())
857857

858858

859-
class AdminRole(Base, IdMixin, CreatedAtUTCMixin):
859+
class AdminRole(Base, CreatedAtUTCMixin):
860860
__tablename__ = "admin_roles"
861861
name: Mapped[str] = mapped_column(String(64), unique=True)
862862
is_owner: Mapped[bool] = mapped_column(default=False, server_default="0")

0 commit comments

Comments
 (0)