Skip to content

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

  1. Detect remove_column calls and read the column and table name.
  2. Using the table name, look up the db/docs/table_name.yml.
  3. Read the classes array.
  4. Try to locate the actual ruby files where these models are implemented.
  5. Parse the ignored_columns array.

Option 2: Runtime check in dev and test environments

  1. Hook into the remove_column method.
  2. When the method is invoked, look up the related model classes.
  3. 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