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
|
__tablename__ = "devices"
|
9
|
|
10
|
id = Column(Integer, primary_key=True, index=True)
|
11
|
vendor_id = Column(String, index=True, nullable=False)
|
12
|
product_id = Column(String, index=True, nullable=False)
|
13
|
serial_number = Column(String, index=True, nullable=False)
|
14
|
assigned = Column(Boolean, index=True, nullable=False)
|
15
|
|
16
|
logs = relationship("USBLog", back_populates="device")
|
17
|
licenses = relationship("DeviceLicense", back_populates="device_lic")
|
18
|
|
19
|
|
20
|
class USBLog(Base):
|
21
|
__tablename__ = "usb_logs"
|
22
|
|
23
|
id = Column(Integer, primary_key=True, index=True)
|
24
|
pc_id = Column(Integer, ForeignKey("pc.id"))
|
25
|
timestamp = Column(DateTime(timezone=True), server_default=func.now())
|
26
|
status = Column(String, index=True, nullable=False)
|
27
|
device_id = Column(Integer, ForeignKey("devices.id"))
|
28
|
|
29
|
device = relationship("Device", back_populates="logs")
|
30
|
pc = relationship("PC", back_populates="logs_pc")
|
31
|
|
32
|
|
33
|
class License(Base):
|
34
|
__tablename__ = "licenses"
|
35
|
|
36
|
id = Column(Integer, primary_key=True, index=True)
|
37
|
name = Column(String, index=True, nullable=False)
|
38
|
expiration_date = Column(DateTime(timezone=True), server_default=func.now())
|
39
|
|
40
|
devices = relationship("DeviceLicense", back_populates="licenses")
|
41
|
|
42
|
|
43
|
class DeviceLicense(Base):
|
44
|
__tablename__ = "devices_licenses"
|
45
|
|
46
|
id = Column(Integer, primary_key=True, index=True)
|
47
|
device_id = Column(String, ForeignKey("devices.id"))
|
48
|
license_id = Column(String, ForeignKey("licenses.id"))
|
49
|
assigned_datetime = Column(String, index=True, nullable=False)
|
50
|
|
51
|
device_lic = relationship("Device", back_populates="licenses")
|
52
|
licenses = relationship("License", back_populates="devices")
|
53
|
|
54
|
|
55
|
class PC(Base):
|
56
|
__tablename__ = "pc"
|
57
|
|
58
|
id = Column(Integer, primary_key=True, index=True)
|
59
|
username = Column(String, index=True, nullable=False)
|
60
|
hostname = Column(String, index=True, nullable=False)
|
61
|
assigned = Column(Boolean, index=True, nullable=False)
|
62
|
team_id = Column(Integer, ForeignKey("teams.id"))
|
63
|
|
64
|
team = relationship("Team", back_populates="pcs")
|
65
|
logs_pc = relationship("USBLog", back_populates="pc")
|
66
|
|
67
|
|
68
|
class Team(Base):
|
69
|
__tablename__ = "teams"
|
70
|
|
71
|
id = Column(Integer, primary_key=True, index=True)
|
72
|
name = Column(String, index=True, nullable=False)
|
73
|
pcs = relationship("PC", back_populates="team")
|