Commit 9d34272d authored by Andreas Brandl's avatar Andreas Brandl

Spread column drops over three releases

parent a01bad5c
...@@ -101,7 +101,7 @@ and details for a database reviewer: ...@@ -101,7 +101,7 @@ and details for a database reviewer:
- Check consistency with `db/schema.rb` and that migrations are [reversible](migration_style_guide.md#reversibility) - Check consistency with `db/schema.rb` and that migrations are [reversible](migration_style_guide.md#reversibility)
- Check queries timing (If any): Queries executed in a migration - Check queries timing (If any): Queries executed in a migration
need to fit comfortably within `15s` - preferably much less than that - on GitLab.com. need to fit comfortably within `15s` - preferably much less than that - on GitLab.com.
- For column removals, make sure the column has been [ignored in a previous release](https://docs.gitlab.com/ee/development/what_requires_downtime.html#dropping-columns) - For column removals, make sure the column has been [ignored in a previous release](what_requires_downtime.md#dropping-columns)
- Check [background migrations](background_migrations.md): - Check [background migrations](background_migrations.md):
- Establish a time estimate for execution on GitLab.com. - Establish a time estimate for execution on GitLab.com.
- They should only be used when migrating data in larger tables. - They should only be used when migrating data in larger tables.
......
...@@ -37,11 +37,19 @@ information on how to use this method. ...@@ -37,11 +37,19 @@ information on how to use this method.
## Dropping Columns ## Dropping Columns
Removing columns is tricky because running GitLab processes may still be using Removing columns is tricky because running GitLab processes may still be using
the columns. To work around this you will need two separate merge requests and the columns. To work around this safely, you will need three steps in three releases:
releases: one to ignore and then remove the column, and one to remove the ignore
rule.
### Step 1: Ignoring The Column 1. Ignoring the column (release M)
1. Dropping the column (release M+1)
1. Removing the ignore rule (release M+2)
The reason we spread this out across three releases is that dropping a column is
a destructive operation that can't be rolled back easily.
Following this procedure helps us to make sure there are no deployments to GitLab.com
and upgrade processes for self-hosted installations that lump together any of these steps.
### Step 1: Ignoring the column (release M)
The first step is to ignore the column in the application code. This is The first step is to ignore the column in the application code. This is
necessary because Rails caches the columns and re-uses this cache in various necessary because Rails caches the columns and re-uses this cache in various
...@@ -58,27 +66,35 @@ end ...@@ -58,27 +66,35 @@ end
Multiple columns can be ignored, too: Multiple columns can be ignored, too:
```ruby ```ruby
ignore_columns %i[updated_at created_at], remove_with: '12.7', remove_after: '2019-12-22' ignore_columns %i[updated_at created_at], remove_with: '12.7', remove_after: '2019-12-22'
``` ```
We require indication of when it is safe to remove the column ignore with We require indication of when it is safe to remove the column ignore with:
- `remove_with` (a GitLab release, typically the next release after adding the column ignore) and - `remove_with`: set to a GitLab release typically two releases (M+2) after adding the
- `remove_after` (a date after which we consider it safe to remove the column ignore) column ignore.
- `remove_after`: set to a date after which we consider it safe to remove the column
ignore, typically within the development cycle of release M+2.
This information allows us to reason better about column ignores and makes sure we This information allows us to reason better about column ignores and makes sure we
don't remove column ignores too early for both regular releases and deployments to GitLab.com. For don't remove column ignores too early for both regular releases and deployments to GitLab.com. For
example, this avoids a situation where we deploy a bulk of changes that include both changes example, this avoids a situation where we deploy a bulk of changes that include both changes
to ignore the column and subsequently remove the column ignore (which would result in a downtime). to ignore the column and subsequently remove the column ignore (which would result in a downtime).
Once added you should create a _post-deployment_ migration that removes the In this example, the change to ignore the column went into release 12.5.
column. Both these changes should be submitted in the same merge request.
### Step 2: Dropping the column (release M+1)
Continuing our example, dropping the column goes into a _post-deployment_ migration in release 12.6:
```ruby
remove_column :user, :updated_at
```
### Step 2: Removing The Ignore Rule ### Step 3: Removing the ignore rule (release M+2)
Once the changes from step 1 have been released & deployed you can set up a With the next release, in this example 12.7, we set up another merge request to remove the ignore rule.
separate merge request that removes the ignore rule. This merge request removes This removes the `ignore_column` line and - if not needed anymore - also the inclusion of `IgnoreableColumns`.
the `ignore_column` line and possibly also the inclusion of `IgnoreableColumns`.
This should only get merged with the release indicated with `remove_with` and once This should only get merged with the release indicated with `remove_with` and once
the `remove_after` date has passed. the `remove_after` date has passed.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment