Coverage for polar/models/trial_redemption.py: 91%

21 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, Uuid 

5from sqlalchemy.ext.associationproxy import AssociationProxy, association_proxy 

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

7 

8from polar.kit.db.models import RecordModel 

9 

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

11 from polar.models import Customer, Organization, Product 

12 

13 

14class TrialRedemption(RecordModel): 

15 __tablename__ = "trial_redemptions" 

16 

17 customer_email: Mapped[str] = mapped_column(String, nullable=False, index=True) 

18 payment_method_fingerprint: Mapped[str | None] = mapped_column( 

19 String, nullable=True, index=True 

20 ) 

21 

22 customer_id: Mapped[UUID] = mapped_column( 

23 Uuid, ForeignKey("customers.id", ondelete="cascade"), nullable=False, index=True 

24 ) 

25 

26 @declared_attr 

27 def customer(cls) -> Mapped["Customer"]: 

28 return relationship("Customer", lazy="raise") 

29 

30 organization: AssociationProxy["Organization"] = association_proxy( 

31 "customer", "organization" 

32 ) 

33 

34 product_id: Mapped[UUID | None] = mapped_column( 

35 Uuid, ForeignKey("products.id", ondelete="cascade"), nullable=True, index=True 

36 ) 

37 

38 @declared_attr 

39 def product(cls) -> Mapped["Product | None"]: 

40 return relationship("Product", lazy="raise")