Commit 5d9c29e0 authored by Thong Kuah's avatar Thong Kuah

Merge branch '342795-use-yaml-file-to-define-gitlab_schema' into 'master'

Use a YAML file to define gitlab_schema for tables

See merge request gitlab-org/gitlab!72353
parents 24b5a5d4 a5748ec5
# frozen_string_literal: true
class ApplicationRecord < ActiveRecord::Base
self.gitlab_schema = :gitlab_main
self.abstract_class = true
alias_method :reset, :reload
......
......@@ -2,7 +2,6 @@
module Ci
class ApplicationRecord < ::ApplicationRecord
self.gitlab_schema = :gitlab_ci
self.abstract_class = true
def self.table_name_prefix
......
......@@ -69,7 +69,7 @@ module LooseForeignKey
end
on_delete_options = %i[async_delete async_nullify]
gitlab_schema_options = [ApplicationRecord.gitlab_schema, Ci::ApplicationRecord.gitlab_schema]
gitlab_schema_options = %i(gitlab_main gitlab_ci)
unless on_delete_options.include?(symbolized_options[:on_delete]&.to_sym)
raise "Invalid on_delete option given: #{symbolized_options[:on_delete]}. Valid options: #{on_delete_options.join(', ')}"
......
# frozen_string_literal: true
# This parameter describes a virtual context to indicate
# table affinity to other tables.
#
# Table affinity limits cross-joins, cross-modifications,
# foreign keys and validates relationship between tables
#
# By default it is undefined
ActiveRecord::Base.class_attribute :gitlab_schema, default: nil
......@@ -13,7 +13,3 @@ raise "Counter cache is not disabled" if
ActsAsTaggableOn::Tagging.include IgnorableColumns
ActsAsTaggableOn::Tagging.ignore_column :id_convert_to_bigint, remove_with: '14.5', remove_after: '2021-10-22'
ActsAsTaggableOn::Tagging.ignore_column :taggable_id_convert_to_bigint, remove_with: '14.5', remove_after: '2021-10-22'
# The tags and taggings are supposed to be part of `gitlab_ci`
ActsAsTaggableOn::Tag.gitlab_schema = :gitlab_ci
ActsAsTaggableOn::Tagging.gitlab_schema = :gitlab_ci
......@@ -20,7 +20,6 @@ class AssociateExistingDastBuildsWithVariables < ActiveRecord::Migration[6.1]
class Build < ApplicationRecord
self.table_name = 'ci_builds'
self.inheritance_column = :_type_disabled
self.gitlab_schema = :gitlab_ci
default_scope { where(name: :dast, stage: :dast) } # rubocop:disable Cop/DefaultScope
end
......
......@@ -30,6 +30,7 @@
- "./spec/lib/gitlab/background_migration/migrate_pages_metadata_spec.rb"
- "./spec/migrations/20210907211557_finalize_ci_builds_bigint_conversion_spec.rb"
- "./spec/migrations/associate_existing_dast_builds_with_variables_spec.rb"
- "./spec/migrations/disable_job_token_scope_when_unused_spec.rb"
- "./spec/migrations/schedule_copy_ci_builds_columns_to_security_scans2_spec.rb"
- "./spec/migrations/schedule_pages_metadata_migration_spec.rb"
- "./spec/models/ci/pipeline_spec.rb"
......
......@@ -9,17 +9,12 @@ module Database
end
def self.table_schema(name)
tables_to_schema[name] || :undefined
# When undefined it's best to return a unique name so that we don't incorrectly assume that 2 undefined schemas belong on the same database
tables_to_schema[name] || :"undefined_#{name}"
end
def self.tables_to_schema
@tables_to_schema ||= all_classes_with_schema.to_h do |klass|
[klass.table_name, klass.gitlab_schema]
end
end
def self.all_classes_with_schema
ActiveRecord::Base.descendants.reject(&:abstract_class?).select(&:gitlab_schema?) # rubocop:disable Database/MultipleDatabases
@tables_to_schema ||= YAML.load_file(Rails.root.join('spec/support/database/gitlab_schemas.yml'))
end
end
end
abuse_reports: :gitlab_main
agent_group_authorizations: :gitlab_main
agent_project_authorizations: :gitlab_main
alert_management_alert_assignees: :gitlab_main
alert_management_alerts: :gitlab_main
alert_management_alert_user_mentions: :gitlab_main
alert_management_http_integrations: :gitlab_main
allowed_email_domains: :gitlab_main
analytics_cycle_analytics_group_stages: :gitlab_main
analytics_cycle_analytics_group_value_streams: :gitlab_main
analytics_cycle_analytics_issue_stage_events: :gitlab_main
analytics_cycle_analytics_merge_request_stage_events: :gitlab_main
analytics_cycle_analytics_project_stages: :gitlab_main
analytics_cycle_analytics_project_value_streams: :gitlab_main
analytics_cycle_analytics_stage_event_hashes: :gitlab_main
analytics_devops_adoption_segments: :gitlab_main
analytics_devops_adoption_snapshots: :gitlab_main
analytics_language_trend_repository_languages: :gitlab_main
analytics_usage_trends_measurements: :gitlab_main
appearances: :gitlab_main
application_settings: :gitlab_main
application_setting_terms: :gitlab_main
approval_merge_request_rules_approved_approvers: :gitlab_main
approval_merge_request_rules: :gitlab_main
approval_merge_request_rules_groups: :gitlab_main
approval_merge_request_rule_sources: :gitlab_main
approval_merge_request_rules_users: :gitlab_main
approval_project_rules: :gitlab_main
approval_project_rules_groups: :gitlab_main
approval_project_rules_protected_branches: :gitlab_main
approval_project_rules_users: :gitlab_main
approvals: :gitlab_main
approver_groups: :gitlab_main
approvers: :gitlab_main
atlassian_identities: :gitlab_main
audit_events_external_audit_event_destinations: :gitlab_main
audit_events: :gitlab_main
authentication_events: :gitlab_main
award_emoji: :gitlab_main
aws_roles: :gitlab_main
background_migration_jobs: :gitlab_main
badges: :gitlab_main
banned_users: :gitlab_main
batched_background_migration_jobs: :gitlab_main
batched_background_migrations: :gitlab_main
board_assignees: :gitlab_main
board_group_recent_visits: :gitlab_main
board_labels: :gitlab_main
board_project_recent_visits: :gitlab_main
boards_epic_board_labels: :gitlab_main
boards_epic_board_positions: :gitlab_main
boards_epic_board_recent_visits: :gitlab_main
boards_epic_boards: :gitlab_main
boards_epic_lists: :gitlab_main
boards_epic_list_user_preferences: :gitlab_main
boards_epic_user_preferences: :gitlab_main
boards: :gitlab_main
board_user_preferences: :gitlab_main
broadcast_messages: :gitlab_main
bulk_import_configurations: :gitlab_main
bulk_import_entities: :gitlab_main
bulk_import_exports: :gitlab_main
bulk_import_export_uploads: :gitlab_main
bulk_import_failures: :gitlab_main
bulk_imports: :gitlab_main
bulk_import_trackers: :gitlab_main
chat_names: :gitlab_main
chat_teams: :gitlab_main
ci_build_needs: :gitlab_ci
ci_build_pending_states: :gitlab_ci
ci_build_report_results: :gitlab_ci
ci_builds: :gitlab_ci
ci_builds_metadata: :gitlab_ci
ci_builds_runner_session: :gitlab_ci
ci_build_trace_chunks: :gitlab_ci
ci_build_trace_metadata: :gitlab_ci
ci_daily_build_group_report_results: :gitlab_ci
ci_deleted_objects: :gitlab_ci
ci_freeze_periods: :gitlab_ci
ci_group_variables: :gitlab_ci
ci_instance_variables: :gitlab_ci
ci_job_artifacts: :gitlab_ci
ci_job_token_project_scope_links: :gitlab_ci
ci_job_variables: :gitlab_ci
ci_minutes_additional_packs: :gitlab_ci
ci_namespace_monthly_usages: :gitlab_ci
ci_pending_builds: :gitlab_ci
ci_pipeline_artifacts: :gitlab_ci
ci_pipeline_chat_data: :gitlab_ci
ci_pipeline_messages: :gitlab_ci
ci_pipeline_schedules: :gitlab_ci
ci_pipeline_schedule_variables: :gitlab_ci
ci_pipelines_config: :gitlab_ci
ci_pipelines: :gitlab_ci
ci_pipeline_variables: :gitlab_ci
ci_platform_metrics: :gitlab_ci
ci_project_monthly_usages: :gitlab_ci
ci_refs: :gitlab_ci
ci_resource_groups: :gitlab_ci
ci_resources: :gitlab_ci
ci_runner_namespaces: :gitlab_ci
ci_runner_projects: :gitlab_ci
ci_runners: :gitlab_ci
ci_running_builds: :gitlab_ci
ci_sources_pipelines: :gitlab_ci
ci_sources_projects: :gitlab_ci
ci_stages: :gitlab_ci
ci_subscriptions_projects: :gitlab_ci
ci_trigger_requests: :gitlab_ci
ci_triggers: :gitlab_ci
ci_unit_test_failures: :gitlab_ci
ci_unit_tests: :gitlab_ci
ci_variables: :gitlab_ci
cluster_agents: :gitlab_main
cluster_agent_tokens: :gitlab_main
cluster_groups: :gitlab_main
cluster_platforms_kubernetes: :gitlab_main
cluster_projects: :gitlab_main
cluster_providers_aws: :gitlab_main
cluster_providers_gcp: :gitlab_main
clusters_applications_cert_managers: :gitlab_main
clusters_applications_cilium: :gitlab_main
clusters_applications_crossplane: :gitlab_main
clusters_applications_elastic_stacks: :gitlab_main
clusters_applications_helm: :gitlab_main
clusters_applications_ingress: :gitlab_main
clusters_applications_jupyter: :gitlab_main
clusters_applications_knative: :gitlab_main
clusters_applications_prometheus: :gitlab_main
clusters_applications_runners: :gitlab_main
clusters: :gitlab_main
clusters_integration_elasticstack: :gitlab_main
clusters_integration_prometheus: :gitlab_main
clusters_kubernetes_namespaces: :gitlab_main
commit_user_mentions: :gitlab_main
compliance_management_frameworks: :gitlab_main
container_expiration_policies: :gitlab_main
container_repositories: :gitlab_main
conversational_development_index_metrics: :gitlab_main
coverage_fuzzing_corpuses: :gitlab_main
csv_issue_imports: :gitlab_main
custom_emoji: :gitlab_main
customer_relations_contacts: :gitlab_main
customer_relations_organizations: :gitlab_main
dast_profile_schedules: :gitlab_main
dast_profiles: :gitlab_main
dast_profiles_pipelines: :gitlab_main
dast_scanner_profiles_builds: :gitlab_main
dast_scanner_profiles: :gitlab_main
dast_site_profiles_builds: :gitlab_main
dast_site_profile_secret_variables: :gitlab_main
dast_site_profiles: :gitlab_main
dast_site_profiles_pipelines: :gitlab_main
dast_sites: :gitlab_main
dast_site_tokens: :gitlab_main
dast_site_validations: :gitlab_main
dep_ci_build_trace_section_names: :gitlab_main
dep_ci_build_trace_sections: :gitlab_main
dependency_proxy_blobs: :gitlab_main
dependency_proxy_group_settings: :gitlab_main
dependency_proxy_image_ttl_group_policies: :gitlab_main
dependency_proxy_manifests: :gitlab_main
deploy_keys_projects: :gitlab_main
deployment_clusters: :gitlab_main
deployment_merge_requests: :gitlab_main
deployments: :gitlab_main
deploy_tokens: :gitlab_main
description_versions: :gitlab_main
design_management_designs: :gitlab_main
design_management_designs_versions: :gitlab_main
design_management_versions: :gitlab_main
design_user_mentions: :gitlab_main
detached_partitions: :gitlab_main
diff_note_positions: :gitlab_main
dora_daily_metrics: :gitlab_main
draft_notes: :gitlab_main
elastic_index_settings: :gitlab_main
elastic_reindexing_slices: :gitlab_main
elastic_reindexing_subtasks: :gitlab_main
elastic_reindexing_tasks: :gitlab_main
elasticsearch_indexed_namespaces: :gitlab_main
elasticsearch_indexed_projects: :gitlab_main
emails: :gitlab_main
environments: :gitlab_main
epic_issues: :gitlab_main
epic_metrics: :gitlab_main
epics: :gitlab_main
epic_user_mentions: :gitlab_main
error_tracking_client_keys: :gitlab_main
error_tracking_error_events: :gitlab_main
error_tracking_errors: :gitlab_main
events: :gitlab_main
evidences: :gitlab_main
experiments: :gitlab_main
experiment_subjects: :gitlab_main
experiment_users: :gitlab_main
external_approval_rules: :gitlab_main
external_approval_rules_protected_branches: :gitlab_main
external_pull_requests: :gitlab_main
external_status_checks: :gitlab_main
external_status_checks_protected_branches: :gitlab_main
feature_gates: :gitlab_main
features: :gitlab_main
fork_network_members: :gitlab_main
fork_networks: :gitlab_main
geo_cache_invalidation_events: :gitlab_main
geo_container_repository_updated_events: :gitlab_main
geo_event_log: :gitlab_main
geo_events: :gitlab_main
geo_hashed_storage_attachments_events: :gitlab_main
geo_hashed_storage_migrated_events: :gitlab_main
geo_job_artifact_deleted_events: :gitlab_main
geo_lfs_object_deleted_events: :gitlab_main
geo_node_namespace_links: :gitlab_main
geo_nodes: :gitlab_main
geo_node_statuses: :gitlab_main
geo_repositories_changed_events: :gitlab_main
geo_repository_created_events: :gitlab_main
geo_repository_deleted_events: :gitlab_main
geo_repository_renamed_events: :gitlab_main
geo_repository_updated_events: :gitlab_main
geo_reset_checksum_events: :gitlab_main
geo_upload_deleted_events: :gitlab_main
gitlab_subscription_histories: :gitlab_main
gitlab_subscriptions: :gitlab_main
gpg_keys: :gitlab_main
gpg_key_subkeys: :gitlab_main
gpg_signatures: :gitlab_main
grafana_integrations: :gitlab_main
group_custom_attributes: :gitlab_main
group_deletion_schedules: :gitlab_main
group_deploy_keys: :gitlab_main
group_deploy_keys_groups: :gitlab_main
group_deploy_tokens: :gitlab_main
group_group_links: :gitlab_main
group_import_states: :gitlab_main
group_merge_request_approval_settings: :gitlab_main
group_repository_storage_moves: :gitlab_main
group_wiki_repositories: :gitlab_main
historical_data: :gitlab_main
identities: :gitlab_main
import_export_uploads: :gitlab_main
import_failures: :gitlab_main
incident_management_escalation_policies: :gitlab_main
incident_management_escalation_rules: :gitlab_main
incident_management_issuable_escalation_statuses: :gitlab_main
incident_management_oncall_participants: :gitlab_main
incident_management_oncall_rotations: :gitlab_main
incident_management_oncall_schedules: :gitlab_main
incident_management_oncall_shifts: :gitlab_main
incident_management_pending_alert_escalations: :gitlab_main
incident_management_pending_issue_escalations: :gitlab_main
index_statuses: :gitlab_main
in_product_marketing_emails: :gitlab_main
insights: :gitlab_main
integrations: :gitlab_main
internal_ids: :gitlab_main
ip_restrictions: :gitlab_main
issuable_metric_images: :gitlab_main
issuable_severities: :gitlab_main
issuable_slas: :gitlab_main
issue_assignees: :gitlab_main
issue_customer_relations_contacts: :gitlab_main
issue_email_participants: :gitlab_main
issue_links: :gitlab_main
issue_metrics: :gitlab_main
issues: :gitlab_main
issues_prometheus_alert_events: :gitlab_main
issues_self_managed_prometheus_alert_events: :gitlab_main
issue_tracker_data: :gitlab_main
issue_user_mentions: :gitlab_main
iterations_cadences: :gitlab_main
jira_connect_installations: :gitlab_main
jira_connect_subscriptions: :gitlab_main
jira_imports: :gitlab_main
jira_tracker_data: :gitlab_main
keys: :gitlab_main
label_links: :gitlab_main
label_priorities: :gitlab_main
labels: :gitlab_main
ldap_group_links: :gitlab_main
lfs_file_locks: :gitlab_main
lfs_objects: :gitlab_main
lfs_objects_projects: :gitlab_main
licenses: :gitlab_main
lists: :gitlab_main
list_user_preferences: :gitlab_main
loose_foreign_keys_deleted_records: :gitlab_main
members: :gitlab_main
merge_request_assignees: :gitlab_main
merge_request_blocks: :gitlab_main
merge_request_cleanup_schedules: :gitlab_main
merge_request_context_commit_diff_files: :gitlab_main
merge_request_context_commits: :gitlab_main
merge_request_diff_commits: :gitlab_main
merge_request_diff_commit_users: :gitlab_main
merge_request_diff_details: :gitlab_main
merge_request_diff_files: :gitlab_main
merge_request_diffs: :gitlab_main
merge_request_metrics: :gitlab_main
merge_request_reviewers: :gitlab_main
merge_requests_closing_issues: :gitlab_main
merge_requests: :gitlab_main
merge_request_user_mentions: :gitlab_main
merge_trains: :gitlab_main
metrics_dashboard_annotations: :gitlab_main
metrics_users_starred_dashboards: :gitlab_main
milestone_releases: :gitlab_main
milestones: :gitlab_main
namespace_admin_notes: :gitlab_main
namespace_aggregation_schedules: :gitlab_main
namespace_limits: :gitlab_main
namespace_package_settings: :gitlab_main
namespace_root_storage_statistics: :gitlab_main
namespace_settings: :gitlab_main
namespaces: :gitlab_main
namespace_statistics: :gitlab_main
note_diff_files: :gitlab_main
notes: :gitlab_main
notification_settings: :gitlab_main
oauth_access_grants: :gitlab_main
oauth_access_tokens: :gitlab_main
oauth_applications: :gitlab_main
oauth_openid_requests: :gitlab_main
onboarding_progresses: :gitlab_main
open_project_tracker_data: :gitlab_main
operations_feature_flags_clients: :gitlab_main
operations_feature_flag_scopes: :gitlab_main
operations_feature_flags: :gitlab_main
operations_feature_flags_issues: :gitlab_main
operations_scopes: :gitlab_main
operations_strategies: :gitlab_main
operations_strategies_user_lists: :gitlab_main
operations_user_lists: :gitlab_main
packages_build_infos: :gitlab_main
packages_composer_cache_files: :gitlab_main
packages_composer_metadata: :gitlab_main
packages_conan_file_metadata: :gitlab_main
packages_conan_metadata: :gitlab_main
packages_debian_file_metadata: :gitlab_main
packages_debian_group_architectures: :gitlab_main
packages_debian_group_component_files: :gitlab_main
packages_debian_group_components: :gitlab_main
packages_debian_group_distribution_keys: :gitlab_main
packages_debian_group_distributions: :gitlab_main
packages_debian_project_architectures: :gitlab_main
packages_debian_project_component_files: :gitlab_main
packages_debian_project_components: :gitlab_main
packages_debian_project_distribution_keys: :gitlab_main
packages_debian_project_distributions: :gitlab_main
packages_debian_publications: :gitlab_main
packages_dependencies: :gitlab_main
packages_dependency_links: :gitlab_main
packages_events: :gitlab_main
packages_helm_file_metadata: :gitlab_main
packages_maven_metadata: :gitlab_main
packages_nuget_dependency_link_metadata: :gitlab_main
packages_nuget_metadata: :gitlab_main
packages_package_file_build_infos: :gitlab_main
packages_package_files: :gitlab_main
packages_packages: :gitlab_main
packages_pypi_metadata: :gitlab_main
packages_rubygems_metadata: :gitlab_main
packages_tags: :gitlab_main
pages_deployments: :gitlab_main
pages_domain_acme_orders: :gitlab_main
pages_domains: :gitlab_main
partitioned_foreign_keys: :gitlab_main
path_locks: :gitlab_main
personal_access_tokens: :gitlab_main
plan_limits: :gitlab_main
plans: :gitlab_main
pool_repositories: :gitlab_main
postgres_async_indexes: :gitlab_main
postgres_reindex_actions: :gitlab_main
product_analytics_events_experimental: :gitlab_main
programming_languages: :gitlab_main
project_access_tokens: :gitlab_main
project_alerting_settings: :gitlab_main
project_aliases: :gitlab_main
project_authorizations: :gitlab_main
project_auto_devops: :gitlab_main
project_ci_cd_settings: :gitlab_main
project_ci_feature_usages: :gitlab_main
project_compliance_framework_settings: :gitlab_main
project_custom_attributes: :gitlab_main
project_daily_statistics: :gitlab_main
project_deploy_tokens: :gitlab_main
project_error_tracking_settings: :gitlab_main
project_export_jobs: :gitlab_main
project_features: :gitlab_main
project_feature_usages: :gitlab_main
project_group_links: :gitlab_main
project_import_data: :gitlab_main
project_incident_management_settings: :gitlab_main
project_metrics_settings: :gitlab_main
project_mirror_data: :gitlab_main
project_pages_metadata: :gitlab_main
project_repositories: :gitlab_main
project_repository_states: :gitlab_main
project_repository_storage_moves: :gitlab_main
project_security_settings: :gitlab_main
project_settings: :gitlab_main
projects: :gitlab_main
project_statistics: :gitlab_main
project_topics: :gitlab_main
project_tracing_settings: :gitlab_main
prometheus_alert_events: :gitlab_main
prometheus_alerts: :gitlab_main
prometheus_metrics: :gitlab_main
protected_branches: :gitlab_main
protected_branch_merge_access_levels: :gitlab_main
protected_branch_push_access_levels: :gitlab_main
protected_branch_unprotect_access_levels: :gitlab_main
protected_environment_deploy_access_levels: :gitlab_main
protected_environments: :gitlab_main
protected_tag_create_access_levels: :gitlab_main
protected_tags: :gitlab_main
push_event_payloads: :gitlab_main
push_rules: :gitlab_main
raw_usage_data: :gitlab_main
redirect_routes: :gitlab_main
release_links: :gitlab_main
releases: :gitlab_main
remote_mirrors: :gitlab_main
repository_languages: :gitlab_main
required_code_owners_sections: :gitlab_main
requirements: :gitlab_main
requirements_management_test_reports: :gitlab_main
resource_iteration_events: :gitlab_main
resource_label_events: :gitlab_main
resource_milestone_events: :gitlab_main
resource_state_events: :gitlab_main
resource_weight_events: :gitlab_main
reviews: :gitlab_main
routes: :gitlab_main
saml_group_links: :gitlab_main
saml_providers: :gitlab_main
scim_identities: :gitlab_main
scim_oauth_access_tokens: :gitlab_main
security_findings: :gitlab_main
security_orchestration_policy_configurations: :gitlab_main
security_orchestration_policy_rule_schedules: :gitlab_main
security_scans: :gitlab_main
self_managed_prometheus_alert_events: :gitlab_main
sent_notifications: :gitlab_main
sentry_issues: :gitlab_main
serverless_domain_cluster: :gitlab_main
service_desk_settings: :gitlab_main
shards: :gitlab_main
slack_integrations: :gitlab_main
smartcard_identities: :gitlab_main
snippet_repositories: :gitlab_main
snippet_repository_storage_moves: :gitlab_main
snippets: :gitlab_main
snippet_statistics: :gitlab_main
snippet_user_mentions: :gitlab_main
software_license_policies: :gitlab_main
software_licenses: :gitlab_main
spam_logs: :gitlab_main
sprints: :gitlab_main
status_check_responses: :gitlab_main
status_page_published_incidents: :gitlab_main
status_page_settings: :gitlab_main
subscriptions: :gitlab_main
suggestions: :gitlab_main
system_note_metadata: :gitlab_main
taggings: :gitlab_ci
tags: :gitlab_ci
term_agreements: :gitlab_main
terraform_states: :gitlab_main
terraform_state_versions: :gitlab_main
timelogs: :gitlab_main
todos: :gitlab_main
token_with_ivs: :gitlab_main
topics: :gitlab_main
trending_projects: :gitlab_main
u2f_registrations: :gitlab_main
upcoming_reconciliations: :gitlab_main
uploads: :gitlab_main
user_agent_details: :gitlab_main
user_callouts: :gitlab_main
user_canonical_emails: :gitlab_main
user_credit_card_validations: :gitlab_main
user_custom_attributes: :gitlab_main
user_details: :gitlab_main
user_follow_users: :gitlab_main
user_group_callouts: :gitlab_main
user_highest_roles: :gitlab_main
user_interacted_projects: :gitlab_main
user_permission_export_uploads: :gitlab_main
user_preferences: :gitlab_main
users: :gitlab_main
users_ops_dashboard_projects: :gitlab_main
users_security_dashboard_projects: :gitlab_main
users_star_projects: :gitlab_main
users_statistics: :gitlab_main
user_statuses: :gitlab_main
user_synced_attributes_metadata: :gitlab_main
verification_codes: :gitlab_main
vulnerabilities: :gitlab_main
vulnerability_exports: :gitlab_main
vulnerability_external_issue_links: :gitlab_main
vulnerability_feedback: :gitlab_main
vulnerability_finding_evidence_assets: :gitlab_main
vulnerability_finding_evidence_headers: :gitlab_main
vulnerability_finding_evidence_requests: :gitlab_main
vulnerability_finding_evidence_responses: :gitlab_main
vulnerability_finding_evidences: :gitlab_main
vulnerability_finding_evidence_sources: :gitlab_main
vulnerability_finding_evidence_supporting_messages: :gitlab_main
vulnerability_finding_links: :gitlab_main
vulnerability_finding_signatures: :gitlab_main
vulnerability_findings_remediations: :gitlab_main
vulnerability_flags: :gitlab_main
vulnerability_historical_statistics: :gitlab_main
vulnerability_identifiers: :gitlab_main
vulnerability_issue_links: :gitlab_main
vulnerability_occurrence_identifiers: :gitlab_main
vulnerability_occurrence_pipelines: :gitlab_main
vulnerability_occurrences: :gitlab_main
vulnerability_remediations: :gitlab_main
vulnerability_scanners: :gitlab_main
vulnerability_statistics: :gitlab_main
vulnerability_user_mentions: :gitlab_main
webauthn_registrations: :gitlab_main
web_hook_logs: :gitlab_main
web_hooks: :gitlab_main
wiki_page_meta: :gitlab_main
wiki_page_slugs: :gitlab_main
work_item_types: :gitlab_main
x509_certificates: :gitlab_main
x509_commit_signatures: :gitlab_main
x509_issuers: :gitlab_main
zentao_tracker_data: :gitlab_main
zoom_meetings: :gitlab_main
......@@ -91,6 +91,11 @@ module Database
return if tables.empty?
# All migrations will write to schema_migrations in the same transaction.
# It's safe to ignore this since schema_migrations exists in all
# databases
return if tables == ['schema_migrations']
cross_database_context[:modified_tables_by_db][database].merge(tables)
all_tables = cross_database_context[:modified_tables_by_db].values.map(&:to_a).flatten
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Database::GitlabSchema do
it 'matches all the tables in the database', :aggregate_failures do
# These tables do not need a gitlab_schema
excluded_tables = %w(ar_internal_metadata schema_migrations)
all_tables_in_database = ApplicationRecord.connection.tables
all_tables_with_gitlab_schema = described_class.tables_to_schema.keys
missing = []
all_tables_in_database.each do |table_in_database|
next if table_in_database.in?(excluded_tables)
missing << table_in_database unless all_tables_with_gitlab_schema.include?(table_in_database)
end
extras = []
all_tables_with_gitlab_schema.each do |table_with_gitlab_schema|
extras << table_with_gitlab_schema unless all_tables_in_database.include?(table_with_gitlab_schema)
end
expect(missing).to be_empty, "Missing table(s) #{missing} not found in #{described_class}.tables_to_schema. Any new tables must be added to spec/support/database/gitlab_schemas.yml ."
expect(extras).to be_empty, "Extra table(s) #{extras} found in #{described_class}.tables_to_schema. Any removed or renamed tables must be removed from spec/support/database/gitlab_schemas.yml ."
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