Commit 262a9c56 authored by Andreas Brandl's avatar Andreas Brandl

Add IgnorableColumns concern

This is basically only documenting when column-ignores can be removed
again

Relates to https://gitlab.com/gitlab-org/gitlab/issues/33127
parent ec916fc3
......@@ -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
......
......@@ -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_columns :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
......
# frozen_string_literal: true
module IgnorableColumns
extend ActiveSupport::Concern
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 'Please indicate when we can stop ignoring columns with remove_after, example: ignore_columns(:name, remove_after: \'2019-12-01\', remove_with: \'12.6\')' unless remove_after && remove_with
self.ignored_columns += columns
end
end
end
......@@ -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_columns :can_push, remove_after: '2019-12-15', remove_with: '12.6'
accepts_nested_attributes_for :deploy_keys_projects
......
......@@ -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_columns :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
......
......@@ -11,6 +11,7 @@ module EE
extend ::Gitlab::Cache::RequestCache
include ::Gitlab::Utils::StrongMemoize
include ::EE::GitlabRoutingHelper # rubocop: disable Cop/InjectEnterpriseEditionModule
include IgnorableColumns
GIT_LFS_DOWNLOAD_OPERATION = 'download'.freeze
......@@ -23,10 +24,7 @@ module EE
include DeprecatedApprovalsBeforeMerge
include UsageStatistics
self.ignored_columns += %i[
mirror_last_update_at
mirror_last_successful_update_at
]
ignore_columns :mirror_last_update_at, :mirror_last_successful_update_at, remove_after: '2019-12-15', remove_with: '12.6'
before_save :set_override_pull_mirror_available, unless: -> { ::Gitlab::CurrentSettings.mirror_available }
before_save :set_next_execution_timestamp_to_now, if: ->(project) { project.mirror? && project.mirror_changed? && project.import_state }
......
......@@ -3,9 +3,10 @@
module Operations
class FeatureFlagsClient < ApplicationRecord
include TokenAuthenticatable
include IgnorableColumns
self.table_name = 'operations_feature_flags_clients'
self.ignored_columns += %i[token]
ignore_columns :token, remove_after: '2019-12-15', remove_with: '12.6'
belongs_to :project
......
# frozen_string_literal: true
require 'spec_helper'
describe IgnorableColumns do
class User < ApplicationRecord
include IgnorableColumns
end
it 'adds columns to ignored_columns' do
expect do
User.ignore_columns(:name, :created_at, remove_after: '2019-12-01', remove_with: '12.6')
end.to change { User.ignored_columns }.from([]).to(%w(name created_at))
end
it 'requires remove_after attribute to be set' do
expect { User.ignore_columns(:name, remove_after: nil, remove_with: 12.6) }.to raise_error
end
it 'requires remove_with attribute to be set' do
expect { User.ignore_columns(:name, remove_after: '2019-12-01', remove_with: nil) }.to raise_error
end
end
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment