Commit bf71f9fe authored by Fabio Pitino's avatar Fabio Pitino

Merge branch 'remove-bad-join-from-destroy-ci-records' into 'master'

Use CommitStatus scopes to explicitly destroy records instead of nullifying the foreign key

See merge request gitlab-org/gitlab!74925
parents 97d7576e 54bfc55f
...@@ -190,8 +190,6 @@ module Ci ...@@ -190,8 +190,6 @@ module Ci
scope :without_coverage, -> { where(coverage: nil) } scope :without_coverage, -> { where(coverage: nil) }
scope :with_coverage_regex, -> { where.not(coverage_regex: nil) } scope :with_coverage_regex, -> { where.not(coverage_regex: nil) }
scope :for_project, -> (project_id) { where(project_id: project_id) }
acts_as_taggable acts_as_taggable
add_authentication_token_field :token, encrypted: :required add_authentication_token_field :token, encrypted: :required
......
...@@ -53,6 +53,7 @@ class CommitStatus < Ci::ApplicationRecord ...@@ -53,6 +53,7 @@ class CommitStatus < Ci::ApplicationRecord
scope :before_stage, -> (index) { where('stage_idx < ?', index) } scope :before_stage, -> (index) { where('stage_idx < ?', index) }
scope :for_stage, -> (index) { where(stage_idx: index) } scope :for_stage, -> (index) { where(stage_idx: index) }
scope :after_stage, -> (index) { where('stage_idx > ?', index) } scope :after_stage, -> (index) { where('stage_idx > ?', index) }
scope :for_project, -> (project_id) { where(project_id: project_id) }
scope :for_ref, -> (ref) { where(ref: ref) } scope :for_ref, -> (ref) { where(ref: ref) }
scope :by_name, -> (name) { where(name: name) } scope :by_name, -> (name) { where(name: name) }
scope :in_pipelines, ->(pipelines) { where(pipeline: pipelines) } scope :in_pipelines, ->(pipelines) { where(pipeline: pipelines) }
...@@ -68,7 +69,8 @@ class CommitStatus < Ci::ApplicationRecord ...@@ -68,7 +69,8 @@ class CommitStatus < Ci::ApplicationRecord
# Pluck is used to split this query. Splitting the query is required for database decomposition for `ci_*` tables. # Pluck is used to split this query. Splitting the query is required for database decomposition for `ci_*` tables.
# https://docs.gitlab.com/ee/development/database/transaction_guidelines.html#database-decomposition-and-sharding # https://docs.gitlab.com/ee/development/database/transaction_guidelines.html#database-decomposition-and-sharding
project_ids = Project.where_full_path_in(Array(paths)).pluck(:id) project_ids = Project.where_full_path_in(Array(paths)).pluck(:id)
where(project: project_ids)
for_project(project_ids)
end end
scope :with_preloads, -> do scope :with_preloads, -> do
......
...@@ -150,7 +150,7 @@ module Projects ...@@ -150,7 +150,7 @@ module Projects
::Ci::DestroyPipelineService.new(project, current_user).execute(pipeline) ::Ci::DestroyPipelineService.new(project, current_user).execute(pipeline)
end end
deleted_count = project.commit_statuses.delete_all deleted_count = ::CommitStatus.for_project(project).delete_all
Gitlab::AppLogger.info( Gitlab::AppLogger.info(
class: 'Projects::DestroyService', class: 'Projects::DestroyService',
......
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