feat(backend): add Match + ActivityEvent ORM models
This commit is contained in:
@@ -177,8 +177,6 @@ class Batch(Base):
|
||||
# alone (no migration runner) get the same index direction as prod.
|
||||
Index("ix_batches_parsed_at", text("parsed_at DESC")),
|
||||
)
|
||||
# TODO(T6): when ActivityEvent model is added, mirror this pattern for
|
||||
# `ix_activity_events_ts` on activity_events(ts DESC) per 0001_initial.sql:86.
|
||||
|
||||
|
||||
class Claim(Base):
|
||||
@@ -283,3 +281,46 @@ class CasAdjustment(Base):
|
||||
__table_args__ = (
|
||||
Index("ix_cas_adjustments_remittance_id", "remittance_id"),
|
||||
)
|
||||
|
||||
|
||||
class Match(Base):
|
||||
__tablename__ = "matches"
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
||||
claim_id: Mapped[str] = mapped_column(
|
||||
String(64), ForeignKey("claims.id", ondelete="CASCADE"),
|
||||
nullable=False, unique=True,
|
||||
)
|
||||
remittance_id: Mapped[str] = mapped_column(
|
||||
String(64), ForeignKey("remittances.id", ondelete="CASCADE"), nullable=False
|
||||
)
|
||||
strategy: Mapped[str] = mapped_column(String(16), nullable=False)
|
||||
matched_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), nullable=False)
|
||||
prior_claim_state: Mapped[Optional[ClaimState]] = mapped_column(
|
||||
Enum(ClaimState, native_enum=False), nullable=True
|
||||
)
|
||||
is_reversal: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False)
|
||||
|
||||
__table_args__ = (
|
||||
Index("ix_matches_remittance_id", "remittance_id"),
|
||||
Index("ix_matches_matched_at", "matched_at"),
|
||||
)
|
||||
|
||||
|
||||
class ActivityEvent(Base):
|
||||
__tablename__ = "activity_events"
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
||||
ts: Mapped[datetime] = mapped_column(DateTime(timezone=True), nullable=False)
|
||||
kind: Mapped[str] = mapped_column(String(32), nullable=False)
|
||||
batch_id: Mapped[Optional[str]] = mapped_column(String(32), nullable=True)
|
||||
claim_id: Mapped[Optional[str]] = mapped_column(String(64), nullable=True)
|
||||
remittance_id: Mapped[Optional[str]] = mapped_column(String(64), nullable=True)
|
||||
payload_json: Mapped[Optional[dict]] = mapped_column(JSONText, nullable=True)
|
||||
|
||||
__table_args__ = (
|
||||
# Migration declares this as DESC; mirror the qualifier so create_all
|
||||
# on a fresh DB (without migrations) produces identical DDL.
|
||||
Index("ix_activity_events_ts", text("ts DESC")),
|
||||
Index("ix_activity_events_kind", "kind"),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user