diff --git a/.rubocop_todo/rspec/example_wording.yml b/.rubocop_todo/rspec/example_wording.yml index e87933e9e03d4f3d9ad156fab5712a29c9546986..f010e04dd3179d80a8231a8a7c35e3611a507040 100644 --- a/.rubocop_todo/rspec/example_wording.yml +++ b/.rubocop_todo/rspec/example_wording.yml @@ -63,7 +63,6 @@ RSpec/ExampleWording: - 'spec/support/shared_examples/quick_actions/issuable/max_issuable_examples.rb' - 'spec/support/shared_examples/services/migrate_to_ghost_user_service_shared_examples.rb' - 'spec/support/shared_examples/uploaders/upload_type_shared_examples.rb' - - 'spec/tasks/gitlab/db/cells/bump_cell_sequences_rake_spec.rb' - 'spec/tasks/gitlab/db/decomposition/rollback/bump_ci_sequences_rake_spec.rb' - 'spec/tooling/lib/tooling/api/job_spec.rb' - 'spec/uploaders/dependency_proxy/file_uploader_spec.rb' diff --git a/lib/tasks/gitlab/db/cells/bump_cell_sequences.rake b/lib/tasks/gitlab/db/cells/bump_cell_sequences.rake deleted file mode 100644 index 1f02e89b6aa38fbeb18842f059fdfa4bf3e2af20..0000000000000000000000000000000000000000 --- a/lib/tasks/gitlab/db/cells/bump_cell_sequences.rake +++ /dev/null @@ -1,25 +0,0 @@ -# frozen_string_literal: true - -namespace :gitlab do - namespace :db do - namespace :cells do - desc 'Bump sequences for cell-local tables on the cells database' - task :bump_cell_sequences, [:increase_by] => :environment do |_t, args| - # We do not want to run this on production environment, even accidentally. - unless Gitlab.dev_or_test_env? - puts Rainbow('This rake task cannot be run in production environment').red - exit 1 - end - - increase_by = args.increase_by.to_i - if increase_by < 1 - puts Rainbow('Please specify a positive integer `increase_by` value').red - puts Rainbow('Example: rake gitlab:db:cells:bump_cell_sequences[100000]').green - exit 1 - end - - Gitlab::Database::BumpSequences.new(:gitlab_main_cell, increase_by).execute - end - end - end -end diff --git a/spec/tasks/gitlab/db/cells/bump_cell_sequences_rake_spec.rb b/spec/tasks/gitlab/db/cells/bump_cell_sequences_rake_spec.rb deleted file mode 100644 index ff11e4ee8cbea40b21d5440347ed0a439cffdbb6..0000000000000000000000000000000000000000 --- a/spec/tasks/gitlab/db/cells/bump_cell_sequences_rake_spec.rb +++ /dev/null @@ -1,79 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe 'gitlab:db:cells:bump_cell_sequences', :silence_stdout, - :suppress_gitlab_schemas_validate_connection, feature_category: :cell, query_analyzers: false do - before(:all) do - Rake.application.rake_require 'tasks/gitlab/db/cells/bump_cell_sequences' - end - - let(:main_sequence_name) { 'users_id_seq' } - let(:main_cell_sequence_name) { 'namespaces_id_seq' } - - # This is just to make sure that all of the sequences start with `is_called=True` - # which means that the next call to nextval() is going to increment the sequence. - # To give predictable test results. - before do - ApplicationRecord.connection.select_value("select nextval($1)", nil, [main_cell_sequence_name]) - end - - context 'when run in production environment' do - let(:expected_error_message) do - <<~HEREDOC - This rake task cannot be run in production environment - HEREDOC - end - - it 'will print error message and exit' do - allow(Gitlab).to receive(:dev_or_test_env?).and_return(false) - - expect do - run_rake_task('gitlab:db:cells:bump_cell_sequences', '10') - end.to raise_error(SystemExit) { |error| expect(error.status).to eq(1) } - .and output(expected_error_message).to_stdout - end - end - - context 'when passing wrong argument' do - let(:expected_error_message) do - <<~HEREDOC - Please specify a positive integer `increase_by` value - Example: rake gitlab:db:cells:bump_cell_sequences[100000] - HEREDOC - end - - it 'will print an error message and exit when passing no argument' do - expect do - run_rake_task('gitlab:db:cells:bump_cell_sequences') - end.to raise_error(SystemExit) { |error| expect(error.status).to eq(1) } - .and output(expected_error_message).to_stdout - end - - it 'will print an error message and exit when passing a non positive integer value' do - expect do - run_rake_task('gitlab:db:cells:bump_cell_sequences', '-5') - end.to raise_error(SystemExit) { |error| expect(error.status).to eq(1) } - .and output(expected_error_message).to_stdout - end - end - - context 'when bumping the sequences' do - it 'increments the sequence of the tables in the given schema, but not in other schemas' do - expect do - run_rake_task('gitlab:db:cells:bump_cell_sequences', '10') - end.to change { - last_value_of_sequence(ApplicationRecord.connection, main_sequence_name) - }.by(0) - .and change { - last_value_of_sequence(ApplicationRecord.connection, main_cell_sequence_name) - }.by(11) # the +1 is because the sequence has is_called = true - end - end -end - -def last_value_of_sequence(connection, sequence_name) - allow_cross_joins_across_databases(url: 'https://gitlab.com/gitlab-org/gitlab/-/issues/408220') do - connection.select_value("select last_value from #{sequence_name}") - end -end