2023-08-11 15:25:44 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module HasDeprecatedColumns
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
class_methods do
|
|
|
|
def deprecate_column(column_name, drop_from:, raise_error: false, message: nil)
|
2024-01-31 01:34:10 +08:00
|
|
|
message = message.presence || "column `#{column_name}` is deprecated."
|
2023-08-11 15:25:44 +08:00
|
|
|
|
2024-01-31 01:34:10 +08:00
|
|
|
define_method(column_name) do
|
|
|
|
Discourse.deprecate(message, drop_from: drop_from, raise_error: raise_error)
|
|
|
|
super()
|
|
|
|
end
|
2023-08-11 15:25:44 +08:00
|
|
|
|
2024-01-31 01:34:10 +08:00
|
|
|
define_method("#{column_name}=") do |value|
|
|
|
|
Discourse.deprecate(message, drop_from: drop_from, raise_error: raise_error)
|
|
|
|
super(value)
|
2023-08-11 15:25:44 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|