"""gate stops: each time a Grimoire gate stood in front of a tool call Revision ID: 0138 Revises: 0137 Create Date: 2026-11-27 A row per stop the plugin made: a moment rule set to enforce or hold, the act checkpoint, or the project fence asking the operator. With whether the session then opened the rule (`cleared_at`) and whether the stopped call ran after all (`ran_at`), so how often each gate stops work, for which rule, and whether it cleared the way it is meant to can be read. """ import sqlalchemy as sa from alembic import op revision = "0138" down_revision = "0137" branch_labels = None depends_on = None def upgrade() -> None: op.create_table( "gate_stops", sa.Column("id", sa.BigInteger(), primary_key=True), sa.Column("user_id", sa.BigInteger(), nullable=False), sa.Column("session_id", sa.Text(), nullable=False), sa.Column("gate", sa.Text(), nullable=False), sa.Column("outcome", sa.Text(), nullable=False), sa.Column("rule_id", sa.BigInteger(), nullable=True), sa.Column("tool", sa.Text(), nullable=False), sa.Column("at", sa.Text(), nullable=True), sa.Column("target", sa.Text(), nullable=True), sa.Column("call_id", sa.Text(), nullable=True), sa.Column("stopped_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.func.now()), sa.Column("cleared_at", sa.DateTime(timezone=True), nullable=True), sa.Column("ran_at", sa.DateTime(timezone=True), nullable=True), sa.Column("plugin", sa.Text(), nullable=True), ) op.create_index("ix_gate_stops_session_rule", "gate_stops", ["user_id", "session_id", "rule_id", "stopped_at"]) op.create_index("ix_gate_stops_stopped_at", "gate_stops", ["stopped_at"]) def downgrade() -> None: op.drop_index("ix_gate_stops_stopped_at", table_name="gate_stops") op.drop_index("ix_gate_stops_session_rule", table_name="gate_stops") op.drop_table("gate_stops")