Add rollback migration helpers for change_column_type_concurrently
The following migration helpers:
Have no proper rollback (undo_
) counterparts, so their changes can not be rolled back correctly in case of an incident.
Other than the separate issue discussed in #247489 (closed), they more or less work if they are both successfully executed and then rolled back together.
Their usage is explained in Changing Column Types Guide: the provided example does not work correctly in case only the first of the two migrations has to be rolled back by itself: The result of the rollback is going to basically result in a state similar to both the migrations having run, not the initial state of the database.
Given that username
is a string column, migrating and then rolling back the following will result to username
being a text column.
# A regular migration in db/migrate
class ChangeUsersUsernameStringToText < ActiveRecord::Migration[4.2]
include Gitlab::Database::MigrationHelpers
disable_ddl_transaction!
def up
change_column_type_concurrently :users, :username, :text
end
def down
cleanup_concurrent_column_type_change :users, :username
end
end
We should add undo migration helpers for both and update the guidelines to reflect the proper use, similarly to the examples provided for Renaming Columns