feat: close autonomous operations for blocked products

This commit is contained in:
gti
2026-09-22 14:51:54 -03:00
parent dca4847c21
commit 3a36ac630b
16 changed files with 666 additions and 3 deletions
@@ -0,0 +1,43 @@
"""Add deduplicated blocked product registry."""
from alembic import op
import sqlalchemy as sa
revision = "0016_blocked_product_registry"
down_revision = "0015_ai_budget_and_product_cache"
branch_labels = None
depends_on = None
def upgrade():
op.create_table(
"blocked_products",
sa.Column("id", sa.Integer(), primary_key=True),
sa.Column("tenant_id", sa.Integer(), sa.ForeignKey("tenants.id"), nullable=False),
sa.Column("company", sa.String(length=128), nullable=False),
sa.Column("product_code", sa.String(length=64), nullable=False),
sa.Column("gtin", sa.String(length=16)),
sa.Column("description", sa.Text()),
sa.Column("blocker_type", sa.String(length=48), nullable=False),
sa.Column("field", sa.String(length=64), nullable=False),
sa.Column("reason_code", sa.String(length=96), nullable=False),
sa.Column("evidence_summary", sa.JSON(), nullable=False),
sa.Column("input_fingerprint", sa.String(length=64), nullable=False),
sa.Column("blocker_fingerprint", sa.String(length=64), nullable=False),
sa.Column("first_seen_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
sa.Column("last_seen_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
sa.Column("retry_count", sa.Integer(), server_default="0", nullable=False),
sa.Column("next_retry_at", sa.DateTime(timezone=True)),
sa.Column("resolved_at", sa.DateTime(timezone=True)),
sa.Column("resolution_source", sa.String(length=48)),
sa.UniqueConstraint("blocker_fingerprint", name="uq_blocked_product_fingerprint"),
)
for name, column in (("tenant", "tenant_id"), ("company", "company"), ("product", "product_code"), ("gtin", "gtin"), ("blocker_type", "blocker_type"), ("field", "field"), ("input", "input_fingerprint")):
op.create_index(f"ix_blocked_products_{name}", "blocked_products", [column])
def downgrade():
for name in ("input", "field", "blocker_type", "gtin", "product", "company", "tenant"):
op.drop_index(f"ix_blocked_products_{name}", table_name="blocked_products")
op.drop_table("blocked_products")