Initial monorepo structure
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
"""Additional models."""
|
||||
|
||||
from sqlalchemy import Column, String, Text, Integer, ForeignKey, Boolean
|
||||
from sqlalchemy.orm import relationship
|
||||
from app.models.base import Base, TimestampMixin
|
||||
|
||||
|
||||
class Company(Base, TimestampMixin):
|
||||
"""Company model."""
|
||||
|
||||
__tablename__ = "companies"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
name = Column(String(255), unique=True, nullable=False)
|
||||
address = Column(Text)
|
||||
phone = Column(String(50))
|
||||
website = Column(String(255))
|
||||
|
||||
# Relationships
|
||||
tickets = relationship("Ticket", back_populates="company")
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"<Company(id={self.id}, name='{self.name}')>"
|
||||
|
||||
|
||||
class Location(Base, TimestampMixin):
|
||||
"""Location model."""
|
||||
|
||||
__tablename__ = "locations"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
name = Column(String(255), unique=True, nullable=False)
|
||||
address = Column(Text)
|
||||
phone = Column(String(50))
|
||||
|
||||
# Relationships
|
||||
tickets = relationship("Ticket", back_populates="location")
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"<Location(id={self.id}, name='{self.name}')>"
|
||||
|
||||
|
||||
class Department(Base, TimestampMixin):
|
||||
"""Department model."""
|
||||
|
||||
__tablename__ = "departments"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
name = Column(String(255), unique=True, nullable=False)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"<Department(id={self.id}, name='{self.name}')>"
|
||||
|
||||
|
||||
class UserDepartment(Base, TimestampMixin):
|
||||
"""UserDepartment model - local department assignments."""
|
||||
|
||||
__tablename__ = "user_departments"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
user_id = Column(Integer, ForeignKey("users.id", ondelete="CASCADE"), nullable=False)
|
||||
department_id = Column(Integer, ForeignKey("departments.id", ondelete="CASCADE"), nullable=False)
|
||||
is_primary = Column(Boolean, default=False)
|
||||
|
||||
# Relationships
|
||||
user = relationship("User")
|
||||
department = relationship("Department")
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"<UserDepartment(user_id={self.user_id}, department_id={self.department_id})>"
|
||||
Reference in New Issue
Block a user