Database Review Guidelines

This page is specific to database reviews. Please refer to our code review guide for broader advice and best practices for code review in general.

General process

A database review is required for:

A database reviewer is expected to look out for obviously complex queries in the change and review those closer. If the author does not point out specific queries for review and there are no obviously complex queries, it is enough to concentrate on reviewing the migration only.

It is preferable to review queries in SQL form and generally accepted to ask the author to translate any ActiveRecord queries in SQL form for review.

Roles and process

A Merge Request author's role is to:

A database reviewer's role is to:

When there are no database maintainers available

Currently we have a critical shortage of database maintainers. Until we are able to increase the number of database maintainers to support the volume of reviews, we have implemented this temporary solution. If the database reviewer cannot find an available database maintainer then:

  1. Assign the MR for a second review by a database trainee maintainer for further review.
  2. Once satisfied with the review process, and if the database maintainer is still not available, skip the database maintainer approval step and assign the merge request to a backend maintainer for final review and approval.

A database maintainer's role is to:

Distributing review workload

Review workload is distributed using reviewer roulette (example). The MR author should then co-assign the suggested database reviewer. When they give their sign-off, they will hand over to the suggested database maintainer.

If reviewer roulette didn't suggest a database reviewer & maintainer, make sure you have applied the ~database label and rerun the danger-review CI job, or pick someone from the @gl-database team.

How to prepare the merge request for a database review

In order to make reviewing easier and therefore faster, please take the following preparations into account.

Preparation when adding migrations

Preparation when adding or modifying queries

Preparation when adding foreign keys to existing tables

Preparation when adding tables

Preparation when removing columns, tables, indexes or other structures

How to review for database

Timing guidelines for migrations

In general, migrations for a single deploy shouldn't take longer than 1 hour for GitLab.com. The following guidelines are not hard rules, they were estimated to keep migration timing to a minimum.

NOTE: Note: Keep in mind that all runtimes should be measured against GitLab.com.

 Migration Type Execution Time Recommended Notes
Regular migrations on db/migrate 3 minutes A valid exception are index creation as this can take a long time.
Post migrations on db/post_migrate  10 minutes
 Background migrations  --- Since these are suitable for larger tables, it's not possible to set a precise timing guideline, however, any query must stay well below 10s of execution time.