-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
executable file
·144 lines (115 loc) · 4.6 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
from datetime import datetime
from enum import Enum
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy import Boolean, Column, DateTime, Float, ForeignKey, Integer, String
from sqlalchemy.orm import DeclarativeBase, relationship
class UserRole(Enum):
admin = 1
user = 2
class Base(DeclarativeBase):
pass
db = SQLAlchemy(model_class=Base)
class User(db.Model):
__tablename__ = "user"
id = Column(Integer, primary_key=True, index=True)
created_datetime = Column(DateTime(timezone=True), default=datetime.utcnow)
last_modified_datetime = Column(DateTime(timezone=True), default=datetime.utcnow)
first_name = Column(String)
last_name = Column(String)
username = Column(String, unique=True, nullable=False, index=True)
description = Column(String)
email = Column(String)
password = Column(String)
role = Column(Integer, default=UserRole.user.value)
hurls = relationship("Hurl", back_populates="user", cascade="all, delete")
def __unicode__(self):
return self.username
class Visit(db.Model):
__tablename__ = "visit"
id = Column(Integer, primary_key=True, index=True)
token = Column(String, index=True)
x_forwarded_for = Column(String, index=True)
remote_addr = Column(String, index=True)
referrer = Column(String, index=True)
content_md5 = Column(String)
origin = Column(String)
view_args = Column(String)
scheme = Column(String)
method = Column(String)
root_path = Column(String)
path = Column(String, index=True)
query_string = Column(String)
duration = Column(Float)
start_datetime_utc = Column(DateTime(timezone=True))
end_datetime_utc = Column(DateTime(timezone=True))
user_agent = Column(String)
x_forwarded_proto = Column(String)
x_forwarded_host = Column(String)
x_forwarded_prefix = Column(String)
host = Column(String)
connection = Column(String)
accept = Column(String)
accept_language = Column(String)
accept_encoding = Column(String)
dnt = Column(String)
upgrade_insecure_requests = Column(String)
sec_fetch_dest = Column(String)
sec_fetch_mode = Column(String)
sec_fetch_site = Column(String)
sec_fetch_user = Column(String)
headers = Column(String)
cookies = Column(String)
content_length = Column(Integer)
hurl_id = Column(Integer, ForeignKey("hurl.id"), nullable=False, index=True)
hurl = relationship("Hurl", back_populates="visits")
def __unicode__(self):
return f"Visit {self.id}: {self.x_forwarded_for}: {self.start_datetime_utc}"
class Hurl(db.Model):
__tablename__ = "hurl"
id = Column(Integer, primary_key=True, index=True)
token = Column(String, nullable=False, index=True)
name = Column(String)
pixel_name = Column(String)
url = Column(String, nullable=False)
created_datetime = Column(DateTime(timezone=True), default=datetime.utcnow)
last_modified_datetime = Column(DateTime(timezone=True), default=datetime.utcnow)
is_active = Column(Boolean, default=True)
is_deleted = Column(Boolean, default=False)
deleted_datetime = Column(DateTime(timezone=True), default=datetime.utcnow)
user_id = Column(Integer, ForeignKey("user.id"), nullable=False, index=True)
user = relationship("User", back_populates="hurls")
visits = relationship("Visit", back_populates="hurl", cascade="all, delete")
def __unicode__(self):
return f"Hurl {self.id}: {self.name}"
class Contact(db.Model):
__tablename__ = "contact"
id = Column(Integer, primary_key=True, index=True)
name = Column(String)
email = Column(String)
message = Column(String, nullable=False)
created_datetime = Column(DateTime(timezone=True), nullable=False, default=datetime.utcnow)
class Log(db.Model):
__tablename__ = "log"
id = Column(Integer, primary_key=True, index=True)
x_forwarded_for = Column(String, index=True)
remote_addr = Column(String, index=True)
referrer = Column(String, index=True)
content_md5 = Column(String)
origin = Column(String)
scheme = Column(String)
method = Column(String)
path = Column(String, index=True)
query_string = Column(String)
duration = Column(Float)
start_datetime_utc = Column(DateTime(timezone=True))
end_datetime_utc = Column(DateTime(timezone=True))
user_agent = Column(String)
accept = Column(String)
accept_language = Column(String)
accept_encoding = Column(String)
content_length = Column(Integer)
class Error(db.Model):
__tablename__ = "error"
id = Column(Integer, primary_key=True, index=True)
status_code = Column(Integer)
details = Column(String)