"""rule triggers — typed predicates on the act that deliver a rule, checked in code Revision ID: 0130 Revises: 0129 Create Date: 2026-11-22 A trigger is a kind (tool, path, command, keyword) and a pattern, optionally scoped to a moment. Unscoped, it delivers the rule on any act that matches; scoped, it makes the rule's mount on that moment conditional on the act matching. Matched in code against the act, never by embedding. """ import sqlalchemy as sa from alembic import op revision = "0130" down_revision = "0129" branch_labels = None depends_on = None def upgrade() -> None: op.create_table( "rule_triggers", sa.Column("rule_id", sa.BigInteger(), sa.ForeignKey("rules.id", ondelete="CASCADE"), primary_key=True), sa.Column("kind", sa.Text(), primary_key=True), sa.Column("pattern", sa.Text(), primary_key=True), sa.Column("moment", sa.Text(), primary_key=True, server_default=""), sa.Column("created_at", sa.DateTime(timezone=True), nullable=True), sa.CheckConstraint( "kind IN ('tool', 'path', 'command', 'keyword')", name="ck_rule_triggers_kind", ), sa.CheckConstraint("length(pattern) > 0", name="ck_rule_triggers_pattern"), ) def downgrade() -> None: op.drop_table("rule_triggers")