Coverage for polar/models/login_code.py: 88%

15 statements  

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

1from datetime import datetime 1ab

2from typing import TYPE_CHECKING 1ab

3from uuid import UUID 1ab

4 

5from sqlalchemy import CHAR, TIMESTAMP, ForeignKey, String, Uuid 1ab

6from sqlalchemy.orm import Mapped, mapped_column, relationship 1ab

7 

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

9 

10if TYPE_CHECKING: 10 ↛ 11line 10 didn't jump to line 11 because the condition on line 10 was never true1ab

11 from polar.models import User 

12 

13 

14class LoginCode(RecordModel): 1ab

15 __tablename__ = "login_codes" 1ab

16 

17 code_hash: Mapped[str] = mapped_column( 1ab

18 CHAR(64), nullable=False, index=True, unique=True 

19 ) 

20 expires_at: Mapped[datetime] = mapped_column( 1ab

21 TIMESTAMP(timezone=True), nullable=False, index=True 

22 ) 

23 email: Mapped[str] = mapped_column(String(320), nullable=False, index=True) 1ab

24 

25 user_id: Mapped[UUID | None] = mapped_column( 1ab

26 Uuid, 

27 ForeignKey("users.id", ondelete="cascade"), 

28 nullable=True, 

29 index=True, 

30 ) 

31 user: Mapped["User | None"] = relationship("User", lazy="raise") 1ab