Add durable reconciliation decisions
This commit is contained in:
@@ -17,6 +17,7 @@ from sqlalchemy import (
|
||||
)
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from govoplan_core.core.concurrency import strong_resource_etag
|
||||
from govoplan_core.db.base import Base, TimestampMixin
|
||||
|
||||
|
||||
@@ -121,6 +122,11 @@ class DataflowPipeline(Base, TimestampMixin):
|
||||
cascade="all, delete-orphan",
|
||||
order_by="DataflowTrigger.created_at",
|
||||
)
|
||||
decision_sets: Mapped[list["DataflowReconciliationDecisionSet"]] = relationship(
|
||||
back_populates="pipeline",
|
||||
cascade="all, delete-orphan",
|
||||
order_by="DataflowReconciliationDecisionSet.name",
|
||||
)
|
||||
|
||||
|
||||
class DataflowPipelineRevision(Base, TimestampMixin):
|
||||
@@ -153,6 +159,99 @@ class DataflowPipelineRevision(Base, TimestampMixin):
|
||||
pipeline: Mapped[DataflowPipeline] = relationship(back_populates="revisions")
|
||||
|
||||
|
||||
class DataflowReconciliationDecisionSet(Base, TimestampMixin):
|
||||
__tablename__ = "dataflow_reconciliation_decision_sets"
|
||||
__table_args__ = (
|
||||
UniqueConstraint(
|
||||
"tenant_id",
|
||||
"pipeline_id",
|
||||
"name",
|
||||
name="uq_dataflow_decision_sets_pipeline_name",
|
||||
),
|
||||
Index(
|
||||
"ix_dataflow_decision_sets_tenant_pipeline",
|
||||
"tenant_id",
|
||||
"pipeline_id",
|
||||
),
|
||||
)
|
||||
|
||||
id: Mapped[str] = mapped_column(String(36), primary_key=True, default=new_uuid)
|
||||
tenant_id: Mapped[str] = mapped_column(String(36), nullable=False, index=True)
|
||||
pipeline_id: Mapped[str] = mapped_column(
|
||||
ForeignKey("dataflow_pipelines.id", ondelete="CASCADE"),
|
||||
nullable=False,
|
||||
index=True,
|
||||
)
|
||||
name: Mapped[str] = mapped_column(String(300), nullable=False)
|
||||
node_id: Mapped[str | None] = mapped_column(String(100), nullable=True)
|
||||
resource_revision: Mapped[int] = mapped_column(
|
||||
Integer,
|
||||
default=1,
|
||||
nullable=False,
|
||||
)
|
||||
created_by: Mapped[str | None] = mapped_column(String(255), nullable=True)
|
||||
updated_by: Mapped[str | None] = mapped_column(String(255), nullable=True)
|
||||
|
||||
pipeline: Mapped[DataflowPipeline] = relationship(back_populates="decision_sets")
|
||||
decisions: Mapped[list["DataflowReconciliationDecision"]] = relationship(
|
||||
back_populates="decision_set",
|
||||
cascade="all, delete-orphan",
|
||||
order_by="DataflowReconciliationDecision.revision",
|
||||
)
|
||||
|
||||
@property
|
||||
def strong_etag(self) -> str:
|
||||
return strong_resource_etag(
|
||||
"dataflow_reconciliation_decision_set",
|
||||
self.id,
|
||||
self.resource_revision,
|
||||
)
|
||||
|
||||
|
||||
class DataflowReconciliationDecision(Base, TimestampMixin):
|
||||
__tablename__ = "dataflow_reconciliation_decisions"
|
||||
__table_args__ = (
|
||||
UniqueConstraint(
|
||||
"decision_set_id",
|
||||
"revision",
|
||||
name="uq_dataflow_reconciliation_decision_revision",
|
||||
),
|
||||
Index(
|
||||
"ix_dataflow_reconciliation_decisions_current",
|
||||
"tenant_id",
|
||||
"decision_set_id",
|
||||
"key_hash",
|
||||
"revision",
|
||||
),
|
||||
)
|
||||
|
||||
id: Mapped[str] = mapped_column(String(36), primary_key=True, default=new_uuid)
|
||||
tenant_id: Mapped[str] = mapped_column(String(36), nullable=False, index=True)
|
||||
decision_set_id: Mapped[str] = mapped_column(
|
||||
ForeignKey(
|
||||
"dataflow_reconciliation_decision_sets.id",
|
||||
ondelete="CASCADE",
|
||||
),
|
||||
nullable=False,
|
||||
index=True,
|
||||
)
|
||||
revision: Mapped[int] = mapped_column(Integer, nullable=False)
|
||||
key_hash: Mapped[str] = mapped_column(String(64), nullable=False, index=True)
|
||||
input_hash: Mapped[str] = mapped_column(String(64), nullable=False)
|
||||
action: Mapped[str] = mapped_column(String(20), nullable=False)
|
||||
reason: Mapped[str] = mapped_column(Text, nullable=False)
|
||||
correction: Mapped[dict[str, Any] | None] = mapped_column(JSON, nullable=True)
|
||||
actor_ref: Mapped[str] = mapped_column(String(255), nullable=False)
|
||||
decided_at: Mapped[datetime] = mapped_column(
|
||||
DateTime(timezone=True),
|
||||
nullable=False,
|
||||
)
|
||||
|
||||
decision_set: Mapped[DataflowReconciliationDecisionSet] = relationship(
|
||||
back_populates="decisions"
|
||||
)
|
||||
|
||||
|
||||
class DataflowRun(Base, TimestampMixin):
|
||||
__tablename__ = "dataflow_runs"
|
||||
__table_args__ = (
|
||||
|
||||
Reference in New Issue
Block a user