This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
"""Index the cached submission limit independently of Alpha quality checks."""
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
revision = "0020"
|
||||
down_revision = "0019"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
op.add_column("alphas", sa.Column("submission_blocked", sa.Boolean(), nullable=False, server_default=sa.false()))
|
||||
table = sa.table("alphas", sa.column("id", sa.String()), sa.column("checks", sa.JSON()),
|
||||
sa.column("submission_blocked", sa.Boolean()))
|
||||
connection = op.get_bind()
|
||||
last_id = None
|
||||
while True:
|
||||
query = sa.select(table.c.id, table.c.checks).order_by(table.c.id).limit(500)
|
||||
if last_id is not None:
|
||||
query = query.where(table.c.id > last_id)
|
||||
rows = connection.execute(query).mappings().all()
|
||||
if not rows:
|
||||
break
|
||||
# Frozen snapshot interpretation; never depend on future application code.
|
||||
blocked = [row["id"] for row in rows if isinstance(row["checks"], list) and any(
|
||||
isinstance(check, dict) and check.get("name") == "REGULAR_SUBMISSION"
|
||||
and isinstance(check.get("result"), str) and check["result"].upper() == "FAIL"
|
||||
for check in row["checks"])]
|
||||
if blocked:
|
||||
connection.execute(table.update().where(table.c.id.in_(blocked)).values(submission_blocked=True))
|
||||
last_id = rows[-1]["id"]
|
||||
op.create_index("ix_alphas_submission_blocked", "alphas", ["submission_blocked"])
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.drop_index("ix_alphas_submission_blocked", table_name="alphas")
|
||||
op.drop_column("alphas", "submission_blocked")
|
||||
Reference in New Issue
Block a user