Commit 60df4112 authored by Kamil Trzciński's avatar Kamil Trzciński

Remove duplicate `ci_pipelines.merge_request_id`

It appears that due to mistake we had a duplicate
definition in `ci_pipelines.merge_request_id`
parent 14c818df
......@@ -94,9 +94,6 @@ ci_pipelines:
- table: users
column: user_id
on_delete: async_nullify
- table: merge_requests
column: merge_request_id
on_delete: async_delete
ci_project_mirrors:
- table: projects
column: project_id
......
......@@ -28,7 +28,11 @@ module Gitlab
end
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
private_class_method :build_definition
......
......@@ -18,6 +18,36 @@ RSpec.describe Gitlab::Database::LooseForeignKeys do
))
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
def base_models_for(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