Grade migration risk by production table size
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 tableoperations[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):
drop_column,drop_tableortruncate_table:"ack_required", whatever the size.add_column_nullable,create_index_concurrentlyorcreate_table:"safe", whatever the size.add_column_with_default,create_index,alter_column_type,add_not_nullorbackfill_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".
- Unknown, or 1,000,000 or more:
- Any other operation:
"ack_required".
Examples
review_migration_risk(operations: list[str], row_counts: list[int]) -> list[str]Example 1
Input
review_migration_risk(["add_column_nullable", "create_index", "drop_column"], [50000000, 50000000, 50000000])Output
["safe", "ack_required", "ack_required"]Example 2
Input
review_migration_risk(["create_index", "create_index"], [9999, 10000])Output
["safe", "warn"]Example 3
Input
review_migration_risk(["alter_column_type"], [-1])Output
["ack_required"]