38 lines
1.3 KiB
Python
38 lines
1.3 KiB
Python
"""
|
|
Flexible storage for unmapped CSV columns during import
|
|
"""
|
|
from sqlalchemy import Column, Integer, String
|
|
from sqlalchemy.types import JSON
|
|
|
|
from app.models.base import BaseModel
|
|
|
|
|
|
class FlexibleImport(BaseModel):
|
|
"""Stores per-row extra/unmapped data for any import, without persisting mapping patterns."""
|
|
|
|
__tablename__ = "flexible_imports"
|
|
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
|
|
# The CSV filename used by the importer (e.g., "FILES.csv" or arbitrary names in flexible mode)
|
|
file_type = Column(String(120), nullable=False, index=True)
|
|
|
|
# The SQLAlchemy model table this extra data is associated with (if any)
|
|
target_table = Column(String(120), nullable=True, index=True)
|
|
|
|
# Optional link to the primary record created in the target table
|
|
primary_key_field = Column(String(120), nullable=True)
|
|
primary_key_value = Column(String(255), nullable=True, index=True)
|
|
|
|
# Extra unmapped columns from the CSV row
|
|
extra_data = Column(JSON, nullable=False)
|
|
|
|
def __repr__(self) -> str: # pragma: no cover - repr utility
|
|
return (
|
|
f"<FlexibleImport(id={self.id}, file_type='{self.file_type}', "
|
|
f"target_table='{self.target_table}', pk_field='{self.primary_key_field}', "
|
|
f"pk_value='{self.primary_key_value}')>"
|
|
)
|
|
|
|
|