Projekt

Obecné

Profil

Stáhnout (4.92 KB) Statistiky
| Větev: | Tag: | Revize:
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
56
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
class PC(Base):
75 4911f0ea Matej Zeman
    """
76
    Class defining database table pc
77
    """
78 6c1e92e3 Matej Zeman
    __tablename__ = "pc"
79
80
    id = Column(Integer, primary_key=True, index=True)
81
    username = Column(String, index=True, nullable=False)
82
    hostname = Column(String, index=True, nullable=False)
83 99c92c11 Matej Zeman
    assigned = Column(Boolean, index=True, nullable=False)
84
    team_id = Column(Integer, ForeignKey("teams.id"))
85
86 4911f0ea Matej Zeman
    # relationships for foreign keys, thus connecting table with teams, usb_logs and ld_logs
87
    # tables
88 99c92c11 Matej Zeman
    team = relationship("Team", back_populates="pcs")
89 6c1e92e3 Matej Zeman
    logs_pc = relationship("USBLog", back_populates="pc")
90 eaf8ace4 Matej Zeman
    ld_pc = relationship("LDLog", back_populates="ldpc")
91 99c92c11 Matej Zeman
92
93
class Team(Base):
94 4911f0ea Matej Zeman
    """
95
    Class defining database table teams
96
    """
97 99c92c11 Matej Zeman
    __tablename__ = "teams"
98
99
    id = Column(Integer, primary_key=True, index=True)
100
    name = Column(String, index=True, nullable=False)
101 4911f0ea Matej Zeman
102
    # relationships for foreign keys, thus connecting table with pc table
103 99c92c11 Matej Zeman
    pcs = relationship("PC", back_populates="team")
104 eaf8ace4 Matej Zeman
105
106
class HeadDevice(Base):
107 4911f0ea Matej Zeman
    """
108
    Class defining database table head_devices
109
    """
110 eaf8ace4 Matej Zeman
    __tablename__ = "head_devices"
111
112
    id = Column(Integer, primary_key=True, index=True)
113
    serial_number = Column(String, index=True, nullable=False)
114
115 4911f0ea Matej Zeman
    # relationships for foreign keys, thus connecting table with ld_logs table
116 eaf8ace4 Matej Zeman
    h_logs = relationship("LDLog", back_populates="head_device")
117
118
119
class BodyDevice(Base):
120 4911f0ea Matej Zeman
    """
121
    Class defining database table body_devices
122
    """
123 eaf8ace4 Matej Zeman
    __tablename__ = "body_devices"
124
125
    id = Column(Integer, primary_key=True, index=True)
126
    serial_number = Column(String, index=True, nullable=False)
127
128 4911f0ea Matej Zeman
    # relationships for foreign keys, thus connecting table with ld_logs table
129 eaf8ace4 Matej Zeman
    b_logs = relationship("LDLog", back_populates="body_device")
130
131
132
class LDLog(Base):
133 4911f0ea Matej Zeman
    """
134
    Class defining database table ld_logs
135
    """
136 eaf8ace4 Matej Zeman
    __tablename__ = "ld_logs"
137
138
    id = Column(Integer, primary_key=True, index=True)
139
    pc_id = Column(Integer, ForeignKey("pc.id"))
140
    timestamp = Column(DateTime(timezone=True), server_default=func.now())
141
    status = Column(String, index=True, nullable=False)
142
    head_id = Column(Integer, ForeignKey("head_devices.id"))
143
    body_id = Column(Integer, ForeignKey("body_devices.id"))
144
145 4911f0ea Matej Zeman
    # relationships for foreign keys, thus connecting table with pc, head_devices and body_devices
146
    # tables
147 eaf8ace4 Matej Zeman
    ldpc = relationship("PC", back_populates="ld_pc")
148
    head_device = relationship("HeadDevice", back_populates="h_logs")
149
    body_device = relationship("BodyDevice", back_populates="b_logs")