-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
88 lines (65 loc) · 2.56 KB
/
models.py
File metadata and controls
88 lines (65 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import time
from sqlalchemy import Column, Integer, String, Float, ForeignKey, UniqueConstraint, Index
from pydantic import BaseModel
from database import Base
class User(Base):
__tablename__ = "users"
id = Column(Integer, primary_key=True, index=True)
username = Column(String, unique=True, index=True, nullable=False)
password_hash = Column(String, nullable=False)
class Progress(Base):
__tablename__ = "progress"
id = Column(Integer, primary_key=True, index=True)
user_id = Column(Integer, ForeignKey("users.id"), nullable=False)
document = Column(String, index=True, nullable=False)
progress = Column(String, nullable=False)
percentage = Column(Float, nullable=False)
device = Column(String, nullable=False)
device_id = Column(String, nullable=False)
timestamp = Column(Integer, default=lambda: int(time.time()))
filename = Column(String, nullable=True, index=True)
class ProgressHistory(Base):
__tablename__ = "progress_history"
id = Column(Integer, primary_key=True, index=True)
user_id = Column(Integer, ForeignKey("users.id"), nullable=False)
document = Column(String, nullable=False)
progress = Column(String, nullable=False)
percentage = Column(Float, nullable=False)
device = Column(String, nullable=False)
device_id = Column(String, nullable=False)
timestamp = Column(Integer, nullable=False)
filename = Column(String, nullable=True)
__table_args__ = (
Index('ix_progress_history_user_doc_ts', 'user_id', 'document', 'timestamp'),
)
class DocumentLink(Base):
__tablename__ = "document_links"
id = Column(Integer, primary_key=True, index=True)
user_id = Column(Integer, ForeignKey("users.id"), nullable=False)
document_hash = Column(String, nullable=False, index=True)
canonical_hash = Column(String, nullable=False)
class BookLabel(Base):
__tablename__ = "book_labels"
id = Column(Integer, primary_key=True, index=True)
user_id = Column(Integer, ForeignKey("users.id"), nullable=False)
canonical_hash = Column(String, nullable=False, index=True)
label = Column(String, nullable=False)
__table_args__ = (
UniqueConstraint('user_id', 'canonical_hash', name='uq_user_canonical'),
)
class UserCreate(BaseModel):
username: str
password: str
class ProgressUpdate(BaseModel):
document: str
progress: str
percentage: float
device: str
device_id: str
class ProgressResponse(BaseModel):
document: str
progress: str
percentage: float
device: str
device_id: str
timestamp: int