Flask backend with Vue 3 frontend for shop floor machine management. Includes database schema export for MySQL shopdb_flask database. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
78 lines
2.0 KiB
Python
78 lines
2.0 KiB
Python
"""Machine relationship models."""
|
|
|
|
from shopdb.extensions import db
|
|
from .base import BaseModel
|
|
|
|
|
|
class RelationshipType(BaseModel):
|
|
"""Types of relationships between machines."""
|
|
__tablename__ = 'relationshiptypes'
|
|
|
|
relationshiptypeid = db.Column(db.Integer, primary_key=True)
|
|
relationshiptype = db.Column(db.String(50), unique=True, nullable=False)
|
|
description = db.Column(db.Text)
|
|
|
|
# Example types:
|
|
# - "Controls" (PC controls Equipment)
|
|
# - "Dualpath" (Redundant path partner)
|
|
# - "Backup" (Backup machine)
|
|
|
|
def __repr__(self):
|
|
return f"<RelationshipType {self.relationshiptype}>"
|
|
|
|
|
|
class MachineRelationship(BaseModel):
|
|
"""
|
|
Relationships between machines.
|
|
|
|
Examples:
|
|
- PC controls CNC machine
|
|
- Two CNCs are dualpath partners
|
|
"""
|
|
__tablename__ = 'machinerelationships'
|
|
|
|
relationshipid = db.Column(db.Integer, primary_key=True)
|
|
|
|
parentmachineid = db.Column(
|
|
db.Integer,
|
|
db.ForeignKey('machines.machineid'),
|
|
nullable=False
|
|
)
|
|
childmachineid = db.Column(
|
|
db.Integer,
|
|
db.ForeignKey('machines.machineid'),
|
|
nullable=False
|
|
)
|
|
relationshiptypeid = db.Column(
|
|
db.Integer,
|
|
db.ForeignKey('relationshiptypes.relationshiptypeid'),
|
|
nullable=False
|
|
)
|
|
|
|
notes = db.Column(db.Text)
|
|
|
|
# Relationships
|
|
parent_machine = db.relationship(
|
|
'Machine',
|
|
foreign_keys=[parentmachineid],
|
|
backref='child_relationships'
|
|
)
|
|
child_machine = db.relationship(
|
|
'Machine',
|
|
foreign_keys=[childmachineid],
|
|
backref='parent_relationships'
|
|
)
|
|
relationship_type = db.relationship('RelationshipType', backref='relationships')
|
|
|
|
__table_args__ = (
|
|
db.UniqueConstraint(
|
|
'parentmachineid',
|
|
'childmachineid',
|
|
'relationshiptypeid',
|
|
name='uq_machine_relationship'
|
|
),
|
|
)
|
|
|
|
def __repr__(self):
|
|
return f"<MachineRelationship {self.parentmachineid} -> {self.childmachineid}>"
|