Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec/db
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-09-20 14:18:08 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-09-20 14:18:08 +0300
commit5afcbe03ead9ada87621888a31a62652b10a7e4f (patch)
tree9918b67a0d0f0bafa6542e839a8be37adf73102d /spec/db
parentc97c0201564848c1f53226fe19d71fdcc472f7d0 (diff)
Add latest changes from gitlab-org/gitlab@16-4-stable-eev16.4.0-rc42
Diffstat (limited to 'spec/db')
-rw-r--r--spec/db/avoid_migration_name_collisions_spec.rb17
-rw-r--r--spec/db/schema_spec.rb51
2 files changed, 61 insertions, 7 deletions
diff --git a/spec/db/avoid_migration_name_collisions_spec.rb b/spec/db/avoid_migration_name_collisions_spec.rb
new file mode 100644
index 00000000000..f5fa3da0c81
--- /dev/null
+++ b/spec/db/avoid_migration_name_collisions_spec.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe 'Avoid Migration Name Collisions', feature_category: :database do
+ subject(:duplicated_migration_class_names) do
+ class_names = migration_files.map { |path| class_name_regex.match(File.read(path))[1] }
+ class_names.select { |class_name| class_names.count(class_name) > 1 }
+ end
+
+ let(:class_name_regex) { /^\s*class\s+:*([A-Z][A-Za-z0-9_]+\S+)/ }
+ let(:migration_files) { Dir['db/migrate/*.rb', 'db/post_migrate/*.rb', 'ee/elastic/migrate/*.rb'] }
+
+ it 'loads all database and search migrations without name collisions' do
+ expect(duplicated_migration_class_names).to be_empty
+ end
+end
diff --git a/spec/db/schema_spec.rb b/spec/db/schema_spec.rb
index 3c99393b14b..cfd6bbf3094 100644
--- a/spec/db/schema_spec.rb
+++ b/spec/db/schema_spec.rb
@@ -42,7 +42,7 @@ RSpec.describe 'Database schema', feature_category: :database do
aws_roles: %w[role_external_id],
boards: %w[milestone_id iteration_id],
broadcast_messages: %w[namespace_id],
- chat_names: %w[chat_id team_id user_id integration_id],
+ chat_names: %w[chat_id team_id user_id],
chat_teams: %w[team_id],
ci_builds: %w[project_id runner_id user_id erased_by_id trigger_request_id partition_id],
ci_namespace_monthly_usages: %w[namespace_id],
@@ -187,6 +187,44 @@ RSpec.describe 'Database schema', feature_category: :database do
expect(ignored_columns).to match_array(ignored_columns - foreign_keys)
end
end
+
+ context 'btree indexes' do
+ it 'only has existing indexes in the ignored duplicate indexes duplicate_indexes.yml' do
+ table_ignored_indexes = (ignored_indexes[table] || {}).to_a.flatten.uniq
+ indexes_by_name = indexes.map(&:name)
+ expect(indexes_by_name).to include(*table_ignored_indexes)
+ end
+
+ it 'does not have any duplicated indexes' do
+ duplicate_indexes = Database::DuplicateIndexes.new(table, indexes).duplicate_indexes
+ expect(duplicate_indexes).to be_an_instance_of Hash
+
+ table_ignored_indexes = ignored_indexes[table] || {}
+
+ # We ignore all the indexes that are explicitly ignored in duplicate_indexes.yml
+ duplicate_indexes.each do |index, matching_indexes|
+ duplicate_indexes[index] = matching_indexes.reject do |matching_index|
+ table_ignored_indexes.fetch(index.name, []).include?(matching_index.name) ||
+ table_ignored_indexes.fetch(matching_index.name, []).include?(index.name)
+ end
+
+ duplicate_indexes.delete(index) if duplicate_indexes[index].empty?
+ end
+
+ if duplicate_indexes.present?
+ btree_index = duplicate_indexes.each_key.first
+ matching_indexes = duplicate_indexes[btree_index]
+
+ error_message = <<~ERROR
+ Duplicate index: #{btree_index.name} with #{matching_indexes.map(&:name)}
+ #{btree_index.name} : #{btree_index.columns.inspect}
+ #{matching_indexes.first.name} : #{matching_indexes.first.columns.inspect}.
+ Consider dropping the indexes #{matching_indexes.map(&:name).join(', ')}
+ ERROR
+ raise error_message
+ end
+ end
+ end
end
end
end
@@ -196,23 +234,18 @@ RSpec.describe 'Database schema', feature_category: :database do
IGNORED_LIMIT_ENUMS = {
'Analytics::CycleAnalytics::Stage' => %w[start_event_identifier end_event_identifier],
'Ci::Bridge' => %w[failure_reason],
- 'Ci::Bridge::Partitioned' => %w[failure_reason],
'Ci::Build' => %w[failure_reason],
- 'Ci::Build::Partitioned' => %w[failure_reason],
'Ci::BuildMetadata' => %w[timeout_source],
'Ci::BuildTraceChunk' => %w[data_store],
'Ci::DailyReportResult' => %w[param_type],
'Ci::JobArtifact' => %w[file_type],
'Ci::Pipeline' => %w[source config_source failure_reason],
'Ci::Processable' => %w[failure_reason],
- 'Ci::Processable::Partitioned' => %w[failure_reason],
'Ci::Runner' => %w[access_level],
'Ci::Stage' => %w[status],
'Clusters::Cluster' => %w[platform_type provider_type],
'CommitStatus' => %w[failure_reason],
- 'CommitStatus::Partitioned' => %w[failure_reason],
'GenericCommitStatus' => %w[failure_reason],
- 'GenericCommitStatus::Partitioned' => %w[failure_reason],
'InternalId' => %w[usage],
'List' => %w[list_type],
'NotificationSetting' => %w[level],
@@ -244,7 +277,6 @@ RSpec.describe 'Database schema', feature_category: :database do
"ApplicationSetting" => %w[repository_storages_weighted],
"AlertManagement::Alert" => %w[payload],
"Ci::BuildMetadata" => %w[config_options config_variables],
- "Ci::BuildMetadata::Partitioned" => %w[config_options config_variables id_tokens runtime_runner_features secrets],
"ExperimentSubject" => %w[context],
"ExperimentUser" => %w[context],
"Geo::Event" => %w[payload],
@@ -409,4 +441,9 @@ RSpec.describe 'Database schema', feature_category: :database do
def ignored_jsonb_columns(model)
IGNORED_JSONB_COLUMNS.fetch(model, [])
end
+
+ def ignored_indexes
+ duplicate_indexes_file_path = "spec/support/helpers/database/duplicate_indexes.yml"
+ @ignored_indexes ||= YAML.load_file(Rails.root.join(duplicate_indexes_file_path)) || {}
+ end
end