diff options
Diffstat (limited to 'app/models/concerns')
-rw-r--r-- | app/models/concerns/ignorable_columns.rb | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/app/models/concerns/ignorable_columns.rb b/app/models/concerns/ignorable_columns.rb index 249d0b99494..fb114eed400 100644 --- a/app/models/concerns/ignorable_columns.rb +++ b/app/models/concerns/ignorable_columns.rb @@ -3,13 +3,11 @@ module IgnorableColumns extend ActiveSupport::Concern - ColumnIgnore = Struct.new(:remove_after, :remove_with) do + ColumnIgnore = Struct.new(:remove_after, :remove_with, :remove_never) do def safe_to_remove? - Date.today > remove_after - end + return false if remove_never - def to_s - "(#{remove_after}, #{remove_with})" + Date.today > remove_after end end @@ -17,14 +15,17 @@ module IgnorableColumns # Ignore database columns in a model # # Indicate the earliest date and release we can stop ignoring the column with +remove_after+ (a date string) and +remove_with+ (a release) - def ignore_columns(*columns, remove_after:, remove_with:) - raise ArgumentError, 'Please indicate when we can stop ignoring columns with remove_after (date string YYYY-MM-DD), example: ignore_columns(:name, remove_after: \'2019-12-01\', remove_with: \'12.6\')' unless Gitlab::Regex.utc_date_regex.match?(remove_after) - raise ArgumentError, 'Please indicate in which release we can stop ignoring columns with remove_with, example: ignore_columns(:name, remove_after: \'2019-12-01\', remove_with: \'12.6\')' unless remove_with + def ignore_columns(*columns, remove_after: nil, remove_with: nil, remove_never: false) + unless remove_never + raise ArgumentError, 'Please indicate when we can stop ignoring columns with remove_after (date string YYYY-MM-DD), example: ignore_columns(:name, remove_after: \'2019-12-01\', remove_with: \'12.6\')' unless remove_after && Gitlab::Regex.utc_date_regex.match?(remove_after) + raise ArgumentError, 'Please indicate in which release we can stop ignoring columns with remove_with, example: ignore_columns(:name, remove_after: \'2019-12-01\', remove_with: \'12.6\')' unless remove_with + end self.ignored_columns += columns.flatten # rubocop:disable Cop/IgnoredColumns columns.flatten.each do |column| - self.ignored_columns_details[column.to_sym] = ColumnIgnore.new(Date.parse(remove_after), remove_with) + remove_after_date = remove_after ? Date.parse(remove_after) : nil + self.ignored_columns_details[column.to_sym] = ColumnIgnore.new(remove_after_date, remove_with, remove_never) end end |