Projekt

Obecné

Profil

Stáhnout (3.6 KB) Statistiky
| Větev: | Tag: | Revize:
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(Integer, ForeignKey("devices.id"))
48
    license_id = Column(Integer, 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
    ld_pc = relationship("LDLog", back_populates="ldpc")
67

    
68

    
69
class Team(Base):
70
    __tablename__ = "teams"
71

    
72
    id = Column(Integer, primary_key=True, index=True)
73
    name = Column(String, index=True, nullable=False)
74
    pcs = relationship("PC", back_populates="team")
75

    
76

    
77
class HeadDevice(Base):
78
    __tablename__ = "head_devices"
79

    
80
    id = Column(Integer, primary_key=True, index=True)
81
    serial_number = Column(String, index=True, nullable=False)
82

    
83
    h_logs = relationship("LDLog", back_populates="head_device")
84

    
85

    
86
class BodyDevice(Base):
87
    __tablename__ = "body_devices"
88

    
89
    id = Column(Integer, primary_key=True, index=True)
90
    serial_number = Column(String, index=True, nullable=False)
91

    
92
    b_logs = relationship("LDLog", back_populates="body_device")
93

    
94

    
95
class LDLog(Base):
96
    __tablename__ = "ld_logs"
97

    
98
    id = Column(Integer, primary_key=True, index=True)
99
    pc_id = Column(Integer, ForeignKey("pc.id"))
100
    timestamp = Column(DateTime(timezone=True), server_default=func.now())
101
    status = Column(String, index=True, nullable=False)
102
    head_id = Column(Integer, ForeignKey("head_devices.id"))
103
    body_id = Column(Integer, ForeignKey("body_devices.id"))
104

    
105
    ldpc = relationship("PC", back_populates="ld_pc")
106
    head_device = relationship("HeadDevice", back_populates="h_logs")
107
    body_device = relationship("BodyDevice", back_populates="b_logs")
(5-5/6)