diff options
Diffstat (limited to 'app')
33 files changed, 93 insertions, 0 deletions
diff --git a/app/models/admin/abuse_report_label.rb b/app/models/admin/abuse_report_label.rb index a2ccc8b5513..6f951b02933 100644 --- a/app/models/admin/abuse_report_label.rb +++ b/app/models/admin/abuse_report_label.rb @@ -2,5 +2,6 @@ module Admin class AbuseReportLabel < Label + self.allow_legacy_sti_class = true end end diff --git a/app/models/application_record.rb b/app/models/application_record.rb index 15e44296635..45983c08a3e 100644 --- a/app/models/application_record.rb +++ b/app/models/application_record.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true class ApplicationRecord < ActiveRecord::Base + include DisablesSti include DatabaseReflection include Transactions include LegacyBulkInsert diff --git a/app/models/badges/group_badge.rb b/app/models/badges/group_badge.rb index f74c9f89e9f..2ef8a3bd821 100644 --- a/app/models/badges/group_badge.rb +++ b/app/models/badges/group_badge.rb @@ -3,6 +3,8 @@ class GroupBadge < Badge include EachBatch + self.allow_legacy_sti_class = true + belongs_to :group validates :group, presence: true diff --git a/app/models/badges/project_badge.rb b/app/models/badges/project_badge.rb index 8c51ebafb5e..6a8a70dfe02 100644 --- a/app/models/badges/project_badge.rb +++ b/app/models/badges/project_badge.rb @@ -3,6 +3,8 @@ class ProjectBadge < Badge include EachBatch + self.allow_legacy_sti_class = true + belongs_to :project validates :project, presence: true diff --git a/app/models/ci/bridge.rb b/app/models/ci/bridge.rb index 564b10ea8e3..8db80cd05dc 100644 --- a/app/models/ci/bridge.rb +++ b/app/models/ci/bridge.rb @@ -16,6 +16,8 @@ module Ci pipeline_variables: false }.freeze + self.allow_legacy_sti_class = true + belongs_to :project belongs_to :trigger_request diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index 8536f790b7d..1a758c80df8 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -15,6 +15,8 @@ module Ci extend ::Gitlab::Utils::Override + self.allow_legacy_sti_class = true + belongs_to :project, inverse_of: :builds belongs_to :runner belongs_to :trigger_request diff --git a/app/models/ci/processable.rb b/app/models/ci/processable.rb index 7ad1a727a0e..132f706d265 100644 --- a/app/models/ci/processable.rb +++ b/app/models/ci/processable.rb @@ -9,6 +9,8 @@ module Ci include Ci::Metadatable extend ::Gitlab::Utils::Override + self.allow_legacy_sti_class = true + has_one :resource, class_name: 'Ci::Resource', foreign_key: 'build_id', inverse_of: :processable has_one :sourced_pipeline, class_name: 'Ci::Sources::Pipeline', foreign_key: :source_job_id, inverse_of: :source_job diff --git a/app/models/concerns/disables_sti.rb b/app/models/concerns/disables_sti.rb new file mode 100644 index 00000000000..418da323d3d --- /dev/null +++ b/app/models/concerns/disables_sti.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +# Disables usage of STI +# See https://docs.gitlab.com/ee/development/database/single_table_inheritance.html +module DisablesSti + extend ActiveSupport::Concern + + SKIP_STI_CHECK = Gitlab.dev_or_test_env? && + Gitlab::Utils.to_boolean(ENV['SKIP_STI_CHECK'], default: false) + + included do + class_attribute :allow_legacy_sti_class + end + + class_methods do + def new(...) + if sti_class_disallowed? + raise( + "Do not use Single Table Inheritance (`#{name}` inherits `#{base_class.name}`). " \ + "See https://docs.gitlab.com/ee/development/database/single_table_inheritance.html" # rubocop:disable Gitlab/DocUrl -- route helpers don't always work + ) + end + + super + end + + def sti_class_disallowed? + return false if SKIP_STI_CHECK + + self != base_class && !allow_legacy_sti_class && has_attribute?(inheritance_column) + end + end +end diff --git a/app/models/deploy_key.rb b/app/models/deploy_key.rb index de777b8ae53..9ede494cfcc 100644 --- a/app/models/deploy_key.rb +++ b/app/models/deploy_key.rb @@ -6,6 +6,8 @@ class DeployKey < Key include PolicyActor include Presentable + self.allow_legacy_sti_class = true + has_many :deploy_keys_projects, inverse_of: :deploy_key, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent has_many :projects, through: :deploy_keys_projects diff --git a/app/models/diff_note.rb b/app/models/diff_note.rb index d680d0e334f..33dd7308e14 100644 --- a/app/models/diff_note.rb +++ b/app/models/diff_note.rb @@ -8,6 +8,8 @@ class DiffNote < Note include DiffPositionableNote include Gitlab::Utils::StrongMemoize + self.allow_legacy_sti_class = true + def self.noteable_types %w[MergeRequest Commit DesignManagement::Design] end diff --git a/app/models/discussion_note.rb b/app/models/discussion_note.rb index fa830179022..7e17a9c759e 100644 --- a/app/models/discussion_note.rb +++ b/app/models/discussion_note.rb @@ -7,6 +7,8 @@ class DiscussionNote < Note # This prepend must stay here because the `validates` below depends on it. prepend_mod_with('DiscussionNote') # rubocop: disable Cop/InjectEnterpriseEditionModule + self.allow_legacy_sti_class = true + # Names of all implementers of `Noteable` that support discussions. def self.noteable_types %w[MergeRequest Issue Commit Snippet AbuseReport] diff --git a/app/models/generic_commit_status.rb b/app/models/generic_commit_status.rb index f795585dfc5..356acfa063d 100644 --- a/app/models/generic_commit_status.rb +++ b/app/models/generic_commit_status.rb @@ -3,6 +3,8 @@ class GenericCommitStatus < CommitStatus EXTERNAL_STAGE_IDX = 1_000_000 + self.allow_legacy_sti_class = true + validates :target_url, addressable_url: true, length: { maximum: 255 }, allow_nil: true validate :name_uniqueness_across_types, unless: :importing? diff --git a/app/models/group.rb b/app/models/group.rb index 59383b51bb9..7092d5217e1 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -23,6 +23,8 @@ class Group < Namespace extend ::Gitlab::Utils::Override + self.allow_legacy_sti_class = true + README_PROJECT_PATH = 'gitlab-profile' def self.sti_name diff --git a/app/models/group_label.rb b/app/models/group_label.rb index 46e56166951..efad937b390 100644 --- a/app/models/group_label.rb +++ b/app/models/group_label.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true class GroupLabel < Label + self.allow_legacy_sti_class = true + belongs_to :group belongs_to :parent_container, foreign_key: :group_id, class_name: 'Group' diff --git a/app/models/hooks/project_hook.rb b/app/models/hooks/project_hook.rb index 05c5ad22218..9b700ff17b2 100644 --- a/app/models/hooks/project_hook.rb +++ b/app/models/hooks/project_hook.rb @@ -6,6 +6,8 @@ class ProjectHook < WebHook include Limitable extend ::Gitlab::Utils::Override + self.allow_legacy_sti_class = true + self.limit_scope = :project triggerable_hooks [ diff --git a/app/models/hooks/service_hook.rb b/app/models/hooks/service_hook.rb index 453b986ca4d..b1f1ab79b6a 100644 --- a/app/models/hooks/service_hook.rb +++ b/app/models/hooks/service_hook.rb @@ -5,6 +5,8 @@ class ServiceHook < WebHook extend ::Gitlab::Utils::Override + self.allow_legacy_sti_class = true + belongs_to :integration validates :integration, presence: true diff --git a/app/models/hooks/system_hook.rb b/app/models/hooks/system_hook.rb index 3c7f0ef9ffc..57409faee5a 100644 --- a/app/models/hooks/system_hook.rb +++ b/app/models/hooks/system_hook.rb @@ -3,6 +3,8 @@ class SystemHook < WebHook include TriggerableHooks + self.allow_legacy_sti_class = true + triggerable_hooks [ :repository_update_hooks, :push_hooks, diff --git a/app/models/integration.rb b/app/models/integration.rb index 2c5731deb58..c7161574a17 100644 --- a/app/models/integration.rb +++ b/app/models/integration.rb @@ -15,6 +15,7 @@ class Integration < ApplicationRecord UnknownType = Class.new(StandardError) + self.allow_legacy_sti_class = true self.inheritance_column = :type_new INTEGRATION_NAMES = %w[ diff --git a/app/models/label_note.rb b/app/models/label_note.rb index eda650f2fa2..dcc92dbb6ae 100644 --- a/app/models/label_note.rb +++ b/app/models/label_note.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true class LabelNote < SyntheticNote + self.allow_legacy_sti_class = true + attr_accessor :resource_parent attr_reader :events diff --git a/app/models/legacy_diff_note.rb b/app/models/legacy_diff_note.rb index ede20578850..336264317ac 100644 --- a/app/models/legacy_diff_note.rb +++ b/app/models/legacy_diff_note.rb @@ -9,6 +9,8 @@ class LegacyDiffNote < Note include NoteOnDiff + self.allow_legacy_sti_class = true + serialize :st_diff # rubocop:disable Cop/ActiveRecordSerialize validates :line_code, presence: true, line_code: true diff --git a/app/models/members/group_member.rb b/app/models/members/group_member.rb index b5a590d646e..50ae70734e4 100644 --- a/app/models/members/group_member.rb +++ b/app/models/members/group_member.rb @@ -4,6 +4,8 @@ class GroupMember < Member include FromUnion include CreatedAtFilterable + self.allow_legacy_sti_class = true + SOURCE_TYPE = 'Namespace' SOURCE_TYPE_FORMAT = /\ANamespace\z/ diff --git a/app/models/members/project_member.rb b/app/models/members/project_member.rb index 5e5f9ab7385..7ae6e138aca 100644 --- a/app/models/members/project_member.rb +++ b/app/models/members/project_member.rb @@ -4,6 +4,8 @@ class ProjectMember < Member SOURCE_TYPE = 'Project' SOURCE_TYPE_FORMAT = /\AProject\z/ + self.allow_legacy_sti_class = true + belongs_to :project, foreign_key: 'source_id' delegate :namespace_id, to: :project diff --git a/app/models/members/project_namespace_member.rb b/app/models/members/project_namespace_member.rb index 0e0c52ee3ca..f74a085669c 100644 --- a/app/models/members/project_namespace_member.rb +++ b/app/models/members/project_namespace_member.rb @@ -4,4 +4,5 @@ # This file is a part of the Consolidate Group and Project member management epic, # and will be developed further as we progress through that epic. class ProjectNamespaceMember < ProjectMember # rubocop:disable Gitlab/NamespacedClass + self.allow_legacy_sti_class = true end diff --git a/app/models/milestone_note.rb b/app/models/milestone_note.rb index 14808158fd0..2bbd2d9a383 100644 --- a/app/models/milestone_note.rb +++ b/app/models/milestone_note.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true class MilestoneNote < SyntheticNote + self.allow_legacy_sti_class = true + attr_accessor :milestone def self.from_event(event, resource: nil, resource_parent: nil) diff --git a/app/models/namespaces/project_namespace.rb b/app/models/namespaces/project_namespace.rb index 288c5c0d2d4..573944d8f5c 100644 --- a/app/models/namespaces/project_namespace.rb +++ b/app/models/namespaces/project_namespace.rb @@ -2,6 +2,8 @@ module Namespaces class ProjectNamespace < Namespace + self.allow_legacy_sti_class = true + # These aliases are added to make it easier to sync parent/parent_id attribute with # project.namespace/project.namespace_id attribute. # diff --git a/app/models/namespaces/user_namespace.rb b/app/models/namespaces/user_namespace.rb index 408acb6dcce..fde6c4291ee 100644 --- a/app/models/namespaces/user_namespace.rb +++ b/app/models/namespaces/user_namespace.rb @@ -22,6 +22,8 @@ module Namespaces #################################################################### class UserNamespace < Namespace + self.allow_legacy_sti_class = true + def self.sti_name 'User' end diff --git a/app/models/packages/ml_model/package.rb b/app/models/packages/ml_model/package.rb index de2b5f8f2a8..a327a30ce26 100644 --- a/app/models/packages/ml_model/package.rb +++ b/app/models/packages/ml_model/package.rb @@ -3,6 +3,8 @@ module Packages module MlModel class Package < Packages::Package + self.allow_legacy_sti_class = true + has_one :model_version, class_name: "Ml::ModelVersion", inverse_of: :package validates :name, diff --git a/app/models/personal_snippet.rb b/app/models/personal_snippet.rb index 0915278fb65..299f1f7a630 100644 --- a/app/models/personal_snippet.rb +++ b/app/models/personal_snippet.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true class PersonalSnippet < Snippet + self.allow_legacy_sti_class = true + include WithUploads def parent_user diff --git a/app/models/project_label.rb b/app/models/project_label.rb index 05d7b7429ff..2867006bd2e 100644 --- a/app/models/project_label.rb +++ b/app/models/project_label.rb @@ -3,6 +3,8 @@ class ProjectLabel < Label MAX_NUMBER_OF_PRIORITIES = 1 + self.allow_legacy_sti_class = true + belongs_to :project belongs_to :parent_container, foreign_key: :project_id, class_name: 'Project' diff --git a/app/models/project_snippet.rb b/app/models/project_snippet.rb index 7a80ad33d68..0f3c22bbb92 100644 --- a/app/models/project_snippet.rb +++ b/app/models/project_snippet.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true class ProjectSnippet < Snippet + self.allow_legacy_sti_class = true + belongs_to :project validates :project, presence: true diff --git a/app/models/push_event.rb b/app/models/push_event.rb index 0f626cb618e..4e18d4840e6 100644 --- a/app/models/push_event.rb +++ b/app/models/push_event.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true class PushEvent < Event + self.allow_legacy_sti_class = true + # This validation exists so we can't accidentally use PushEvent with a # different "action" value. validate :validate_push_action diff --git a/app/models/state_note.rb b/app/models/state_note.rb index 93c025a9bf0..8b1474b3c7a 100644 --- a/app/models/state_note.rb +++ b/app/models/state_note.rb @@ -3,6 +3,8 @@ class StateNote < SyntheticNote include Gitlab::Utils::StrongMemoize + self.allow_legacy_sti_class = true + def self.from_event(event, resource: nil, resource_parent: nil) attrs = note_attributes(action_by(event), event, resource, resource_parent) diff --git a/app/models/synthetic_note.rb b/app/models/synthetic_note.rb index f88fa052665..e71f9838d9b 100644 --- a/app/models/synthetic_note.rb +++ b/app/models/synthetic_note.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true class SyntheticNote < Note + self.allow_legacy_sti_class = true + attr_accessor :resource_parent, :event def self.note_attributes(action, event, resource, resource_parent) |