Validate ignored_columns when removing a DB column
Problem to solve
When removing database columns engineers must follow the remove column procedure to avoid undefined column errors when running zero-downtime deployments. Since the procedure runs for several releases, missing to check the ignored_columns
definition during review may happen.
Related incident: gitlab-com/gl-infra/production#16274 (closed)
Proposal
Implement an automated way to check if the table/model where the column is removed has ignored_columns
definition.
Option 1: rubocop rule
- Detect
remove_column
calls and read the column and table name. - Using the table name, look up the
db/docs/table_name.yml
. - Read the
classes
array. - Try to locate the actual ruby files where these models are implemented.
- Parse the
ignored_columns
array.
Option 2: Runtime check in dev and test environments
- Hook into the
remove_column
method. - When the method is invoked, look up the related model classes.
- Look for the
ignored_columns
and if the removed column is not part of the list, raise error.
Note: there can be cases where we don't want to ignore the columns, so we should provide some sort of fallback. For example, temporary columns added within a transaction.
Edited by Adam Hegyi