1
|
from sqlalchemy import Boolean, Column, ForeignKey, Integer, String, DateTime
|
2
|
from sqlalchemy.orm import relationship
|
3
|
from sqlalchemy.sql import func
|
4
|
from .database import Base
|
5
|
|
6
|
|
7
|
class Device(Base):
|
8
|
"""
|
9
|
Class defining database table devices
|
10
|
"""
|
11
|
__tablename__ = "devices"
|
12
|
|
13
|
id = Column(Integer, primary_key=True, index=True)
|
14
|
vendor_id = Column(String, index=True, nullable=False)
|
15
|
product_id = Column(String, index=True, nullable=False)
|
16
|
serial_number = Column(String, index=True, nullable=False)
|
17
|
assigned = Column(Boolean, index=True, nullable=False)
|
18
|
|
19
|
# relationships for foreign keys, thus connecting table with usb_logs and licenses
|
20
|
# tables
|
21
|
logs = relationship("USBLog", back_populates="device")
|
22
|
licenses = relationship("DeviceLicense", back_populates="device_lic")
|
23
|
|
24
|
|
25
|
class USBLog(Base):
|
26
|
"""
|
27
|
Class defining database table usb_logs
|
28
|
"""
|
29
|
__tablename__ = "usb_logs"
|
30
|
|
31
|
id = Column(Integer, primary_key=True, index=True)
|
32
|
pc_id = Column(Integer, ForeignKey("pc.id"))
|
33
|
timestamp = Column(DateTime(timezone=True), server_default=func.now())
|
34
|
status = Column(String, index=True, nullable=False)
|
35
|
device_id = Column(Integer, ForeignKey("devices.id"))
|
36
|
|
37
|
# relationships for foreign keys, thus connecting table with devices and pc
|
38
|
# tables
|
39
|
device = relationship("Device", back_populates="logs")
|
40
|
pc = relationship("PC", back_populates="logs_pc")
|
41
|
|
42
|
|
43
|
class License(Base):
|
44
|
"""
|
45
|
Class defining database table licenses
|
46
|
"""
|
47
|
__tablename__ = "licenses"
|
48
|
|
49
|
id = Column(Integer, primary_key=True, index=True)
|
50
|
name = Column(String, index=True, nullable=False)
|
51
|
expiration_date = Column(DateTime(timezone=True), server_default=func.now())
|
52
|
|
53
|
# relationships for foreign keys, thus connecting table with devices table
|
54
|
devices = relationship("DeviceLicense", back_populates="licenses")
|
55
|
body_devices = relationship("BodyDeviceLicense", back_populates="b_licenses")
|
56
|
|
57
|
class DeviceLicense(Base):
|
58
|
"""
|
59
|
Class defining database table devices_licenses
|
60
|
"""
|
61
|
__tablename__ = "devices_licenses"
|
62
|
|
63
|
id = Column(Integer, primary_key=True, index=True)
|
64
|
device_id = Column(Integer, ForeignKey("devices.id"))
|
65
|
license_id = Column(Integer, ForeignKey("licenses.id"))
|
66
|
assigned_datetime = Column(String, index=True, nullable=False)
|
67
|
|
68
|
# relationships for foreign keys, thus connecting table with devices and licenses
|
69
|
# tables
|
70
|
device_lic = relationship("Device", back_populates="licenses")
|
71
|
licenses = relationship("License", back_populates="devices")
|
72
|
|
73
|
|
74
|
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
|
class PC(Base):
|
92
|
"""
|
93
|
Class defining database table pc
|
94
|
"""
|
95
|
__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
|
assigned = Column(Boolean, index=True, nullable=False)
|
101
|
team_id = Column(Integer, ForeignKey("teams.id"))
|
102
|
|
103
|
# relationships for foreign keys, thus connecting table with teams, usb_logs and ld_logs
|
104
|
# tables
|
105
|
team = relationship("Team", back_populates="pcs")
|
106
|
logs_pc = relationship("USBLog", back_populates="pc")
|
107
|
ld_pc = relationship("LDLog", back_populates="ldpc")
|
108
|
|
109
|
|
110
|
class Team(Base):
|
111
|
"""
|
112
|
Class defining database table teams
|
113
|
"""
|
114
|
__tablename__ = "teams"
|
115
|
|
116
|
id = Column(Integer, primary_key=True, index=True)
|
117
|
name = Column(String, index=True, nullable=False)
|
118
|
|
119
|
# relationships for foreign keys, thus connecting table with pc table
|
120
|
pcs = relationship("PC", back_populates="team")
|
121
|
|
122
|
|
123
|
class HeadDevice(Base):
|
124
|
"""
|
125
|
Class defining database table head_devices
|
126
|
"""
|
127
|
__tablename__ = "head_devices"
|
128
|
|
129
|
id = Column(Integer, primary_key=True, index=True)
|
130
|
serial_number = Column(String, index=True, nullable=False)
|
131
|
|
132
|
# relationships for foreign keys, thus connecting table with ld_logs table
|
133
|
h_logs = relationship("LDLog", back_populates="head_device")
|
134
|
|
135
|
|
136
|
class BodyDevice(Base):
|
137
|
"""
|
138
|
Class defining database table body_devices
|
139
|
"""
|
140
|
__tablename__ = "body_devices"
|
141
|
|
142
|
id = Column(Integer, primary_key=True, index=True)
|
143
|
serial_number = Column(String, index=True, nullable=False)
|
144
|
|
145
|
# relationships for foreign keys, thus connecting table with ld_logs table
|
146
|
b_logs = relationship("LDLog", back_populates="body_device")
|
147
|
debug_licenses = relationship("BodyDeviceLicense", back_populates="bodydevice_lic")
|
148
|
|
149
|
|
150
|
class LDLog(Base):
|
151
|
"""
|
152
|
Class defining database table ld_logs
|
153
|
"""
|
154
|
__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
|
# relationships for foreign keys, thus connecting table with pc, head_devices and body_devices
|
164
|
# tables
|
165
|
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")
|