| """ |
| RuleTechniqueMapping associative entity — ER Diagram §3.2.6 |
| Attributes: Mapping_ID, Rule_ID (FK), Technique_ID (FK), confidence_score |
| Index on rule_id for fast lookup — mentioned explicitly in Use Case 6 (§3.2.7). |
| """ |
|
|
| from sqlalchemy import Float, ForeignKey, Index, Integer, String |
| from sqlalchemy.orm import Mapped, mapped_column, relationship |
|
|
| from app.db.base import Base |
|
|
|
|
| class RuleTechniqueMapping(Base): |
| __tablename__ = "rule_technique_mappings" |
|
|
| mapping_id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True) |
| rule_id: Mapped[str] = mapped_column( |
| String(50), ForeignKey("rules.rule_id"), nullable=False |
| ) |
| technique_id: Mapped[str] = mapped_column( |
| String(20), ForeignKey("techniques.technique_id"), nullable=False |
| ) |
| confidence_score: Mapped[float] = mapped_column(Float, nullable=False) |
|
|
| rule: Mapped["Rule"] = relationship(back_populates="technique_mappings") |
| technique: Mapped["Technique"] = relationship(back_populates="rule_mappings") |
|
|
| __table_args__ = ( |
| |
| Index("ix_rule_technique_rule_id", "rule_id"), |
| ) |
|
|