Coverage for polar/models/notification_recipient.py: 89%

16 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-10-07 12:42 +0000

1from typing import TYPE_CHECKING 

2from uuid import UUID 

3 

4from sqlalchemy import ForeignKey, Index, String, Uuid 

5from sqlalchemy.orm import Mapped, declared_attr, mapped_column, relationship 

6 

7from polar.kit.db.models.base import RecordModel 

8 

9if TYPE_CHECKING: 9 ↛ 10line 9 didn't jump to line 10 because the condition on line 9 was never true

10 from .user import User 

11 

12 

13class NotificationRecipient(RecordModel): 

14 __tablename__ = "notification_recipients" 

15 __table_args__ = ( 

16 Index( 

17 "ix_notification_recipients_expo_push_token", 

18 "user_id", 

19 "expo_push_token", 

20 "deleted_at", 

21 unique=True, 

22 postgresql_nulls_not_distinct=True, 

23 ), 

24 ) 

25 

26 user_id: Mapped[UUID] = mapped_column( 

27 Uuid, ForeignKey("users.id", ondelete="cascade") 

28 ) 

29 platform: Mapped[str] = mapped_column(String, nullable=False) 

30 expo_push_token: Mapped[str] = mapped_column( 

31 String, 

32 nullable=False, 

33 ) 

34 

35 @declared_attr 

36 def user(cls) -> Mapped["User"]: 

37 return relationship("User", lazy="raise_on_sql")