Commit 1a76d420 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch 'update-lfk-yaml' into 'master'

Remove duplicate `ci_pipelines.merge_request_id`

See merge request gitlab-org/gitlab!79220
parents 3957b4e4 60df4112
...@@ -94,9 +94,6 @@ ci_pipelines: ...@@ -94,9 +94,6 @@ ci_pipelines:
- table: users - table: users
column: user_id column: user_id
on_delete: async_nullify on_delete: async_nullify
- table: merge_requests
column: merge_request_id
on_delete: async_delete
ci_project_mirrors: ci_project_mirrors:
- table: projects - table: projects
column: project_id column: project_id
......
...@@ -28,7 +28,11 @@ module Gitlab ...@@ -28,7 +28,11 @@ module Gitlab
end end
def self.loose_foreign_keys_yaml def self.loose_foreign_keys_yaml
@loose_foreign_keys_yaml ||= YAML.load_file(Rails.root.join('lib/gitlab/database/gitlab_loose_foreign_keys.yml')) @loose_foreign_keys_yaml ||= YAML.load_file(self.loose_foreign_keys_yaml_path)
end
def self.loose_foreign_keys_yaml_path
@loose_foreign_keys_yaml_path ||= Rails.root.join('lib/gitlab/database/gitlab_loose_foreign_keys.yml')
end end
private_class_method :build_definition private_class_method :build_definition
......
...@@ -18,6 +18,36 @@ RSpec.describe Gitlab::Database::LooseForeignKeys do ...@@ -18,6 +18,36 @@ RSpec.describe Gitlab::Database::LooseForeignKeys do
)) ))
end end
context 'ensure no duplicates are found' do
it 'does not have duplicate tables defined' do
# since we use hash to detect duplicate hash keys we need to parse YAML document
parsed = YAML.parse_file(described_class.loose_foreign_keys_yaml_path)
expect(parsed).to be_document
expect(parsed.children).to be_one, "YAML has a single document"
# require hash
mapping = parsed.children.first
expect(mapping).to be_mapping, "YAML has a top-level hash"
# find all scalars with names
table_names = mapping.children.select(&:scalar?).map(&:value)
expect(table_names).not_to be_empty, "YAML has a non-zero tables defined"
# expect to not have duplicates
expect(table_names).to contain_exactly(*table_names.uniq)
end
it 'does not have duplicate column definitions' do
# ignore other modifiers
all_definitions = definitions.map do |definition|
{ from_table: definition.from_table, to_table: definition.to_table, column: definition.column }
end
# expect to not have duplicates
expect(all_definitions).to contain_exactly(*all_definitions.uniq)
end
end
describe 'ensuring database integrity' do describe 'ensuring database integrity' do
def base_models_for(table) def base_models_for(table)
parent_table_schema = Gitlab::Database::GitlabSchema.table_schema(table) parent_table_schema = Gitlab::Database::GitlabSchema.table_schema(table)
......
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