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
« 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
4from sqlalchemy import ForeignKey, String, Uuid
5from sqlalchemy.ext.associationproxy import AssociationProxy, association_proxy
6from sqlalchemy.orm import Mapped, declared_attr, mapped_column, relationship
8from polar.kit.db.models import RecordModel
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
14class TrialRedemption(RecordModel):
15 __tablename__ = "trial_redemptions"
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 )
22 customer_id: Mapped[UUID] = mapped_column(
23 Uuid, ForeignKey("customers.id", ondelete="cascade"), nullable=False, index=True
24 )
26 @declared_attr
27 def customer(cls) -> Mapped["Customer"]:
28 return relationship("Customer", lazy="raise")
30 organization: AssociationProxy["Organization"] = association_proxy(
31 "customer", "organization"
32 )
34 product_id: Mapped[UUID | None] = mapped_column(
35 Uuid, ForeignKey("products.id", ondelete="cascade"), nullable=True, index=True
36 )
38 @declared_attr
39 def product(cls) -> Mapped["Product | None"]:
40 return relationship("Product", lazy="raise")