Projekt

Obecné

Profil

Stáhnout (2.47 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
    __tablename__ = "devices"
9
10
    id = Column(Integer, primary_key=True, index=True)
11 99c92c11 Matej Zeman
    vendor_id = Column(String, index=True, nullable=False)
12
    product_id = Column(String, index=True, nullable=False)
13 aba60b70 Matej Zeman
    serial_number = Column(String, index=True, nullable=False)
14 99c92c11 Matej Zeman
    assigned = Column(Boolean, index=True, nullable=False)
15 aba60b70 Matej Zeman
16
    logs = relationship("USBLog", back_populates="device")
17 6c1e92e3 Matej Zeman
    licenses = relationship("DeviceLicense", back_populates="device_lic")
18 aba60b70 Matej Zeman
19
20
class USBLog(Base):
21
    __tablename__ = "usb_logs"
22
23
    id = Column(Integer, primary_key=True, index=True)
24 6c1e92e3 Matej Zeman
    pc_id = Column(Integer, ForeignKey("pc.id"))
25 99c92c11 Matej Zeman
    timestamp = Column(DateTime(timezone=True), server_default=func.now())
26 aba60b70 Matej Zeman
    status = Column(String, index=True, nullable=False)
27
    device_id = Column(Integer, ForeignKey("devices.id"))
28
29
    device = relationship("Device", back_populates="logs")
30 6c1e92e3 Matej Zeman
    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 99c92c11 Matej Zeman
    expiration_date = Column(DateTime(timezone=True), server_default=func.now())
39 6c1e92e3 Matej Zeman
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 ef87a1d2 Matej Zeman
    device_id = Column(Integer, ForeignKey("devices.id"))
48
    license_id = Column(Integer, ForeignKey("licenses.id"))
49 6c1e92e3 Matej Zeman
    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 99c92c11 Matej Zeman
    assigned = Column(Boolean, index=True, nullable=False)
62
    team_id = Column(Integer, ForeignKey("teams.id"))
63
64
    team = relationship("Team", back_populates="pcs")
65 6c1e92e3 Matej Zeman
    logs_pc = relationship("USBLog", back_populates="pc")
66 99c92c11 Matej Zeman
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")