M34: enforce domain integrity in PostgreSQL
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import DateTime, Integer, String, Text
|
||||
from sqlalchemy import CheckConstraint, DateTime, Index, Integer, String, Text
|
||||
from sqlalchemy.dialects.postgresql import JSONB, UUID
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
@@ -32,6 +32,14 @@ def is_demo_scenario_failure(event: "OutboxEvent") -> bool:
|
||||
|
||||
class OutboxEvent(TimestampMixin, Base):
|
||||
__tablename__ = "outbox_events"
|
||||
__table_args__ = (
|
||||
CheckConstraint(
|
||||
"delivery_status IN ('pending','delivering','succeeded','failed')",
|
||||
name="ck_outbox_delivery_status",
|
||||
),
|
||||
CheckConstraint("attempts >= 0", name="ck_outbox_attempts"),
|
||||
Index("ix_outbox_delivery_next_attempt", "delivery_status", "next_attempt_at"),
|
||||
)
|
||||
|
||||
event_id: Mapped[uuid.UUID] = mapped_column(
|
||||
UUID(as_uuid=True), primary_key=True, default=uuid.uuid4
|
||||
|
||||
Reference in New Issue
Block a user