Coverage for polar/models/license_key_activation.py: 86%
20 statements
« prev ^ index » next coverage.py v7.10.6, created at 2025-12-05 17:15 +0000
« prev ^ index » next coverage.py v7.10.6, created at 2025-12-05 17:15 +0000
1from typing import TYPE_CHECKING, Any 1ab
2from uuid import UUID 1ab
4from sqlalchemy import ( 1ab
5 ForeignKey,
6 String,
7 Uuid,
8)
9from sqlalchemy.dialects.postgresql import JSONB 1ab
10from sqlalchemy.orm import Mapped, declared_attr, mapped_column, relationship 1ab
12from polar.kit.db.models import RecordModel 1ab
13from polar.kit.utils import utc_now 1ab
15if TYPE_CHECKING: 15 ↛ 16line 15 didn't jump to line 16 because the condition on line 15 was never true1ab
16 from .license_key import LicenseKey
19class LicenseKeyActivation(RecordModel): 1ab
20 __tablename__ = "license_key_activations" 1ab
22 license_key_id: Mapped[UUID] = mapped_column( 1ab
23 Uuid,
24 ForeignKey("license_keys.id", ondelete="cascade"),
25 nullable=False,
26 index=True,
27 )
29 @declared_attr 1ab
30 def license_key(cls) -> Mapped["LicenseKey"]: 1ab
31 return relationship("LicenseKey", lazy="raise", back_populates="activations") 1ab
33 label: Mapped[str] = mapped_column(String, nullable=False) 1ab
35 conditions: Mapped[dict[str, Any]] = mapped_column( 1ab
36 JSONB, nullable=False, default=dict
37 )
39 meta: Mapped[dict[str, Any]] = mapped_column(JSONB, nullable=False, default=dict) 1ab
41 def mark_deleted(self) -> None: 1ab
42 self.deleted_at = utc_now()