48 lines
1.7 KiB
Python
48 lines
1.7 KiB
Python
from sqlalchemy import Column, Integer, String, DateTime, Float, Boolean,Index, Text, ForeignKey, Enum as SQLEnum
|
|
from sqlalchemy.sql import func
|
|
from sqlalchemy.orm import relationship
|
|
from database import Base
|
|
|
|
import enum
|
|
|
|
|
|
class Branches(Base):
|
|
__tablename__ = "branches"
|
|
|
|
id = Column(Integer,primary_key=True, nullable=False, autoincrement=True)
|
|
direccion = Column(String(255), nullable=False)
|
|
cp = Column(Integer, nullable=False)
|
|
#physical
|
|
is_physical = Column(Boolean, nullable=False)
|
|
location_id = Column(Integer, ForeignKey("location.id"), nullable=False)
|
|
#validation
|
|
is_active = Column(Boolean, nullable=False, default=True)
|
|
#cliente_id
|
|
client_id = Column(Integer, ForeignKey("clients.id"), nullable=True)
|
|
user_id = Column(Integer, ForeignKey("users.id"), nullable=True)
|
|
|
|
#timestamsp
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now(), nullable=False)
|
|
updated_at = Column(DateTime(timezone=True), onupdate=func.now(), nullable=True)
|
|
deleted_at = Column(DateTime(timezone=True), nullable=True)
|
|
|
|
#trace
|
|
created_by = Column(Integer, nullable=True)
|
|
updated_by = Column(Integer, nullable=True)
|
|
deleted_by = Column(Integer, nullable=True)
|
|
|
|
#indices
|
|
__table_args__ = (
|
|
Index('idx_branches_client', 'client_id'),
|
|
Index('idx_branches_location', 'location_id'),
|
|
Index('idx_branches_user', 'user_id'),
|
|
Index('idx_branches_active', 'is_active')
|
|
)
|
|
|
|
#relaciones
|
|
|
|
client = relationship("Client", foreign_keys=[client_id], back_populates="branches")
|
|
location = relationship("Locations", foreign_keys=[location_id], back_populates="branches")
|
|
user = relationship("Users", back_populates="branch")
|
|
|