diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-23 21:08:27 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-23 21:08:27 +0300 |
commit | 3ca896b640def57a58485def308748b2fccbd0bb (patch) | |
tree | 7aead6484759d2a473bf9776aa7d87632f1e105f /spec/migrations/remove_old_async_index_table_name_length_constraint_spec.rb | |
parent | abdb550f6937ce69ec38954f24ef221d07637438 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/migrations/remove_old_async_index_table_name_length_constraint_spec.rb')
-rw-r--r-- | spec/migrations/remove_old_async_index_table_name_length_constraint_spec.rb | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/spec/migrations/remove_old_async_index_table_name_length_constraint_spec.rb b/spec/migrations/remove_old_async_index_table_name_length_constraint_spec.rb new file mode 100644 index 00000000000..fdecf9a663b --- /dev/null +++ b/spec/migrations/remove_old_async_index_table_name_length_constraint_spec.rb @@ -0,0 +1,64 @@ +# frozen_string_literal: true + +require 'spec_helper' +require_migration! + +RSpec.describe RemoveOldAsyncIndexTableNameLengthConstraint, schema: 20230523074248, feature_category: :database do + let(:migration) { described_class.new } + let(:postgres_async_indexes) { table(:postgres_async_indexes) } + let(:old_length) { Gitlab::Database::MigrationHelpers::MAX_IDENTIFIER_NAME_LENGTH } + let(:long_table_name) { "#{'a' * old_length}.#{'b' * old_length}" } + + describe '.up' do + it 'allows inserting longer table names' do + migration.up + + expect do + postgres_async_indexes.create!( + name: 'some_index', + definition: '(id)', + table_name: long_table_name + ) + end.not_to raise_error + end + end + + describe '.down' do + it 'disallows inserting longer table names' do + migration.down + + expect do + postgres_async_indexes.create!( + name: 'some_index', + definition: '(id)', + table_name: long_table_name + ) + end.to raise_error(ActiveRecord::StatementInvalid) + end + + it 'cleans up records with too long table_name' do + migration.up + + # Delete + postgres_async_indexes.create!( + name: 'some_index', + definition: '(id)', + table_name: long_table_name + ) + + # Keep + postgres_async_indexes.create!( + name: 'other_index', + definition: '(id)', + table_name: 'short_name' + ) + + migration.down + + async_indexes = postgres_async_indexes.all + expect(async_indexes.size).to eq(1) + + expect(async_indexes.first.name).to eq('other_index') + end + end +end |