"""Give the existing backlog a level too. No report is 未定级 any more. Migration 551 made *new* reports arrive at the lowest tier, and deliberately did not touch history — the reasoning was that a level nobody chose, written across the backlog, is indistinguishable from triage that actually happened. That reasoning protected a distinction nobody needed at the cost of the thing the change was for: 142 of 149 reports still showed as 未定级, the console still displayed the wall, and the report page still nagged the operator to go and grade something. 「默认都是低危 不要再有未定级了 不要让用户 多操作好几下」. So the backlog gets the same treatment, and the distinction is preserved where it actually earns its keep: ``severity_is_default`` stays TRUE on every row this touches, which is what keeps the reply composer off the tier's reward letter. A critical finding nobody has graded can never be offered the $0 informational letter — a figure stated to a researcher cannot be withdrawn. What changes is only that the console stops calling it outstanding work. Two things this does NOT do: * **No money.** ``reward_amount_usd`` is untouched. The lowest tier pays $0 and the arrival level is not a reward decision. * **No fix deadline.** ``fix_due_date`` is untouched, because a deadline derived from a level nobody chose would make reports overdue on a judgement no human made. Only rows with ``severity IS NULL`` are touched, so a graded report keeps its grade and re-running changes nothing. Revision ID: 554 Revises: 553 """ from __future__ import annotations import sqlalchemy as sa from alembic import op revision = "554" down_revision = "553" branch_labels = None depends_on = None TABLE = "bounty_reports" TIERS = "bounty_severity_tiers" def upgrade() -> None: conn = op.get_bind() inspector = sa.inspect(conn) if not inspector.has_table(TABLE) or not inspector.has_table(TIERS): return # The bottom of the ladder, by the ladder's OWN ordering rather than by # reward: an operator who re-prices the tiers must not silently change # which one is the safe default. lowest = conn.execute( sa.text( f"SELECT `key` FROM {TIERS} " # noqa: S608 - constant "WHERE enabled = 1 ORDER BY sort_order DESC LIMIT 1", ), ).scalar() if not lowest: # No enabled tier: leave everything ungraded, which is honest. return conn.execute( sa.text( f"UPDATE {TABLE} " # noqa: S608 - constant "SET severity = :lowest, severity_is_default = 1 " "WHERE severity IS NULL AND deleted_at IS NULL", ), {"lowest": lowest}, ) def downgrade() -> None: conn = op.get_bind() if not sa.inspect(conn).has_table(TABLE): return # Only the rows this migration set: flagged as the arrival default. A # level somebody chose has the flag cleared and is left alone. conn.execute( sa.text( f"UPDATE {TABLE} " # noqa: S608 - constant "SET severity = NULL " "WHERE severity_is_default = 1 AND deleted_at IS NULL", ), )