62 lines
2.2 KiB
Python
62 lines
2.2 KiB
Python
# [DEF:DatasetReviewMappingModels:Module]
|
|
# @COMPLEXITY: 2
|
|
# @PURPOSE: Execution mapping model linking imported filters to template variables with approval gates.
|
|
# @LAYER: Domain
|
|
# @RELATION: DEPENDS_ON -> [DatasetReviewEnums:Module]
|
|
# @RELATION: DEPENDS_ON -> [MappingModels]
|
|
|
|
import uuid
|
|
from datetime import datetime
|
|
|
|
from sqlalchemy import (
|
|
Column,
|
|
String,
|
|
Text,
|
|
Boolean,
|
|
DateTime,
|
|
ForeignKey,
|
|
JSON,
|
|
Enum as SQLEnum,
|
|
)
|
|
from sqlalchemy.orm import relationship
|
|
|
|
from src.models.mapping import Base
|
|
from src.models.dataset_review_pkg._enums import (
|
|
MappingMethod,
|
|
MappingWarningLevel,
|
|
ApprovalState,
|
|
)
|
|
|
|
|
|
# [DEF:ExecutionMapping:Class]
|
|
# @COMPLEXITY: 2
|
|
# @PURPOSE: One filter-to-variable mapping with approval gate, effective value, and transformation metadata.
|
|
# @RELATION: DEPENDS_ON -> [DatasetReviewSession]
|
|
# @INVARIANT: Explicit approval is required before launch when requires_explicit_approval is true.
|
|
class ExecutionMapping(Base):
|
|
__tablename__ = "execution_mappings"
|
|
|
|
mapping_id = Column(String, primary_key=True, default=lambda: str(uuid.uuid4()))
|
|
session_id = Column(String, ForeignKey("dataset_review_sessions.session_id"), nullable=False)
|
|
filter_id = Column(String, nullable=False)
|
|
variable_id = Column(String, nullable=False)
|
|
mapping_method = Column(SQLEnum(MappingMethod), nullable=False)
|
|
raw_input_value = Column(JSON, nullable=False)
|
|
effective_value = Column(JSON, nullable=True)
|
|
transformation_note = Column(Text, nullable=True)
|
|
warning_level = Column(SQLEnum(MappingWarningLevel), nullable=True)
|
|
requires_explicit_approval = Column(Boolean, nullable=False, default=False)
|
|
approval_state = Column(SQLEnum(ApprovalState), nullable=False, default=ApprovalState.NOT_REQUIRED)
|
|
approved_by_user_id = Column(String, nullable=True)
|
|
approved_at = Column(DateTime, nullable=True)
|
|
created_at = Column(DateTime, default=datetime.utcnow, nullable=False)
|
|
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, nullable=False)
|
|
|
|
session = relationship("DatasetReviewSession", back_populates="execution_mappings")
|
|
|
|
|
|
# [/DEF:ExecutionMapping:Class]
|
|
|
|
|
|
# [/DEF:DatasetReviewMappingModels:Module]
|