diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-20 02:18:09 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-20 02:18:09 +0300 |
commit | 6ed4ec3e0b1340f96b7c043ef51d1b33bbe85fde (patch) | |
tree | dc4d20fe6064752c0bd323187252c77e0a89144b /spec/lib/gitlab/database/partitioning_migration_helpers/index_helpers_spec.rb | |
parent | 9868dae7fc0655bd7ce4a6887d4e6d487690eeed (diff) |
Add latest changes from gitlab-org/gitlab@15-4-stable-eev15.4.0-rc42
Diffstat (limited to 'spec/lib/gitlab/database/partitioning_migration_helpers/index_helpers_spec.rb')
-rw-r--r-- | spec/lib/gitlab/database/partitioning_migration_helpers/index_helpers_spec.rb | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/spec/lib/gitlab/database/partitioning_migration_helpers/index_helpers_spec.rb b/spec/lib/gitlab/database/partitioning_migration_helpers/index_helpers_spec.rb index edb8ae36c45..7465f69b87c 100644 --- a/spec/lib/gitlab/database/partitioning_migration_helpers/index_helpers_spec.rb +++ b/spec/lib/gitlab/database/partitioning_migration_helpers/index_helpers_spec.rb @@ -26,6 +26,7 @@ RSpec.describe Gitlab::Database::PartitioningMigrationHelpers::IndexHelpers do CREATE TABLE #{table_name} ( id serial NOT NULL, created_at timestamptz NOT NULL, + updated_at timestamptz NOT NULL, PRIMARY KEY (id, created_at) ) PARTITION BY RANGE (created_at); @@ -204,4 +205,30 @@ RSpec.describe Gitlab::Database::PartitioningMigrationHelpers::IndexHelpers do end end end + + describe '#find_duplicate_indexes' do + context 'when duplicate and non-duplicate indexes exist' do + let(:nonduplicate_column_name) { 'updated_at' } + let(:nonduplicate_index_name) { 'updated_at_idx' } + let(:duplicate_column_name) { 'created_at' } + let(:duplicate_index_name1) { 'created_at_idx' } + let(:duplicate_index_name2) { 'index_on_created_at' } + + before do + connection.execute(<<~SQL) + CREATE INDEX #{nonduplicate_index_name} ON #{table_name} (#{nonduplicate_column_name}); + CREATE INDEX #{duplicate_index_name1} ON #{table_name} (#{duplicate_column_name}); + CREATE INDEX #{duplicate_index_name2} ON #{table_name} (#{duplicate_column_name}); + SQL + end + + subject do + migration.find_duplicate_indexes(table_name) + end + + it 'finds the duplicate index' do + expect(subject).to match_array([match_array([duplicate_index_name1, duplicate_index_name2])]) + end + end + end end |