Module: SafelyChangeColumnDefault
- Extended by:
- ActiveSupport::Concern
- Included in:
- AuthenticationEvent, Doorkeeper::AccessGrant, Doorkeeper::AccessToken, Doorkeeper::DeviceAuthorizationGrant::DeviceGrant, Doorkeeper::OpenidConnect::Request, Namespace, NamespaceSetting, PersonalAccessToken, PlanLimits, Project, ProjectSetting, RawUsageData, UserPreference
- Defined in:
- app/models/concerns/safely_change_column_default.rb
Overview
SafelyChangeColumnDefault concern.
Contains functionality that allows safely changing a column default without downtime. Without this concern, Rails can mutate the old default value to the new default value if the old default is explicitly specified.
Usage:
class SomeModel < ApplicationRecord
include SafelyChangeColumnDefault
columns_changing_default :value
end
# Assume a default of 100 for value
SomeModel.create!(value: 100) # INSERT INTO some_model (value) VALUES (100)
change_column_default('some_model', 'value', from: 100, to: 101)
SomeModel.create!(value: 100) # INSERT INTO some_model (value) VALUES (100)
# Without this concern, would be INSERT INTO some_model (value) DEFAULT VALUES and would insert 101.