-
Notifications
You must be signed in to change notification settings - Fork 2
/
models.py
88 lines (78 loc) · 2.86 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
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
from sqlalchemy import Column, Integer, String, DateTime, Boolean, JSON, Float
from sqlalchemy_utils import UUIDType
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.ext.mutable import MutableList
from sqlalchemy.types import Date
from database import *
from fastapi_utils.guid_type import GUID, GUID_DEFAULT_SQLITE
from werkzeug.security import generate_password_hash, check_password_hash
import uuid
'''
Separate file just for models to help maintain structure in database,
should align with schemas.py.
'''
class User(Base):
__tablename__ = 'users'
user_id = Column(UUIDType(binary=False), primary_key=True, default=uuid.uuid4)
reset_id= Column(UUIDType(binary=False))
create_date = Column(DateTime)
# get information
email = Column(String(128))
password_hash = Column(String(128))
is_confirmed = Column(Boolean, default=False)
# name/language
first_name = Column(String(128))
last_name = Column(String(128))
language = Column(String(20), default='en-us')
# other user information
last_update = Column(DateTime)
last_email = Column(DateTime)
last_login = Column(DateTime)
last_login_city = Column(String(128))
last_login_state = Column(String(128))
last_login_country = Column(String(128))
last_login_ip = Column(String(128))
login_number = Column(Integer, default=0)
signup_ip = Column(String(128))
image_link = Column(String(256))
phone_number = Column(String(128))
gender = Column(String(128))
age = Column(Float)
# default_settings
sound=Column(String(128))
voice=Column(String(128))
response_type=Column(String(128))
audio_delete = Column(Boolean, default=False)
# hashing functions for users/passwords
def hash_password(self, password):
self.password_hash = generate_password_hash(password)
def verify_password(self, password):
return check_password_hash(self.password_hash, password)
class Session(Base):
__tablename__ = 'sessions'
session_id = Column(UUIDType(binary=False), primary_key=True, default=uuid.uuid4)
user_id = Column(UUIDType(binary=False))
create_date = Column(DateTime)
class Query(Base):
__tablename__ = 'queries'
query_id = Column(UUIDType(binary=False), primary_key=True, default=uuid.uuid4)
session_id=Column(UUIDType(binary=False))
user_id=Column(UUIDType(binary=False))
create_date = Column(DateTime)
features = Column(String(1028))
transcript = Column(String(128))
bucket = Column(String(128))
rating = Column(Integer)
response = Column(String(1028))
response_method = Column(String(128))
language = Column(String(20), default='en-us')
city = Column(String(128))
state = Column(String(128))
country = Column(String(128))
audio_delete = Column(Boolean, default=False)
class Integration(Base):
__tablename__ = 'integrations'
integration_id = Column(UUIDType(binary=False), primary_key=True, default=uuid.uuid4)
create_date = Column(DateTime)
name = Column(String(128))
credentials = Column(String(2048))