Coverage for polar/models/campaign.py: 100%

15 statements  

« prev     ^ index     » next       coverage.py v7.10.6, created at 2025-12-05 16:17 +0000

1from datetime import datetime 1ab

2 

3from sqlalchemy import ( 1ab

4 TIMESTAMP, 

5 Integer, 

6 String, 

7) 

8from sqlalchemy.orm import ( 1ab

9 Mapped, 

10 mapped_column, 

11) 

12 

13from polar.kit.db.models import RecordModel 1ab

14from polar.kit.metadata import MetadataMixin 1ab

15 

16 

17# Basic campaign structure (alpha) 

18# 

19# Intention: 

20# - Add referral capabilities (user_id) 

21# - Add duration (duration, duration_type: days, gtv) 

22# - Add fallback_percent/fixed after campaign completion 

23class Campaign(MetadataMixin, RecordModel): 1ab

24 __tablename__ = "campaigns" 1ab

25 

26 code: Mapped[str] = mapped_column(String, nullable=False, index=True, unique=True) 1ab

27 name: Mapped[str] = mapped_column(String, nullable=False) 1ab

28 

29 starts_at: Mapped[datetime | None] = mapped_column( 1ab

30 TIMESTAMP(timezone=True), nullable=True 

31 ) 

32 ends_at: Mapped[datetime | None] = mapped_column( 1ab

33 TIMESTAMP(timezone=True), nullable=True 

34 ) 

35 max_redemptions: Mapped[int | None] = mapped_column(Integer, nullable=True) 1ab

36 max_user_redemptions: Mapped[int | None] = mapped_column( 1ab

37 Integer, nullable=True, default=1 

38 ) 

39 

40 fee_percent: Mapped[int | None] = mapped_column( 1ab

41 Integer, nullable=True, default=None 

42 ) 

43 fee_fixed: Mapped[int | None] = mapped_column(Integer, nullable=True, default=None) 1ab