58 lines
2.2 KiB
Python
58 lines
2.2 KiB
Python
from sqlalchemy import Column, Integer, String, DateTime, Float, Boolean, Text, ForeignKey, Enum as SQLEnum, Index
|
|
from sqlalchemy.sql import func
|
|
from sqlalchemy.orm import relationship
|
|
from database import Base
|
|
|
|
import enum
|
|
|
|
class StatusOP(str, enum.Enum):
|
|
COMPLETED = "completed"
|
|
PARTIAL = "partial"
|
|
INITIAL = "initial"
|
|
NO_PROCECED = "no_proceced"
|
|
INVALID = "invalid"
|
|
|
|
class Operation(str, enum.Enum):
|
|
DELETED ="deleted"
|
|
CREATED ="created"
|
|
UPDATED ="updated"
|
|
TRIED ="tried"
|
|
MOST ="mosted"
|
|
LESS ="less"
|
|
MINUS ="minus"
|
|
CANCELED ="canceled"
|
|
|
|
|
|
class AffidavitRecord(Base):
|
|
__tablename__ = "affidavit_logs"
|
|
|
|
id = Column(Integer, primary_key=True, nullable=False, autoincrement=True)
|
|
operation = Column(SQLEnum(Operation, name="operation", create_type=False), default=Operation.TRIED, nullable=True)
|
|
user_id = Column(Integer, ForeignKey("users.id"), nullable=True)
|
|
client_id = Column(Integer, ForeignKey("clients.id"), nullable=True)
|
|
description = Column(Text,nullable=False)
|
|
adjustment = Column(String(100), nullable=True)
|
|
status = Column(SQLEnum(StatusOP, name="status", create_type=False), default=StatusOP.INITIAL, nullable=True)
|
|
sign = Column(String, nullable=False)
|
|
|
|
#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, ForeignKey("users.id"), nullable=True)
|
|
updated_by = Column(Integer, ForeignKey("users.id"), nullable=True)
|
|
deleted_by = Column(Integer, ForeignKey("users.id"), nullable=True)
|
|
|
|
#relationships
|
|
user = relationship("Users", foreign_keys=[user_id], back_populates="affidavit_logs")
|
|
client = relationship("Client", foreign_keys=[client_id])
|
|
|
|
__table_args__ = (
|
|
Index('idx_affidavit_user', 'user_id'),
|
|
Index('idx_affidavit_client', 'client_id'),
|
|
Index('idx_affidavit_operation', 'operation'),
|
|
Index('idx_affidavit_status', 'status'),
|
|
Index('idx_affidavit_created', 'created_at'),
|
|
) |