diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-01 09:06:11 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-01 09:06:11 +0300 |
commit | 864475536355651a9f7caa5b1606aa5640424ec3 (patch) | |
tree | 1dc80c96ddf3f9049c4a163b4c49f052a9b1a4ad /app/models | |
parent | 7ddd5846999029916b2b6d8560b5b0f02ec0f6ea (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/application_setting.rb | 7 | ||||
-rw-r--r-- | app/models/ci/build.rb | 10 | ||||
-rw-r--r-- | app/models/ci/runner.rb | 3 | ||||
-rw-r--r-- | app/models/concerns/ignorable_columns.rb | 45 | ||||
-rw-r--r-- | app/models/deploy_key.rb | 3 | ||||
-rw-r--r-- | app/models/epic.rb | 4 | ||||
-rw-r--r-- | app/models/issue.rb | 4 | ||||
-rw-r--r-- | app/models/merge_request.rb | 4 | ||||
-rw-r--r-- | app/models/project.rb | 3 | ||||
-rw-r--r-- | app/models/project_ci_cd_setting.rb | 5 |
10 files changed, 65 insertions, 23 deletions
diff --git a/app/models/application_setting.rb b/app/models/application_setting.rb index 72605af433f..c681d941e35 100644 --- a/app/models/application_setting.rb +++ b/app/models/application_setting.rb @@ -5,12 +5,9 @@ class ApplicationSetting < ApplicationRecord include CacheMarkdownField include TokenAuthenticatable include ChronicDurationAttribute + include IgnorableColumns - # Only remove this >= %12.6 and >= 2019-12-01 - self.ignored_columns += %i[ - pendo_enabled - pendo_url - ] + ignore_columns :pendo_enabled, :pendo_url, remove_after: '2019-12-01', remove_with: '12.6' add_authentication_token_field :runners_registration_token, encrypted: -> { Feature.enabled?(:application_settings_tokens_optional_encryption, default_enabled: true) ? :optional : :required } add_authentication_token_field :health_check_access_token diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index 5192f85ad8d..caa4478c848 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -13,17 +13,11 @@ module Ci include Importable include Gitlab::Utils::StrongMemoize include HasRef + include IgnorableColumns BuildArchivedError = Class.new(StandardError) - self.ignored_columns += %i[ - artifacts_file - artifacts_file_store - artifacts_metadata - artifacts_metadata_store - artifacts_size - commands - ] + ignore_columns :artifacts_file, :artifacts_file_store, :artifacts_metadata, :artifacts_metadata_store, :artifacts_size, :commands, remove_after: '2019-12-15', remove_with: '12.7' belongs_to :project, inverse_of: :builds belongs_to :runner diff --git a/app/models/ci/runner.rb b/app/models/ci/runner.rb index c4a4410e8fc..3f409b8bb22 100644 --- a/app/models/ci/runner.rb +++ b/app/models/ci/runner.rb @@ -8,6 +8,7 @@ module Ci include ChronicDurationAttribute include FromUnion include TokenAuthenticatable + include IgnorableColumns add_authentication_token_field :token, encrypted: -> { Feature.enabled?(:ci_runners_tokens_optional_encryption, default_enabled: true) ? :optional : :required } @@ -35,7 +36,7 @@ module Ci FORM_EDITABLE = %i[description tag_list active run_untagged locked access_level maximum_timeout_human_readable].freeze - self.ignored_columns += %i[is_shared] + ignore_column :is_shared, remove_after: '2019-12-15', remove_with: '12.6' has_many :builds has_many :runner_projects, inverse_of: :runner, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent diff --git a/app/models/concerns/ignorable_columns.rb b/app/models/concerns/ignorable_columns.rb new file mode 100644 index 00000000000..744a1f0b5f3 --- /dev/null +++ b/app/models/concerns/ignorable_columns.rb @@ -0,0 +1,45 @@ +# frozen_string_literal: true + +module IgnorableColumns + extend ActiveSupport::Concern + + ColumnIgnore = Struct.new(:remove_after, :remove_with) do + def safe_to_remove? + Date.today > remove_after + end + + def to_s + "(#{remove_after}, #{remove_with})" + end + end + + class_methods do + # 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 remove_after =~ Gitlab::Regex.utc_date_regex + 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 + + 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) + end + end + + alias_method :ignore_column, :ignore_columns + + def ignored_columns_details + unless defined?(@ignored_columns_details) + IGNORE_COLUMN_MUTEX.synchronize do + @ignored_columns_details ||= superclass.try(:ignored_columns_details)&.dup || {} + end + end + + @ignored_columns_details + end + + IGNORE_COLUMN_MUTEX = Mutex.new + end +end diff --git a/app/models/deploy_key.rb b/app/models/deploy_key.rb index 22ab326a0ab..19216281e48 100644 --- a/app/models/deploy_key.rb +++ b/app/models/deploy_key.rb @@ -2,6 +2,7 @@ class DeployKey < Key include FromUnion + include IgnorableColumns has_many :deploy_keys_projects, inverse_of: :deploy_key, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent has_many :projects, through: :deploy_keys_projects @@ -10,7 +11,7 @@ class DeployKey < Key scope :are_public, -> { where(public: true) } scope :with_projects, -> { includes(deploy_keys_projects: { project: [:route, :namespace] }) } - self.ignored_columns += %i[can_push] + ignore_column :can_push, remove_after: '2019-12-15', remove_with: '12.6' accepts_nested_attributes_for :deploy_keys_projects diff --git a/app/models/epic.rb b/app/models/epic.rb index 01ef8bd100e..8222bbf9656 100644 --- a/app/models/epic.rb +++ b/app/models/epic.rb @@ -3,7 +3,9 @@ # Placeholder class for model that is implemented in EE # It reserves '&' as a reference prefix, but the table does not exists in CE class Epic < ApplicationRecord - self.ignored_columns += %i[milestone_id] + include IgnorableColumns + + ignore_column :milestone_id, remove_after: '2019-12-15', remove_with: '12.7' def self.link_reference_pattern nil diff --git a/app/models/issue.rb b/app/models/issue.rb index 7e5a94fc0a1..4a17c93e7a2 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -14,6 +14,7 @@ class Issue < ApplicationRecord include TimeTrackable include ThrottledTouch include LabelEventable + include IgnorableColumns DueDateStruct = Struct.new(:title, :name).freeze NoDueDate = DueDateStruct.new('No Due Date', '0').freeze @@ -68,8 +69,7 @@ class Issue < ApplicationRecord scope :counts_by_state, -> { reorder(nil).group(:state_id).count } - # Only remove after 2019-12-22 and with %12.7 - self.ignored_columns += %i[state] + ignore_column :state, remove_with: '12.7', remove_after: '2019-12-22' after_commit :expire_etag_cache after_save :ensure_metrics, unless: :imported? diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index b0d030c78b7..a25d1ccccca 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -17,6 +17,7 @@ class MergeRequest < ApplicationRecord include FromUnion include DeprecatedAssignee include ShaAttribute + include IgnorableColumns sha_attribute :squash_commit_sha @@ -239,8 +240,7 @@ class MergeRequest < ApplicationRecord with_state(:opened).where(auto_merge_enabled: true) end - # Only remove after 2019-12-22 and with %12.7 - self.ignored_columns += %i[state] + ignore_column :state, remove_with: '12.7', remove_after: '2019-12-22' after_save :keep_around_commit diff --git a/app/models/project.rb b/app/models/project.rb index 3177a5b83f9..b452f05c590 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -31,6 +31,7 @@ class Project < ApplicationRecord include FeatureGate include OptionallySearch include FromUnion + include IgnorableColumns extend Gitlab::Cache::RequestCache extend Gitlab::ConfigHelper @@ -64,7 +65,7 @@ class Project < ApplicationRecord # TODO: remove once GitLab 12.5 is released # https://gitlab.com/gitlab-org/gitlab/issues/34638 - self.ignored_columns += %i[merge_requests_require_code_owner_approval] + ignore_column :merge_requests_require_code_owner_approval, remove_after: '2019-12-01', remove_with: '12.6' default_value_for :archived, false default_value_for :resolve_outdated_diff_discussions, false diff --git a/app/models/project_ci_cd_setting.rb b/app/models/project_ci_cd_setting.rb index d089a004d3d..b292d39dae7 100644 --- a/app/models/project_ci_cd_setting.rb +++ b/app/models/project_ci_cd_setting.rb @@ -1,9 +1,10 @@ # frozen_string_literal: true class ProjectCiCdSetting < ApplicationRecord - # TODO: remove once GitLab 12.7 is released + include IgnorableColumns # https://gitlab.com/gitlab-org/gitlab/issues/36651 - self.ignored_columns += %i[merge_trains_enabled] + ignore_column :merge_trains_enabled, remove_with: '12.7', remove_after: '2019-12-22' + belongs_to :project, inverse_of: :ci_cd_settings # The version of the schema that first introduced this model/table. |