Grade migration risk by production table size

Agent buildEasy10 minStripe style

Your task

Every database migration gets a review from an agent before it ships. A statement that is instant on a small table can be an outage on a big one, so the agent weighs each step against the production size of its table.

Write review_migration_risk(operations, row_counts): the rule your agent follows for each step of a migration.

  • operations (list of str): the migration's steps, each an operation name such as "create_index".
  • row_counts (list of int): row_counts[i] is the production row count of the table operations[i] touches. A negative count means the count is unknown. If the list is shorter, a missing count is unknown too.
  • Return one verdict per operation, in input order: "safe", "warn" or "ack_required" (a named person must click through before it merges).

Rules, for each operation (names match exactly):

  1. drop_column, drop_table or truncate_table: "ack_required", whatever the size.
  2. add_column_nullable, create_index_concurrently or create_table: "safe", whatever the size.
  3. add_column_with_default, create_index, alter_column_type, add_not_null or backfill_update: decided by the row count.
    • Unknown, or 1,000,000 or more: "ack_required".
    • 10,000 to 999,999: "warn".
    • Below 10,000: "safe".
  4. Any other operation: "ack_required".

Examples

review_migration_risk(operations: list[str], row_counts: list[int]) -> list[str]
Example 1
Inputreview_migration_risk(["add_column_nullable", "create_index", "drop_column"], [50000000, 50000000, 50000000])
Output["safe", "ack_required", "ack_required"]
Example 2
Inputreview_migration_risk(["create_index", "create_index"], [9999, 10000])
Output["safe", "warn"]
Example 3
Inputreview_migration_risk(["alter_column_type"], [-1])
Output["ack_required"]