feat: acquire immutable sanctions snapshots
This commit is contained in:
@@ -4,7 +4,17 @@ import uuid
|
||||
from datetime import datetime
|
||||
from typing import Any
|
||||
|
||||
from sqlalchemy import DateTime, Index, Integer, JSON, String, Text, UniqueConstraint
|
||||
from sqlalchemy import (
|
||||
DateTime,
|
||||
ForeignKey,
|
||||
Index,
|
||||
Integer,
|
||||
JSON,
|
||||
LargeBinary,
|
||||
String,
|
||||
Text,
|
||||
UniqueConstraint,
|
||||
)
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from govoplan_core.db.base import Base, TimestampMixin
|
||||
@@ -41,4 +51,213 @@ class ConnectorTabularSource(Base, TimestampMixin):
|
||||
deleted_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True, index=True)
|
||||
|
||||
|
||||
__all__ = ["ConnectorTabularSource", "new_uuid"]
|
||||
class ConnectorSanctionsAcquisitionRun(Base, TimestampMixin):
|
||||
__tablename__ = "connector_sanctions_acquisition_runs"
|
||||
__table_args__ = (
|
||||
Index(
|
||||
"ix_connector_sanctions_run_health",
|
||||
"tenant_id",
|
||||
"provider_id",
|
||||
"status",
|
||||
"started_at",
|
||||
),
|
||||
)
|
||||
|
||||
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,
|
||||
)
|
||||
provider_id: Mapped[str] = mapped_column(
|
||||
String(100),
|
||||
nullable=False,
|
||||
index=True,
|
||||
)
|
||||
source_id: Mapped[str] = mapped_column(
|
||||
String(200),
|
||||
nullable=False,
|
||||
index=True,
|
||||
)
|
||||
status: Mapped[str] = mapped_column(
|
||||
String(40),
|
||||
default="running",
|
||||
nullable=False,
|
||||
index=True,
|
||||
)
|
||||
attempt_count: Mapped[int] = mapped_column(
|
||||
Integer,
|
||||
default=0,
|
||||
nullable=False,
|
||||
)
|
||||
request_evidence: Mapped[dict[str, Any]] = mapped_column(
|
||||
JSON,
|
||||
default=dict,
|
||||
nullable=False,
|
||||
)
|
||||
response_evidence: Mapped[dict[str, Any]] = mapped_column(
|
||||
JSON,
|
||||
default=dict,
|
||||
nullable=False,
|
||||
)
|
||||
started_at: Mapped[datetime] = mapped_column(
|
||||
DateTime(timezone=True),
|
||||
nullable=False,
|
||||
index=True,
|
||||
)
|
||||
finished_at: Mapped[datetime | None] = mapped_column(
|
||||
DateTime(timezone=True),
|
||||
nullable=True,
|
||||
)
|
||||
snapshot_id: Mapped[str | None] = mapped_column(
|
||||
String(36),
|
||||
nullable=True,
|
||||
index=True,
|
||||
)
|
||||
error: Mapped[str | None] = mapped_column(
|
||||
Text,
|
||||
nullable=True,
|
||||
)
|
||||
created_by: Mapped[str | None] = mapped_column(
|
||||
String(255),
|
||||
nullable=True,
|
||||
index=True,
|
||||
)
|
||||
|
||||
|
||||
class ConnectorSanctionsSnapshot(Base, TimestampMixin):
|
||||
__tablename__ = "connector_sanctions_snapshots"
|
||||
__table_args__ = (
|
||||
UniqueConstraint(
|
||||
"connector_run_id",
|
||||
name="uq_connector_sanctions_snapshot_run",
|
||||
),
|
||||
Index(
|
||||
"ix_connector_sanctions_snapshot_source",
|
||||
"tenant_id",
|
||||
"provider_id",
|
||||
"acquired_at",
|
||||
),
|
||||
Index(
|
||||
"ix_connector_sanctions_snapshot_version",
|
||||
"provider_id",
|
||||
"source_id",
|
||||
"source_version",
|
||||
),
|
||||
)
|
||||
|
||||
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,
|
||||
)
|
||||
provider_id: Mapped[str] = mapped_column(
|
||||
String(100),
|
||||
nullable=False,
|
||||
index=True,
|
||||
)
|
||||
publisher: Mapped[str] = mapped_column(
|
||||
String(300),
|
||||
nullable=False,
|
||||
)
|
||||
jurisdiction: Mapped[str] = mapped_column(
|
||||
String(100),
|
||||
nullable=False,
|
||||
index=True,
|
||||
)
|
||||
list_type: Mapped[str] = mapped_column(
|
||||
String(100),
|
||||
nullable=False,
|
||||
index=True,
|
||||
)
|
||||
source_id: Mapped[str] = mapped_column(
|
||||
String(200),
|
||||
nullable=False,
|
||||
index=True,
|
||||
)
|
||||
source_version: Mapped[str] = mapped_column(
|
||||
String(255),
|
||||
nullable=False,
|
||||
index=True,
|
||||
)
|
||||
publication_at: Mapped[datetime | None] = mapped_column(
|
||||
DateTime(timezone=True),
|
||||
nullable=True,
|
||||
)
|
||||
effective_at: Mapped[datetime | None] = mapped_column(
|
||||
DateTime(timezone=True),
|
||||
nullable=True,
|
||||
)
|
||||
acquired_at: Mapped[datetime] = mapped_column(
|
||||
DateTime(timezone=True),
|
||||
nullable=False,
|
||||
index=True,
|
||||
)
|
||||
source_url: Mapped[str | None] = mapped_column(
|
||||
String(1500),
|
||||
nullable=True,
|
||||
)
|
||||
content_type: Mapped[str] = mapped_column(
|
||||
String(200),
|
||||
nullable=False,
|
||||
)
|
||||
byte_count: Mapped[int] = mapped_column(
|
||||
Integer,
|
||||
nullable=False,
|
||||
)
|
||||
sha256: Mapped[str] = mapped_column(
|
||||
String(64),
|
||||
nullable=False,
|
||||
index=True,
|
||||
)
|
||||
signature_evidence: Mapped[dict[str, Any]] = mapped_column(
|
||||
JSON,
|
||||
default=dict,
|
||||
nullable=False,
|
||||
)
|
||||
parser_version: Mapped[str] = mapped_column(
|
||||
String(100),
|
||||
nullable=False,
|
||||
)
|
||||
licence_notes: Mapped[str | None] = mapped_column(
|
||||
Text,
|
||||
nullable=True,
|
||||
)
|
||||
trust_notes: Mapped[str | None] = mapped_column(
|
||||
Text,
|
||||
nullable=True,
|
||||
)
|
||||
connector_run_id: Mapped[str] = mapped_column(
|
||||
ForeignKey(
|
||||
"connector_sanctions_acquisition_runs.id",
|
||||
ondelete="RESTRICT",
|
||||
),
|
||||
nullable=False,
|
||||
index=True,
|
||||
)
|
||||
transport_evidence: Mapped[dict[str, Any]] = mapped_column(
|
||||
JSON,
|
||||
default=dict,
|
||||
nullable=False,
|
||||
)
|
||||
raw_content: Mapped[bytes] = mapped_column(
|
||||
LargeBinary,
|
||||
nullable=False,
|
||||
)
|
||||
|
||||
|
||||
__all__ = [
|
||||
"ConnectorSanctionsAcquisitionRun",
|
||||
"ConnectorSanctionsSnapshot",
|
||||
"ConnectorTabularSource",
|
||||
"new_uuid",
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user