34 lines
1.3 KiB
Python
34 lines
1.3 KiB
Python
"""Mapping templates for user-defined data source payloads."""
|
|
|
|
from sqlalchemy import Boolean, Column, DateTime, ForeignKey, Integer, JSON, String
|
|
from sqlalchemy.sql import func
|
|
|
|
from app.core.enums import MappingValidationStatus
|
|
from app.db.session import Base
|
|
|
|
|
|
class DataSourceMappingTemplate(Base):
|
|
__tablename__ = "datasource_mapping_templates"
|
|
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
datasource_config_id = Column(
|
|
Integer,
|
|
ForeignKey("datasource_configs.id"),
|
|
nullable=False,
|
|
index=True,
|
|
)
|
|
target_schema = Column(String(80), nullable=False, index=True)
|
|
mapping_json = Column(JSON, nullable=False, default={})
|
|
sample_payload_hash = Column(String(64), nullable=True)
|
|
validation_status = Column(String(30), nullable=False, default=MappingValidationStatus.DRAFT.value)
|
|
version = Column(Integer, nullable=False, default=1)
|
|
is_active = Column(Boolean, nullable=False, default=False, index=True)
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
updated_at = Column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
|
|
|
|
def __repr__(self):
|
|
return (
|
|
f"<DataSourceMappingTemplate {self.id}: "
|
|
f"{self.datasource_config_id}/{self.target_schema}/v{self.version}>"
|
|
)
|