Coverage for polar/models/member.py: 100%
22 statements
« prev ^ index » next coverage.py v7.10.6, created at 2025-12-05 15:52 +0000
« prev ^ index » next coverage.py v7.10.6, created at 2025-12-05 15:52 +0000
1from enum import StrEnum 1ab
2from uuid import UUID 1ab
4from sqlalchemy import ForeignKey, String, UniqueConstraint, Uuid 1ab
5from sqlalchemy.orm import Mapped, declared_attr, mapped_column, relationship 1ab
7from polar.kit.db.models import RecordModel 1ab
8from polar.models.customer import Customer 1ab
11class MemberRole(StrEnum): 1ab
12 owner = "owner" 1ab
13 billing_manager = "billing_manager" 1ab
14 member = "member" 1ab
17class Member(RecordModel): 1ab
18 __tablename__ = "members" 1ab
19 __table_args__ = ( 1ab
20 UniqueConstraint(
21 "customer_id",
22 "email",
23 name="members_customer_id_email_key",
24 postgresql_nulls_not_distinct=True,
25 ),
26 UniqueConstraint(
27 "customer_id",
28 "external_id",
29 name="members_customer_id_external_id_key",
30 postgresql_nulls_not_distinct=True,
31 ),
32 )
34 customer_id: Mapped[UUID] = mapped_column( 1ab
35 Uuid,
36 ForeignKey("customers.id", ondelete="restrict"),
37 nullable=False,
38 index=True,
39 )
41 organization_id: Mapped[UUID] = mapped_column( 1ab
42 Uuid,
43 ForeignKey("organizations.id", ondelete="restrict"),
44 nullable=False,
45 index=True,
46 )
48 email: Mapped[str] = mapped_column(String(320), nullable=False) 1ab
49 name: Mapped[str | None] = mapped_column(String, nullable=True, default=None) 1ab
50 external_id: Mapped[str | None] = mapped_column(String, nullable=True, default=None) 1ab
52 role: Mapped[MemberRole] = mapped_column( 1ab
53 String, nullable=False, default=MemberRole.member
54 )
56 @declared_attr 1ab
57 def customer(cls) -> Mapped["Customer"]: 1ab
58 return relationship("Customer", lazy="raise", back_populates="members") 1ab