"""Fence the first WP13 downgrade against every durable plugin fact.""" from alembic import op revision = "20260818_557" down_revision = "20260818_556" branch_labels = None depends_on = None _FACT_TABLES = ( # Registry rows carry the persisted review actor and incident link. "plugin_registry_versions", "plugin_approvals", "plugin_runtime_leases", "plugin_runs", "plugin_dead_letters", "plugin_audit_outbox", "plugin_request_claims", "plugin_runtime_breakers", "plugin_recovery_claims", ) def upgrade() -> None: # This revision intentionally changes no successful runtime behaviour. It # owns the first downgrade step so later revisions cannot expose 556's # narrower downgrade checks while any durable WP13 evidence still exists. op.get_bind().exec_driver_sql("SELECT 1") def downgrade() -> None: bind = op.get_bind() checks = " OR ".join( f"EXISTS(SELECT 1 FROM public.{table} LIMIT 1)" for table in _FACT_TABLES ) if bind.exec_driver_sql(f"SELECT {checks}").scalar(): raise RuntimeError("downgrade refused: durable WP13 plugin facts are nonempty")