Commit eff9c876 authored by Patrick Bair's avatar Patrick Bair

Merge branch 'setup-lfk-for-tracked-tables' into 'master'

Setup leftover loose foreign key tracked tables

See merge request gitlab-org/gitlab!76842
parents 6980b02c 1c719423
......@@ -187,8 +187,8 @@ class User < ApplicationRecord
has_one :abuse_report, dependent: :destroy, foreign_key: :user_id # rubocop:disable Cop/ActiveRecordDependent
has_many :reported_abuse_reports, dependent: :destroy, foreign_key: :reporter_id, class_name: "AbuseReport" # rubocop:disable Cop/ActiveRecordDependent
has_many :spam_logs, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent
has_many :builds, dependent: :nullify, class_name: 'Ci::Build' # rubocop:disable Cop/ActiveRecordDependent
has_many :pipelines, dependent: :nullify, class_name: 'Ci::Pipeline' # rubocop:disable Cop/ActiveRecordDependent
has_many :builds, class_name: 'Ci::Build'
has_many :pipelines, class_name: 'Ci::Pipeline'
has_many :todos
has_many :notification_settings
has_many :award_emoji, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent
......
......@@ -22,6 +22,20 @@ ci_namespace_mirrors:
- table: namespaces
column: namespace_id
on_delete: async_delete
ci_builds:
- table: users
column: user_id
on_delete: async_nullify
ci_pipelines:
- table: merge_requests
column: merge_request_id
on_delete: async_delete
- table: external_pull_requests
column: external_pull_request_id
on_delete: async_nullify
- table: users
column: user_id
on_delete: async_nullify
ci_project_mirrors:
- table: projects
column: project_id
......@@ -49,3 +63,7 @@ merge_request_metrics:
- table: ci_pipelines
column: pipeline_id
on_delete: async_delete
project_pages_metadata:
- table: ci_job_artifacts
column: artifacts_archive_id
on_delete: async_nullify
......@@ -26,9 +26,8 @@ RSpec.describe 'Database schema' do
boards: %w[milestone_id iteration_id],
chat_names: %w[chat_id team_id user_id],
chat_teams: %w[team_id],
ci_builds: %w[erased_by_id runner_id trigger_request_id user_id],
ci_builds: %w[erased_by_id runner_id trigger_request_id],
ci_namespace_monthly_usages: %w[namespace_id],
ci_pipelines: %w[user_id],
ci_runner_projects: %w[runner_id],
ci_trigger_requests: %w[commit_id],
cluster_providers_aws: %w[security_group_id vpc_id access_key_id],
......
......@@ -5421,4 +5421,9 @@ RSpec.describe Ci::Build do
it_behaves_like 'it has loose foreign keys' do
let(:factory_name) { :ci_build }
end
it_behaves_like 'cleanup by a loose foreign key' do
let!(:model) { create(:ci_build, user: create(:user)) }
let!(:parent) { model.user }
end
end
......@@ -700,4 +700,8 @@ RSpec.describe Ci::JobArtifact do
when changes or new entries are made.
MSG
end
it_behaves_like 'it has loose foreign keys' do
let(:factory_name) { :ci_job_artifact }
end
end
......@@ -4672,4 +4672,9 @@ RSpec.describe Ci::Pipeline, :mailer, factory_default: :keep do
it_behaves_like 'it has loose foreign keys' do
let(:factory_name) { :ci_pipeline }
end
it_behaves_like 'cleanup by a loose foreign key' do
let!(:model) { create(:ci_pipeline, user: create(:user)) }
let!(:parent) { model.user }
end
end
......@@ -232,4 +232,8 @@ RSpec.describe ExternalPullRequest do
'with space/README.md']
end
end
it_behaves_like 'it has loose foreign keys' do
let(:factory_name) { :external_pull_request }
end
end
......@@ -5042,4 +5042,8 @@ RSpec.describe MergeRequest, factory_default: :keep do
expect(described_class.from_fork).to eq([fork_mr])
end
end
it_behaves_like 'it has loose foreign keys' do
let(:factory_name) { :merge_request }
end
end
......@@ -110,8 +110,8 @@ RSpec.describe User do
it { is_expected.to have_many(:spam_logs).dependent(:destroy) }
it { is_expected.to have_many(:todos) }
it { is_expected.to have_many(:award_emoji).dependent(:destroy) }
it { is_expected.to have_many(:builds).dependent(:nullify) }
it { is_expected.to have_many(:pipelines).dependent(:nullify) }
it { is_expected.to have_many(:builds) }
it { is_expected.to have_many(:pipelines) }
it { is_expected.to have_many(:chat_names).dependent(:destroy) }
it { is_expected.to have_many(:uploads) }
it { is_expected.to have_many(:reported_abuse_reports).dependent(:destroy).class_name('AbuseReport') }
......@@ -6329,4 +6329,8 @@ RSpec.describe User do
expect(user.user_readme).to be(nil)
end
end
it_behaves_like 'it has loose foreign keys' do
let(:factory_name) { :user }
end
end
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