Commit c1338006 authored by Rémy Coutable's avatar Rémy Coutable

Extract the EE specific models/associations from spec/lib/gitlab/import_export/all_models.yml

Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent 91b5b23a
---
issues:
- epic_issue
- epic
milestone:
- boards
merge_requests:
- approvals
- approvers
- approver_groups
- approved_by_users
pipelines:
- source_pipeline
- sourced_pipelines
- triggered_by_pipeline
- triggered_pipelines
- chat_data
protected_branches:
- unprotect_access_levels
protected_environments:
- project
- deploy_access_levels
deploy_access_levels:
- protected_environment
- user
- group
merge_access_levels:
- user
- group
push_access_levels:
- user
- group
unprotect_access_levels:
- user
- protected_branch
- group
project:
- gitlab_slack_application_service
- github_service
- protected_environments
- mirror_user
- push_rule
- jenkins_service
- jenkins_deprecated_service
- index_status
- approvers
- pages_domains
- audit_events
- path_locks
- approver_groups
- repository_state
- source_pipelines
- sourced_pipelines
- prometheus_metrics
- vulnerability_feedback
- prometheus_alerts
- software_license_policies
- project_registry
- packages
prometheus_metrics:
- project
- prometheus_alerts
prometheus_alerts:
- project
epic_issues:
- issue
- epic
......@@ -19,8 +19,6 @@ issues:
- metrics
- timelogs
- issue_assignees
- epic_issue
- epic
- closed_by
events:
- author
......@@ -58,7 +56,6 @@ milestone:
- merge_requests
- participants
- events
- boards
snippets:
- author
- project
......@@ -94,13 +91,9 @@ merge_requests:
- merge_requests_closing_issues
- cached_closes_issues
- metrics
- approvals
- approvers
- approver_groups
- timelogs
- head_pipeline
- latest_merge_request_diff
- approved_by_users
merge_request_diff:
- merge_request
- merge_request_diff_commits
......@@ -127,11 +120,6 @@ pipelines:
- artifacts
- pipeline_schedule
- merge_requests
- source_pipeline
- sourced_pipelines
- triggered_by_pipeline
- triggered_pipelines
- chat_data # EE only
pipeline_variables:
- pipeline
stages:
......@@ -178,29 +166,13 @@ protected_branches:
- project
- merge_access_levels
- push_access_levels
- unprotect_access_levels
protected_environments:
- project
- deploy_access_levels
deploy_access_levels:
- protected_environment
- user
- group
protected_tags:
- project
- create_access_levels
merge_access_levels:
- user
- protected_branch
- group
push_access_levels:
- user
- protected_branch
- group
unprotect_access_levels:
- user
- protected_branch
- group
create_access_levels:
- user
- protected_tag
......@@ -230,8 +202,6 @@ project:
- pipelines_email_service
- mattermost_slash_commands_service
- slack_slash_commands_service
- gitlab_slack_application_service
- github_service
- irker_service
- packagist_service
- pivotaltracker_service
......@@ -272,7 +242,6 @@ project:
- snippets
- hooks
- protected_branches
- protected_environments
- protected_tags
- project_members
- users
......@@ -305,26 +274,13 @@ project:
- pages_domains
- authorized_users
- project_authorizations
- mirror_user
- push_rule
- jenkins_service
- jenkins_deprecated_service
- index_status
- approvers
- pages_domains
- audit_events
- remote_mirrors
- path_locks
- approver_groups
- route
- redirect_routes
- statistics
- container_repositories
- uploads
- import_state
- repository_state
- source_pipelines
- sourced_pipelines
- members_and_requesters
- build_trace_section_names
- build_trace_chunks
......@@ -332,7 +288,6 @@ project:
- fork_network_member
- fork_network
- custom_attributes
- prometheus_metrics
- lfs_file_locks
- project_badges
- source_of_merge_requests
......@@ -342,22 +297,12 @@ project:
- settings
- ci_cd_settings
- import_export_upload
- vulnerability_feedback
- prometheus_alerts
- software_license_policies
- repository_languages
- project_registry
- packages
award_emoji:
- awardable
- user
priorities:
- label
prometheus_metrics:
- project
- prometheus_alerts
prometheus_alerts:
- project
timelogs:
- issue
- merge_request
......@@ -367,9 +312,6 @@ push_event_payload:
issue_assignees:
- issue
- assignee
epic_issues:
- issue
- epic
lfs_file_locks:
- user
project_badges:
......
......@@ -16,14 +16,30 @@ describe 'Import/Export model configuration' do
# - User, Author... Models we do not care about for checking models
names.flatten.uniq - %w(milestones labels user author) + ['project']
end
let(:ce_models_yml) { 'spec/lib/gitlab/import_export/all_models.yml' }
let(:ce_models_hash) { YAML.load_file(ce_models_yml) }
let(:ee_models_yml) { 'ee/spec/lib/gitlab/import_export/all_models.yml' }
let(:ee_models_hash) { File.exist?(ee_models_yml) ? YAML.load_file(ee_models_yml) : {} }
let(:all_models_yml) { 'spec/lib/gitlab/import_export/all_models.yml' }
let(:all_models) { YAML.load_file(all_models_yml) }
let(:current_models) { setup_models }
let(:all_models_hash) do
all_models_hash = ce_models_hash.dup
all_models_hash.each do |model, associations|
associations.concat(ee_models_hash[model] || [])
end
ee_models_hash.each do |model, associations|
all_models_hash[model] ||= associations
end
all_models_hash
end
it 'has no new models' do
model_names.each do |model_name|
new_models = Array(current_models[model_name]) - Array(all_models[model_name])
new_models = Array(current_models[model_name]) - Array(all_models_hash[model_name])
expect(new_models).to be_empty, failure_message(model_name.classify, new_models)
end
end
......@@ -31,27 +47,21 @@ describe 'Import/Export model configuration' do
# List of current models between models, in the format of
# {model: [model_2, model3], ...}
def setup_models
all_models_hash = {}
model_names.each do |model_name|
model_class = relation_class_for_name(model_name)
all_models_hash[model_name] = associations_for(model_class) - ['project']
model_names.each_with_object({}) do |model_name, hash|
hash[model_name] = associations_for(relation_class_for_name(model_name)) - ['project']
end
all_models_hash
end
def failure_message(parent_model_name, new_models)
<<-MSG
<<~MSG
New model(s) <#{new_models.join(',')}> have been added, related to #{parent_model_name}, which is exported by
the Import/Export feature.
If you think this model should be included in the export, please add it to IMPORT_EXPORT_CONFIG.
Definitely add it to MODELS_JSON to signal that you've handled this error and to prevent it from showing up in the future.
If you think this model should be included in the export, please add it to `#{Gitlab::ImportExport.config_file}`.
MODELS_JSON: #{File.expand_path(all_models_yml)}
IMPORT_EXPORT_CONFIG: #{Gitlab::ImportExport.config_file}
Definitely add it to `#{File.expand_path(ce_models_yml)}`
#{"or `#{File.expand_path(ee_models_yml)}` if the model/associations are EE-specific\n" if ee_models_hash.any?}
to signal that you've handled this error and to prevent it from showing up in the future.
MSG
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