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