"""rule enforcement and salience — what a rule does when it arrives, and how much it outranks Revision ID: 0128 Revises: 0127 Create Date: 2026-11-22 Two declared columns on a rule, read by the one function that orders what reaches a moment: - `enforcement`: `enforce` (the act itself is checked), `hold` (the reply or act waits for one read), `inform` (a line beside the work). Every existing rule starts as `inform`; declaring which ones hold is the author's call. - `salience`: `high`, `normal`, `low` — the author's ranking among rules of the same enforcement. """ import sqlalchemy as sa from alembic import op revision = "0128" down_revision = "0127" branch_labels = None depends_on = None _ENFORCEMENTS = ("enforce", "hold", "inform") _SALIENCES = ("high", "normal", "low") def _in_list(column: str, values: tuple[str, ...]) -> str: return f"{column} IN ({', '.join(repr(v) for v in values)})" def upgrade() -> None: op.add_column("rules", sa.Column("enforcement", sa.Text(), nullable=False, server_default="inform")) op.add_column("rules", sa.Column("salience", sa.Text(), nullable=False, server_default="normal")) op.create_check_constraint("ck_rules_enforcement", "rules", _in_list("enforcement", _ENFORCEMENTS)) op.create_check_constraint("ck_rules_salience", "rules", _in_list("salience", _SALIENCES)) # A preference claims no force: it is how work is liked done, not a bar. op.create_check_constraint( "ck_rules_preference_informs", "rules", "kind <> 'preference' OR enforcement = 'inform'", ) def downgrade() -> None: op.drop_constraint("ck_rules_preference_informs", "rules", type_="check") op.drop_constraint("ck_rules_salience", "rules", type_="check") op.drop_constraint("ck_rules_enforcement", "rules", type_="check") op.drop_column("rules", "salience") op.drop_column("rules", "enforcement")