"""Add inherited curation policies and configurable source limits.""" from collections.abc import Sequence import sqlalchemy as sa from alembic import op revision: str = "20260804_0009" down_revision: str | Sequence[str] | None = "20260804_0008" branch_labels: str | Sequence[str] | None = None depends_on: str | Sequence[str] | None = None def upgrade() -> None: with op.batch_alter_table("curation_settings") as batch: batch.add_column( sa.Column("retry_initial_seconds", sa.Integer(), nullable=False, server_default="300") ) batch.add_column( sa.Column("retry_max_seconds", sa.Integer(), nullable=False, server_default="3600") ) batch.add_column( sa.Column("max_source_files", sa.Integer(), nullable=False, server_default="1000") ) batch.add_column( sa.Column( "max_source_chars", sa.Integer(), nullable=False, server_default="20000000" ) ) batch.add_column( sa.Column( "text_file_max_bytes", sa.Integer(), nullable=False, server_default="2097152" ) ) batch.add_column( sa.Column( "rich_file_max_bytes", sa.Integer(), nullable=False, server_default="52428800" ) ) op.create_table( "curation_policy_overrides", sa.Column("key", sa.String(length=120), nullable=False), sa.Column("scope", sa.String(length=20), nullable=False), sa.Column("workspace_type", sa.String(length=32), nullable=True), sa.Column("project_id", sa.String(length=36), nullable=True), sa.Column("values_json", sa.Text(), nullable=False, server_default="{}"), sa.Column("created_at", sa.DateTime(timezone=True), nullable=False), sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False), sa.ForeignKeyConstraint(["project_id"], ["projects.id"], ondelete="CASCADE"), sa.PrimaryKeyConstraint("key"), ) op.create_index( "ix_curation_policy_overrides_scope", "curation_policy_overrides", ["scope"], unique=False, ) op.create_index( "ix_curation_policy_overrides_workspace_type", "curation_policy_overrides", ["workspace_type"], unique=False, ) op.create_index( "ix_curation_policy_overrides_project_id", "curation_policy_overrides", ["project_id"], unique=False, ) def downgrade() -> None: op.drop_index( "ix_curation_policy_overrides_project_id", table_name="curation_policy_overrides", ) op.drop_index( "ix_curation_policy_overrides_workspace_type", table_name="curation_policy_overrides", ) op.drop_index( "ix_curation_policy_overrides_scope", table_name="curation_policy_overrides", ) op.drop_table("curation_policy_overrides") with op.batch_alter_table("curation_settings") as batch: batch.drop_column("rich_file_max_bytes") batch.drop_column("text_file_max_bytes") batch.drop_column("max_source_chars") batch.drop_column("max_source_files") batch.drop_column("retry_max_seconds") batch.drop_column("retry_initial_seconds")