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

17 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, String, UniqueConstraint, 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 .organization import Organization 

11 

12 

13class EventType(RecordModel): 

14 __tablename__ = "event_types" 

15 __table_args__ = ( 

16 UniqueConstraint( 

17 "name", 

18 "organization_id", 

19 name="event_types_name_organization_id_key", 

20 ), 

21 ) 

22 

23 name: Mapped[str] = mapped_column(String(128), nullable=False, index=True) 

24 label: Mapped[str] = mapped_column(String(128), nullable=False) 

25 label_property_selector: Mapped[str | None] = mapped_column( 

26 String(256), nullable=True 

27 ) 

28 

29 organization_id: Mapped[UUID] = mapped_column( 

30 Uuid, 

31 ForeignKey("organizations.id", ondelete="cascade"), 

32 nullable=False, 

33 index=True, 

34 ) 

35 

36 @declared_attr 

37 def organization(cls) -> Mapped["Organization"]: 

38 return relationship("Organization", lazy="raise")