1 |
99c92c11
|
Matej Zeman
|
from sqlalchemy import Boolean, Column, ForeignKey, Integer, String, DateTime
|
2 |
aba60b70
|
Matej Zeman
|
from sqlalchemy.orm import relationship
|
3 |
99c92c11
|
Matej Zeman
|
from sqlalchemy.sql import func
|
4 |
aba60b70
|
Matej Zeman
|
from .database import Base
|
5 |
|
|
|
6 |
|
|
|
7 |
|
|
class Device(Base):
|
8 |
4911f0ea
|
Matej Zeman
|
"""
|
9 |
|
|
Class defining database table devices
|
10 |
|
|
"""
|
11 |
aba60b70
|
Matej Zeman
|
__tablename__ = "devices"
|
12 |
|
|
|
13 |
|
|
id = Column(Integer, primary_key=True, index=True)
|
14 |
99c92c11
|
Matej Zeman
|
vendor_id = Column(String, index=True, nullable=False)
|
15 |
|
|
product_id = Column(String, index=True, nullable=False)
|
16 |
aba60b70
|
Matej Zeman
|
serial_number = Column(String, index=True, nullable=False)
|
17 |
99c92c11
|
Matej Zeman
|
assigned = Column(Boolean, index=True, nullable=False)
|
18 |
aba60b70
|
Matej Zeman
|
|
19 |
4911f0ea
|
Matej Zeman
|
# relationships for foreign keys, thus connecting table with usb_logs and licenses
|
20 |
|
|
# tables
|
21 |
aba60b70
|
Matej Zeman
|
logs = relationship("USBLog", back_populates="device")
|
22 |
6c1e92e3
|
Matej Zeman
|
licenses = relationship("DeviceLicense", back_populates="device_lic")
|
23 |
aba60b70
|
Matej Zeman
|
|
24 |
|
|
|
25 |
|
|
class USBLog(Base):
|
26 |
4911f0ea
|
Matej Zeman
|
"""
|
27 |
|
|
Class defining database table usb_logs
|
28 |
|
|
"""
|
29 |
aba60b70
|
Matej Zeman
|
__tablename__ = "usb_logs"
|
30 |
|
|
|
31 |
|
|
id = Column(Integer, primary_key=True, index=True)
|
32 |
6c1e92e3
|
Matej Zeman
|
pc_id = Column(Integer, ForeignKey("pc.id"))
|
33 |
99c92c11
|
Matej Zeman
|
timestamp = Column(DateTime(timezone=True), server_default=func.now())
|
34 |
aba60b70
|
Matej Zeman
|
status = Column(String, index=True, nullable=False)
|
35 |
|
|
device_id = Column(Integer, ForeignKey("devices.id"))
|
36 |
|
|
|
37 |
4911f0ea
|
Matej Zeman
|
# relationships for foreign keys, thus connecting table with devices and pc
|
38 |
|
|
# tables
|
39 |
aba60b70
|
Matej Zeman
|
device = relationship("Device", back_populates="logs")
|
40 |
6c1e92e3
|
Matej Zeman
|
pc = relationship("PC", back_populates="logs_pc")
|
41 |
|
|
|
42 |
|
|
|
43 |
|
|
class License(Base):
|
44 |
4911f0ea
|
Matej Zeman
|
"""
|
45 |
|
|
Class defining database table licenses
|
46 |
|
|
"""
|
47 |
6c1e92e3
|
Matej Zeman
|
__tablename__ = "licenses"
|
48 |
|
|
|
49 |
|
|
id = Column(Integer, primary_key=True, index=True)
|
50 |
|
|
name = Column(String, index=True, nullable=False)
|
51 |
99c92c11
|
Matej Zeman
|
expiration_date = Column(DateTime(timezone=True), server_default=func.now())
|
52 |
6c1e92e3
|
Matej Zeman
|
|
53 |
4911f0ea
|
Matej Zeman
|
# relationships for foreign keys, thus connecting table with devices table
|
54 |
6c1e92e3
|
Matej Zeman
|
devices = relationship("DeviceLicense", back_populates="licenses")
|
55 |
7fe7be79
|
zemanm98@students.zcu.cz
|
body_devices = relationship("BodyDeviceLicense", back_populates="b_licenses")
|
56 |
6c1e92e3
|
Matej Zeman
|
|
57 |
|
|
class DeviceLicense(Base):
|
58 |
4911f0ea
|
Matej Zeman
|
"""
|
59 |
|
|
Class defining database table devices_licenses
|
60 |
|
|
"""
|
61 |
6c1e92e3
|
Matej Zeman
|
__tablename__ = "devices_licenses"
|
62 |
|
|
|
63 |
|
|
id = Column(Integer, primary_key=True, index=True)
|
64 |
ef87a1d2
|
Matej Zeman
|
device_id = Column(Integer, ForeignKey("devices.id"))
|
65 |
|
|
license_id = Column(Integer, ForeignKey("licenses.id"))
|
66 |
6c1e92e3
|
Matej Zeman
|
assigned_datetime = Column(String, index=True, nullable=False)
|
67 |
|
|
|
68 |
4911f0ea
|
Matej Zeman
|
# relationships for foreign keys, thus connecting table with devices and licenses
|
69 |
|
|
# tables
|
70 |
6c1e92e3
|
Matej Zeman
|
device_lic = relationship("Device", back_populates="licenses")
|
71 |
|
|
licenses = relationship("License", back_populates="devices")
|
72 |
|
|
|
73 |
|
|
|
74 |
7fe7be79
|
zemanm98@students.zcu.cz
|
class BodyDeviceLicense(Base):
|
75 |
|
|
"""
|
76 |
|
|
Class defining database table bodydevices_licenses
|
77 |
|
|
"""
|
78 |
|
|
__tablename__ = "bodydevices_licenses"
|
79 |
|
|
|
80 |
|
|
id = Column(Integer, primary_key=True, index=True)
|
81 |
|
|
bodydevice_id = Column(Integer, ForeignKey("body_devices.id"))
|
82 |
|
|
license_id = Column(Integer, ForeignKey("licenses.id"))
|
83 |
|
|
assigned_datetime = Column(String, index=True, nullable=False)
|
84 |
|
|
|
85 |
|
|
# relationships for foreign keys, thus connecting table with devices and licenses
|
86 |
|
|
# tables
|
87 |
|
|
bodydevice_lic = relationship("BodyDevice", back_populates="debug_licenses")
|
88 |
|
|
b_licenses = relationship("License", back_populates="body_devices")
|
89 |
|
|
|
90 |
|
|
|
91 |
6c1e92e3
|
Matej Zeman
|
class PC(Base):
|
92 |
4911f0ea
|
Matej Zeman
|
"""
|
93 |
|
|
Class defining database table pc
|
94 |
|
|
"""
|
95 |
6c1e92e3
|
Matej Zeman
|
__tablename__ = "pc"
|
96 |
|
|
|
97 |
|
|
id = Column(Integer, primary_key=True, index=True)
|
98 |
|
|
username = Column(String, index=True, nullable=False)
|
99 |
|
|
hostname = Column(String, index=True, nullable=False)
|
100 |
99c92c11
|
Matej Zeman
|
assigned = Column(Boolean, index=True, nullable=False)
|
101 |
|
|
team_id = Column(Integer, ForeignKey("teams.id"))
|
102 |
|
|
|
103 |
4911f0ea
|
Matej Zeman
|
# relationships for foreign keys, thus connecting table with teams, usb_logs and ld_logs
|
104 |
|
|
# tables
|
105 |
99c92c11
|
Matej Zeman
|
team = relationship("Team", back_populates="pcs")
|
106 |
6c1e92e3
|
Matej Zeman
|
logs_pc = relationship("USBLog", back_populates="pc")
|
107 |
eaf8ace4
|
Matej Zeman
|
ld_pc = relationship("LDLog", back_populates="ldpc")
|
108 |
99c92c11
|
Matej Zeman
|
|
109 |
|
|
|
110 |
|
|
class Team(Base):
|
111 |
4911f0ea
|
Matej Zeman
|
"""
|
112 |
|
|
Class defining database table teams
|
113 |
|
|
"""
|
114 |
99c92c11
|
Matej Zeman
|
__tablename__ = "teams"
|
115 |
|
|
|
116 |
|
|
id = Column(Integer, primary_key=True, index=True)
|
117 |
|
|
name = Column(String, index=True, nullable=False)
|
118 |
4911f0ea
|
Matej Zeman
|
|
119 |
|
|
# relationships for foreign keys, thus connecting table with pc table
|
120 |
99c92c11
|
Matej Zeman
|
pcs = relationship("PC", back_populates="team")
|
121 |
eaf8ace4
|
Matej Zeman
|
|
122 |
|
|
|
123 |
|
|
class HeadDevice(Base):
|
124 |
4911f0ea
|
Matej Zeman
|
"""
|
125 |
|
|
Class defining database table head_devices
|
126 |
|
|
"""
|
127 |
eaf8ace4
|
Matej Zeman
|
__tablename__ = "head_devices"
|
128 |
|
|
|
129 |
|
|
id = Column(Integer, primary_key=True, index=True)
|
130 |
|
|
serial_number = Column(String, index=True, nullable=False)
|
131 |
|
|
|
132 |
4911f0ea
|
Matej Zeman
|
# relationships for foreign keys, thus connecting table with ld_logs table
|
133 |
eaf8ace4
|
Matej Zeman
|
h_logs = relationship("LDLog", back_populates="head_device")
|
134 |
|
|
|
135 |
|
|
|
136 |
|
|
class BodyDevice(Base):
|
137 |
4911f0ea
|
Matej Zeman
|
"""
|
138 |
|
|
Class defining database table body_devices
|
139 |
|
|
"""
|
140 |
eaf8ace4
|
Matej Zeman
|
__tablename__ = "body_devices"
|
141 |
|
|
|
142 |
|
|
id = Column(Integer, primary_key=True, index=True)
|
143 |
|
|
serial_number = Column(String, index=True, nullable=False)
|
144 |
|
|
|
145 |
4911f0ea
|
Matej Zeman
|
# relationships for foreign keys, thus connecting table with ld_logs table
|
146 |
eaf8ace4
|
Matej Zeman
|
b_logs = relationship("LDLog", back_populates="body_device")
|
147 |
7fe7be79
|
zemanm98@students.zcu.cz
|
debug_licenses = relationship("BodyDeviceLicense", back_populates="bodydevice_lic")
|
148 |
eaf8ace4
|
Matej Zeman
|
|
149 |
|
|
|
150 |
|
|
class LDLog(Base):
|
151 |
4911f0ea
|
Matej Zeman
|
"""
|
152 |
|
|
Class defining database table ld_logs
|
153 |
|
|
"""
|
154 |
eaf8ace4
|
Matej Zeman
|
__tablename__ = "ld_logs"
|
155 |
|
|
|
156 |
|
|
id = Column(Integer, primary_key=True, index=True)
|
157 |
|
|
pc_id = Column(Integer, ForeignKey("pc.id"))
|
158 |
|
|
timestamp = Column(DateTime(timezone=True), server_default=func.now())
|
159 |
|
|
status = Column(String, index=True, nullable=False)
|
160 |
|
|
head_id = Column(Integer, ForeignKey("head_devices.id"))
|
161 |
|
|
body_id = Column(Integer, ForeignKey("body_devices.id"))
|
162 |
|
|
|
163 |
4911f0ea
|
Matej Zeman
|
# relationships for foreign keys, thus connecting table with pc, head_devices and body_devices
|
164 |
|
|
# tables
|
165 |
eaf8ace4
|
Matej Zeman
|
ldpc = relationship("PC", back_populates="ld_pc")
|
166 |
|
|
head_device = relationship("HeadDevice", back_populates="h_logs")
|
167 |
|
|
body_device = relationship("BodyDevice", back_populates="b_logs")
|