from sqlalchemy import UUID, Column, Date, Float, ForeignKey, Integer, String, Boolean from sqlalchemy.orm import relationship from src.database.core import Base from src.models import DefaultMixin class StandardScope(Base, DefaultMixin): __tablename__ = 'oh_ms_standard_scope' location_tag = Column(String, nullable=False) is_alternating_oh = Column(Boolean, nullable=False, default=False) assigned_date = Column(Date, nullable=True) service_cost = Column(Float, nullable=True) master_equipment = relationship('MasterEquipment', lazy='selectin', primaryjoin='and_(StandardScope.location_tag == foreign(MasterEquipment.location_tag))', uselist=False) oh_history = relationship('EquipmentOHHistory', lazy='selectin', primaryjoin='and_(StandardScope.location_tag == foreign(EquipmentOHHistory.location_tag))', uselist=False) workscope_groups = relationship('EquipmentWorkscopeGroup', lazy='selectin', primaryjoin='and_(EquipmentWorkscopeGroup.location_tag == foreign(StandardScope.location_tag))', uselist=True) class EquipmentOHHistory(Base, DefaultMixin): __tablename__ = 'oh_ms_equipment_oh_history' location_tag = Column(String, nullable=False) last_oh_date = Column(Date, nullable=True) last_oh_type = Column(String, nullable=True) class MasterEquipment(Base, DefaultMixin): __tablename__ = 'ms_equipment_master' id = Column(UUID(as_uuid=True), primary_key=True, index=True) parent_id = Column(UUID(as_uuid=True), ForeignKey('ms_equipment_master.id', ondelete='CASCADE'), nullable=True) assetnum = Column(String, nullable=True) system_tag = Column(String, nullable=True) location_tag = Column(String, nullable=True) name = Column(String, nullable=True) equipment_tree_id = Column(UUID(as_uuid=True), ForeignKey('ms_equipment_tree.id'), nullable=True) equipment_tree = relationship('MasterEquipmentTree', backref='master_equipments') parent = relationship('MasterEquipment', remote_side=[id], lazy='selectin') class MasterEquipmentTree(Base, DefaultMixin): __tablename__ = 'ms_equipment_tree' level_no = Column(Integer)