39 lines
1.6 KiB
Python
Executable File
39 lines
1.6 KiB
Python
Executable File
"""
|
|
Linux BenchTools - Device Model
|
|
"""
|
|
|
|
from sqlalchemy import Column, Integer, String, DateTime, Text, Float
|
|
from sqlalchemy.orm import relationship
|
|
from datetime import datetime
|
|
from app.db.base import Base
|
|
|
|
|
|
class Device(Base):
|
|
"""
|
|
Represents a machine (physical or virtual)
|
|
"""
|
|
__tablename__ = "devices"
|
|
|
|
id = Column(Integer, primary_key=True, index=True, autoincrement=True)
|
|
hostname = Column(String(255), nullable=False, index=True)
|
|
fqdn = Column(String(255), nullable=True)
|
|
description = Column(Text, nullable=True)
|
|
asset_tag = Column(String(100), nullable=True)
|
|
location = Column(String(255), nullable=True)
|
|
owner = Column(String(100), nullable=True)
|
|
tags = Column(Text, nullable=True) # JSON or comma-separated
|
|
purchase_store = Column(String(255), nullable=True)
|
|
purchase_date = Column(String(50), nullable=True)
|
|
purchase_price = Column(Float, nullable=True)
|
|
created_at = Column(DateTime, nullable=False, default=datetime.utcnow)
|
|
updated_at = Column(DateTime, nullable=False, default=datetime.utcnow, onupdate=datetime.utcnow)
|
|
|
|
# Relationships
|
|
hardware_snapshots = relationship("HardwareSnapshot", back_populates="device", cascade="all, delete-orphan")
|
|
benchmarks = relationship("Benchmark", back_populates="device", cascade="all, delete-orphan")
|
|
manufacturer_links = relationship("ManufacturerLink", back_populates="device", cascade="all, delete-orphan")
|
|
documents = relationship("Document", back_populates="device", cascade="all, delete-orphan")
|
|
|
|
def __repr__(self):
|
|
return f"<Device(id={self.id}, hostname='{self.hostname}')>"
|