39 lines
1.2 KiB
Python
39 lines
1.2 KiB
Python
"""rule_moments — the moments of work a rule arrives at
|
|
|
|
Revision ID: 0117
|
|
Revises: 0116
|
|
Create Date: 2026-10-05
|
|
|
|
A rule mounted on a moment is delivered whenever that moment happens, by
|
|
lookup rather than by score. The moment is a catalog name, validated by the
|
|
service; the catalog is code, so there is no table to key it to. Cascades
|
|
with the rule, like rule_systems beside it.
|
|
"""
|
|
import sqlalchemy as sa
|
|
from alembic import op
|
|
|
|
revision = "0117"
|
|
down_revision = "0116"
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
op.create_table(
|
|
"rule_moments",
|
|
sa.Column(
|
|
"rule_id", sa.BigInteger(),
|
|
sa.ForeignKey("rules.id", ondelete="CASCADE"), primary_key=True,
|
|
),
|
|
sa.Column("moment", sa.Text(), primary_key=True),
|
|
sa.Column("created_at", sa.DateTime(timezone=True), nullable=True),
|
|
)
|
|
# The delivery read asks "which rules are on this moment?", the
|
|
# opposite direction from the primary key.
|
|
op.create_index("ix_rule_moments_moment", "rule_moments", ["moment"])
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.drop_index("ix_rule_moments_moment", table_name="rule_moments")
|
|
op.drop_table("rule_moments")
|