"""Durable operator configuration and revision history. Revision ID: 20260907_0025 Revises: 20260830_0024 """ import sqlalchemy as sa from alembic import op revision = "20260907_0025" down_revision = "20260830_0024" branch_labels = None depends_on = None def upgrade() -> None: op.create_table( "configuration_state", sa.Column("id", sa.Integer(), primary_key=True), sa.Column("revision", sa.Integer(), nullable=False), sa.Column("overrides", sa.JSON(), nullable=False), sa.CheckConstraint("id = 1"), sa.CheckConstraint("revision >= 0"), ) op.create_table( "configuration_revisions", sa.Column("revision", sa.Integer(), primary_key=True), sa.Column("previous_revision", sa.Integer(), nullable=False), sa.Column("created_at", sa.DateTime(timezone=True), nullable=False), sa.Column("actor", sa.String(255), nullable=False), sa.Column("correlation_id", sa.String(255), nullable=False), sa.Column("overrides", sa.JSON(), nullable=False), sa.Column("preview_digest", sa.String(64), nullable=False), ) if op.get_bind().dialect.name == "postgresql": op.execute("GRANT SELECT, INSERT, UPDATE ON configuration_state TO modelforge_runtime") op.execute("REVOKE UPDATE, DELETE, TRUNCATE ON configuration_revisions FROM modelforge_runtime") op.execute("GRANT SELECT, INSERT ON configuration_revisions TO modelforge_runtime") def downgrade() -> None: if op.get_bind().execute(sa.text("SELECT count(*) FROM configuration_revisions")).scalar_one(): raise RuntimeError("Configuration history exists; recover the pre-migration backup instead.") op.drop_table("configuration_revisions") op.drop_table("configuration_state")