forked from Study-Together-Org/time_counter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
49 lines (36 loc) · 1.62 KB
/
models.py
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
import os
from dotenv import load_dotenv
from sqlalchemy import ForeignKey, Column, String
from sqlalchemy.dialects.mysql import DATETIME, INTEGER, BIGINT
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship
import utilities
load_dotenv("dev.env")
database_name = os.getenv("database")
varchar_length = int(os.getenv("varchar_length"))
DATETIME = DATETIME(fsp=int(os.getenv("time_fsp")))
Base = declarative_base()
action_categories = [
"start channel", "end channel", "start stream", "end stream", "start video", "end video", "start voice",
"end voice",
# Currently timer logs are not implemented
# "start timer", "end timer"
]
class User(Base):
# Question - How to make it just use the class name instead of hard coding the table name?
__tablename__ = 'user'
id = Column(BIGINT, primary_key=True)
longest_streak = Column(INTEGER, server_default="0")
current_streak = Column(INTEGER, server_default="0")
class Action(Base):
__tablename__ = 'action'
id = Column(INTEGER, primary_key=True)
user_id = Column(BIGINT, ForeignKey('user.id', onupdate="CASCADE"), nullable=False, index=True)
category = Column(String(varchar_length), nullable=False)
detail = Column(BIGINT) # Currently, detail is the id of the channel where actions happen
creation_time = Column(DATETIME, default=utilities.get_time)
user = relationship("User", back_populates="action")
# This must be in global scope for correct models
User.action = relationship("Action", order_by=Action.id, back_populates="user")
if __name__ == '__main__':
utilities.recreate_db(Base)