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
diff options
context:
space:
mode:
Diffstat (limited to 'spec/migrations')
-rw-r--r--spec/migrations/20221002234454_finalize_group_member_namespace_id_migration_spec.rb76
-rw-r--r--spec/migrations/20221018050323_add_objective_and_keyresult_to_work_item_types_spec.rb73
-rw-r--r--spec/migrations/20221018062308_schedule_backfill_project_namespace_details_spec.rb37
-rw-r--r--spec/migrations/20221018193635_ensure_task_note_renaming_background_migration_finished_spec.rb95
-rw-r--r--spec/migrations/20221021145820_create_routing_table_for_builds_metadata_v2_spec.rb36
-rw-r--r--spec/migrations/20221025043930_change_default_value_on_password_last_changed_at_to_user_details_spec.rb37
-rw-r--r--spec/migrations/20221028022627_add_index_on_password_last_changed_at_to_user_details_spec.rb16
-rw-r--r--spec/migrations/20221101032521_add_default_preferred_language_to_application_settings_spec.rb27
-rw-r--r--spec/migrations/20221101032600_add_text_limit_to_default_preferred_language_on_application_settings_spec.rb29
-rw-r--r--spec/migrations/20221102090940_create_next_ci_partitions_record_spec.rb63
-rw-r--r--spec/migrations/20221102090943_create_second_partition_for_builds_metadata_spec.rb61
-rw-r--r--spec/migrations/20230802085923_queue_fix_allow_descendants_override_disabled_shared_runners_spec.rb2
-rw-r--r--spec/migrations/20231107092912_queue_backfill_branch_protection_namespace_setting_spec.rb26
-rw-r--r--spec/migrations/20231115025547_queue_backfill_merge_request_diffs_project_id_spec.rb (renamed from spec/migrations/20231001105945_requeue_backfill_finding_id_in_vulnerabilities_spec.rb)4
-rw-r--r--spec/migrations/20231129105945_requeue_backfill_finding_id_in_vulnerabilities3_spec.rb (renamed from spec/migrations/20230912105945_queue_backfill_finding_id_in_vulnerabilities_spec.rb)2
-rw-r--r--spec/migrations/20231130140901_queue_backfill_vs_code_settings_uuid_spec.rb (renamed from spec/migrations/queue_backfill_user_details_fields_spec.rb)8
-rw-r--r--spec/migrations/20231201171229_detect_and_fix_duplicate_organizations_path_spec.rb31
-rw-r--r--spec/migrations/20231201204712_requeue2_backfill_has_remediations_of_vulnerability_reads_spec.rb (renamed from spec/migrations/20231011142714_queue_backfill_has_remediations_of_vulnerability_reads_spec.rb)2
-rw-r--r--spec/migrations/20231207194620_backfill_catalog_resources_visibility_level_spec.rb27
-rw-r--r--spec/migrations/cleanup_vulnerability_state_transitions_with_same_from_state_to_state_spec.rb50
-rw-r--r--spec/migrations/delete_migrate_shared_vulnerability_scanners_spec.rb73
-rw-r--r--spec/migrations/finalize_invalid_member_cleanup_spec.rb76
-rw-r--r--spec/migrations/fix_broken_user_achievements_awarded_spec.rb46
-rw-r--r--spec/migrations/fix_broken_user_achievements_revoked_spec.rb44
-rw-r--r--spec/migrations/queue_populate_projects_star_count_spec.rb24
-rw-r--r--spec/migrations/recount_epic_cache_counts_spec.rb32
-rw-r--r--spec/migrations/reschedule_migrate_shared_vulnerability_scanners_spec.rb41
-rw-r--r--spec/migrations/set_email_confirmation_setting_from_send_user_confirmation_email_setting_spec.rb41
-rw-r--r--spec/migrations/sync_new_amount_used_for_ci_namespace_monthly_usages_spec.rb43
-rw-r--r--spec/migrations/sync_new_amount_used_for_ci_project_monthly_usages_spec.rb43
30 files changed, 184 insertions, 981 deletions
diff --git a/spec/migrations/20221002234454_finalize_group_member_namespace_id_migration_spec.rb b/spec/migrations/20221002234454_finalize_group_member_namespace_id_migration_spec.rb
deleted file mode 100644
index e3adea47273..00000000000
--- a/spec/migrations/20221002234454_finalize_group_member_namespace_id_migration_spec.rb
+++ /dev/null
@@ -1,76 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-require_migration!
-
-RSpec.describe FinalizeGroupMemberNamespaceIdMigration, :migration, feature_category: :groups_and_projects do
- let(:batched_migrations) { table(:batched_background_migrations) }
-
- let!(:migration) { described_class::MIGRATION }
-
- describe '#up' do
- shared_examples 'finalizes the migration' do
- it 'finalizes the migration' do
- allow_next_instance_of(Gitlab::Database::BackgroundMigration::BatchedMigrationRunner) do |runner|
- expect(runner).to receive(:finalize).with(migration, :members, :id, [])
- end
- end
- end
-
- context 'when migration is missing' do
- before do
- batched_migrations.where(job_class_name: migration).delete_all
- end
-
- it 'warns migration not found' do
- expect(Gitlab::AppLogger)
- .to receive(:warn).with(/Could not find batched background migration for the given configuration:/)
-
- migrate!
- end
- end
-
- context 'with migration present' do
- let!(:group_member_namespace_id_backfill) do
- batched_migrations.create!(
- job_class_name: migration,
- table_name: :members,
- column_name: :id,
- job_arguments: [],
- interval: 2.minutes,
- min_value: 1,
- max_value: 2,
- batch_size: 1000,
- sub_batch_size: 200,
- gitlab_schema: :gitlab_main,
- status: 3 # finished
- )
- end
-
- context 'when migration finished successfully' do
- it 'does not raise exception' do
- expect { migrate! }.not_to raise_error
- end
- end
-
- context 'with different migration statuses' do
- using RSpec::Parameterized::TableSyntax
-
- where(:status, :description) do
- 0 | 'paused'
- 1 | 'active'
- 4 | 'failed'
- 5 | 'finalizing'
- end
-
- with_them do
- before do
- group_member_namespace_id_backfill.update!(status: status)
- end
-
- it_behaves_like 'finalizes the migration'
- end
- end
- end
- end
-end
diff --git a/spec/migrations/20221018050323_add_objective_and_keyresult_to_work_item_types_spec.rb b/spec/migrations/20221018050323_add_objective_and_keyresult_to_work_item_types_spec.rb
deleted file mode 100644
index d591b370d65..00000000000
--- a/spec/migrations/20221018050323_add_objective_and_keyresult_to_work_item_types_spec.rb
+++ /dev/null
@@ -1,73 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-require_migration!
-
-RSpec.describe AddObjectiveAndKeyresultToWorkItemTypes, :migration, feature_category: :team_planning do
- include MigrationHelpers::WorkItemTypesHelper
-
- let!(:work_item_types) { table(:work_item_types) }
-
- let(:base_types) do
- {
- issue: 0,
- incident: 1,
- test_case: 2,
- requirement: 3,
- task: 4,
- objective: 5,
- key_result: 6
- }
- end
-
- append_after(:all) do
- # Make sure base types are recreated after running the migration
- # because migration specs are not run in a transaction
- reset_work_item_types
- end
-
- it 'skips creating both objective & keyresult type record if it already exists' do
- reset_db_state_prior_to_migration
- work_item_types.find_or_create_by!(
- name: 'Key Result', namespace_id: nil, base_type: base_types[:key_result], icon_name: 'issue-type-keyresult'
- )
- work_item_types.find_or_create_by!(
- name: 'Objective', namespace_id: nil, base_type: base_types[:objective], icon_name: 'issue-type-objective'
- )
-
- expect do
- migrate!
- end.to not_change(work_item_types, :count)
- end
-
- it 'adds both objective & keyresult to base work item types' do
- reset_db_state_prior_to_migration
-
- expect do
- migrate!
- end.to change(work_item_types, :count).from(5).to(7)
-
- expect(work_item_types.all.pluck(:base_type)).to include(base_types[:objective])
- expect(work_item_types.all.pluck(:base_type)).to include(base_types[:key_result])
- end
-
- def reset_db_state_prior_to_migration
- # Database needs to be in a similar state as when this migration was created
- work_item_types.delete_all
- work_item_types.find_or_create_by!(
- name: 'Issue', namespace_id: nil, base_type: base_types[:issue], icon_name: 'issue-type-issue'
- )
- work_item_types.find_or_create_by!(
- name: 'Incident', namespace_id: nil, base_type: base_types[:incident], icon_name: 'issue-type-incident'
- )
- work_item_types.find_or_create_by!(
- name: 'Test Case', namespace_id: nil, base_type: base_types[:test_case], icon_name: 'issue-type-test-case'
- )
- work_item_types.find_or_create_by!(
- name: 'Requirement', namespace_id: nil, base_type: base_types[:requirement], icon_name: 'issue-type-requirements'
- )
- work_item_types.find_or_create_by!(
- name: 'Task', namespace_id: nil, base_type: base_types[:task], icon_name: 'issue-type-task'
- )
- end
-end
diff --git a/spec/migrations/20221018062308_schedule_backfill_project_namespace_details_spec.rb b/spec/migrations/20221018062308_schedule_backfill_project_namespace_details_spec.rb
deleted file mode 100644
index 9cca2a5adfc..00000000000
--- a/spec/migrations/20221018062308_schedule_backfill_project_namespace_details_spec.rb
+++ /dev/null
@@ -1,37 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-require_migration!
-
-RSpec.describe ScheduleBackfillProjectNamespaceDetails, schema: 20221018062308, feature_category: :groups_and_projects do
- context 'when on gitlab.com' do
- let!(:background_migration) { described_class::MIGRATION }
- let!(:migration) { described_class.new }
-
- before do
- migration.up
- end
-
- describe '#up' do
- it 'schedules background jobs for each batch of projects' do
- expect(background_migration).to(
- have_scheduled_batched_migration(
- table_name: :projects,
- column_name: :id,
- interval: described_class::INTERVAL,
- batch_size: described_class::BATCH_SIZE,
- sub_batch_size: described_class::SUB_BATCH_SIZE
- )
- )
- end
- end
-
- describe '#down' do
- it 'deletes all batched migration records' do
- migration.down
-
- expect(described_class::MIGRATION).not_to have_scheduled_batched_migration
- end
- end
- end
-end
diff --git a/spec/migrations/20221018193635_ensure_task_note_renaming_background_migration_finished_spec.rb b/spec/migrations/20221018193635_ensure_task_note_renaming_background_migration_finished_spec.rb
deleted file mode 100644
index da1df92691e..00000000000
--- a/spec/migrations/20221018193635_ensure_task_note_renaming_background_migration_finished_spec.rb
+++ /dev/null
@@ -1,95 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-require_migration!
-
-RSpec.describe EnsureTaskNoteRenamingBackgroundMigrationFinished, :migration, feature_category: :team_planning do
- let(:batched_migrations) { table(:batched_background_migrations) }
- let(:batch_failed_status) { 2 }
- let(:batch_finalized_status) { 3 }
-
- let!(:migration) { described_class::MIGRATION }
-
- describe '#up' do
- shared_examples 'finalizes the migration' do
- it 'finalizes the migration' do
- expect do
- migrate!
-
- task_renaming_migration.reload
- failed_job.reload
- end.to change(task_renaming_migration, :status).from(task_renaming_migration.status).to(3).and(
- change(failed_job, :status).from(batch_failed_status).to(batch_finalized_status)
- )
- end
- end
-
- context 'when migration is missing' do
- before do
- batched_migrations.where(job_class_name: migration).delete_all
- end
-
- it 'warns migration not found' do
- expect(Gitlab::AppLogger)
- .to receive(:warn).with(/Could not find batched background migration for the given configuration:/)
-
- migrate!
- end
- end
-
- context 'with migration present' do
- let!(:task_renaming_migration) do
- batched_migrations.create!(
- job_class_name: migration,
- table_name: :system_note_metadata,
- column_name: :id,
- job_arguments: [],
- interval: 2.minutes,
- min_value: 1,
- max_value: 2,
- batch_size: 1000,
- sub_batch_size: 200,
- gitlab_schema: :gitlab_main,
- status: 3 # finished
- )
- end
-
- context 'when migration finished successfully' do
- it 'does not raise exception' do
- expect { migrate! }.not_to raise_error
- end
- end
-
- context 'with different migration statuses', :redis do
- using RSpec::Parameterized::TableSyntax
-
- where(:status, :description) do
- 0 | 'paused'
- 1 | 'active'
- 4 | 'failed'
- 5 | 'finalizing'
- end
-
- with_them do
- let!(:failed_job) do
- table(:batched_background_migration_jobs).create!(
- batched_background_migration_id: task_renaming_migration.id,
- status: batch_failed_status,
- min_value: 1,
- max_value: 10,
- attempts: 2,
- batch_size: 100,
- sub_batch_size: 10
- )
- end
-
- before do
- task_renaming_migration.update!(status: status)
- end
-
- it_behaves_like 'finalizes the migration'
- end
- end
- end
- end
-end
diff --git a/spec/migrations/20221021145820_create_routing_table_for_builds_metadata_v2_spec.rb b/spec/migrations/20221021145820_create_routing_table_for_builds_metadata_v2_spec.rb
deleted file mode 100644
index 235351956c4..00000000000
--- a/spec/migrations/20221021145820_create_routing_table_for_builds_metadata_v2_spec.rb
+++ /dev/null
@@ -1,36 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-require_migration!
-
-RSpec.describe CreateRoutingTableForBuildsMetadataV2, :migration, feature_category: :continuous_integration do
- let!(:migration) { described_class.new }
-
- describe '#up' do
- context 'when the table is already partitioned' do
- before do
- # `convert_table_to_first_list_partition` checks if it's being executed
- # inside a transaction, but we're using transactional fixtures here so we
- # need to tell it that it's not inside a transaction.
- # We toggle the behavior depending on how many transactions we have open
- # instead of just returning `false` because the migration could have the
- # DDL transaction enabled.
- #
- open_transactions = ActiveRecord::Base.connection.open_transactions
- allow(migration).to receive(:transaction_open?) do
- ActiveRecord::Base.connection.open_transactions > open_transactions
- end
-
- migration.convert_table_to_first_list_partition(
- table_name: :ci_builds_metadata,
- partitioning_column: :partition_id,
- parent_table_name: :p_ci_builds_metadata,
- initial_partitioning_value: 100)
- end
-
- it 'skips the migration' do
- expect { migrate! }.not_to raise_error
- end
- end
- end
-end
diff --git a/spec/migrations/20221025043930_change_default_value_on_password_last_changed_at_to_user_details_spec.rb b/spec/migrations/20221025043930_change_default_value_on_password_last_changed_at_to_user_details_spec.rb
deleted file mode 100644
index 0e5bb419e32..00000000000
--- a/spec/migrations/20221025043930_change_default_value_on_password_last_changed_at_to_user_details_spec.rb
+++ /dev/null
@@ -1,37 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-require_migration!
-
-RSpec.describe ChangeDefaultValueOnPasswordLastChangedAtToUserDetails, :migration, feature_category: :user_profile do
- let(:namespace) { table(:namespaces).create!(name: 'user', path: 'user') }
- let(:users) { table(:users) }
- let(:user_details) { table(:user_details) }
-
- it 'correctly migrates up and down' do
- user = create_user!(email: '1234@abc')
- user_details.create!(user_id: user.id, provisioned_by_group_id: namespace.id)
-
- expect(UserDetail.find_by(user_id: user.id).password_last_changed_at).to be_nil
-
- migrate!
-
- user = create_user!(email: 'abc@1234')
- user_details.create!(user_id: user.id, provisioned_by_group_id: namespace.id)
-
- expect(UserDetail.find_by(user_id: user.id).password_last_changed_at).not_to be_nil
- end
-
- private
-
- def create_user!(name: "Example User", email: "user@example.com", user_type: nil)
- users.create!(
- name: name,
- email: email,
- username: name,
- projects_limit: 0,
- user_type: user_type,
- confirmed_at: Time.current
- )
- end
-end
diff --git a/spec/migrations/20221028022627_add_index_on_password_last_changed_at_to_user_details_spec.rb b/spec/migrations/20221028022627_add_index_on_password_last_changed_at_to_user_details_spec.rb
deleted file mode 100644
index 332b3a5abba..00000000000
--- a/spec/migrations/20221028022627_add_index_on_password_last_changed_at_to_user_details_spec.rb
+++ /dev/null
@@ -1,16 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-require_migration!
-
-RSpec.describe AddIndexOnPasswordLastChangedAtToUserDetails, :migration, feature_category: :user_profile do
- let(:index_name) { 'index_user_details_on_password_last_changed_at' }
-
- it 'correctly migrates up and down' do
- expect(subject).not_to be_index_exists_by_name(:user_details, index_name)
-
- migrate!
-
- expect(subject).to be_index_exists_by_name(:user_details, index_name)
- end
-end
diff --git a/spec/migrations/20221101032521_add_default_preferred_language_to_application_settings_spec.rb b/spec/migrations/20221101032521_add_default_preferred_language_to_application_settings_spec.rb
deleted file mode 100644
index deca498146b..00000000000
--- a/spec/migrations/20221101032521_add_default_preferred_language_to_application_settings_spec.rb
+++ /dev/null
@@ -1,27 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-
-require_migration!
-
-RSpec.describe AddDefaultPreferredLanguageToApplicationSettings, feature_category: :internationalization do
- let(:application_setting) { table(:application_settings).create! }
-
- describe "#up" do
- it 'allows to read default_preferred_language field' do
- migrate!
-
- expect(application_setting.attributes.keys).to include('default_preferred_language')
- expect(application_setting.default_preferred_language).to eq 'en'
- end
- end
-
- describe "#down" do
- it 'deletes default_preferred_language field' do
- migrate!
- schema_migrate_down!
-
- expect(application_setting.attributes.keys).not_to include('default_preferred_language')
- end
- end
-end
diff --git a/spec/migrations/20221101032600_add_text_limit_to_default_preferred_language_on_application_settings_spec.rb b/spec/migrations/20221101032600_add_text_limit_to_default_preferred_language_on_application_settings_spec.rb
deleted file mode 100644
index 3e36e99a0ca..00000000000
--- a/spec/migrations/20221101032600_add_text_limit_to_default_preferred_language_on_application_settings_spec.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-
-require_migration!
-
-RSpec.describe AddTextLimitToDefaultPreferredLanguageOnApplicationSettings, feature_category: :internationalization do
- let(:application_setting) { table(:application_settings).create! }
- let(:too_long_text) { SecureRandom.alphanumeric(described_class::MAXIMUM_LIMIT + 1) }
-
- subject { application_setting.update_column(:default_preferred_language, too_long_text) }
-
- describe "#up" do
- it 'adds text limit to default_preferred_language' do
- migrate!
-
- expect { subject }.to raise_error ActiveRecord::StatementInvalid
- end
- end
-
- describe "#down" do
- it 'deletes text limit to default_preferred_language' do
- migrate!
- schema_migrate_down!
-
- expect { subject }.not_to raise_error
- end
- end
-end
diff --git a/spec/migrations/20221102090940_create_next_ci_partitions_record_spec.rb b/spec/migrations/20221102090940_create_next_ci_partitions_record_spec.rb
deleted file mode 100644
index dc6f365fe2b..00000000000
--- a/spec/migrations/20221102090940_create_next_ci_partitions_record_spec.rb
+++ /dev/null
@@ -1,63 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-require_migration!
-
-RSpec.describe CreateNextCiPartitionsRecord, migration: :gitlab_ci, feature_category: :continuous_integration do
- let(:migration) { described_class.new }
- let(:partitions) { table(:ci_partitions) }
-
- describe '#up' do
- context 'when on sass' do
- before do
- allow(Gitlab).to receive(:com?).and_return(true)
- end
-
- it 'creates next partitions record and resets the sequence' do
- expect { migrate! }
- .to change { partitions.where(id: 101).any? }
- .from(false).to(true)
-
- expect { partitions.create! }.not_to raise_error
- end
- end
-
- context 'when self-managed' do
- before do
- allow(Gitlab).to receive(:com?).and_return(false)
- end
-
- it 'does not create records' do
- expect { migrate! }.not_to change(partitions, :count)
- end
- end
- end
-
- describe '#down' do
- context 'when on sass' do
- before do
- allow(Gitlab).to receive(:com?).and_return(true)
- end
-
- it 'removes the record' do
- migrate!
-
- expect { migration.down }
- .to change { partitions.where(id: 101).any? }
- .from(true).to(false)
- end
- end
-
- context 'when self-managed' do
- before do
- allow(Gitlab).to receive(:com?).and_return(true, false)
- end
-
- it 'does not remove the record' do
- expect { migrate! }.to change(partitions, :count).by(1)
-
- expect { migration.down }.not_to change(partitions, :count)
- end
- end
- end
-end
diff --git a/spec/migrations/20221102090943_create_second_partition_for_builds_metadata_spec.rb b/spec/migrations/20221102090943_create_second_partition_for_builds_metadata_spec.rb
deleted file mode 100644
index b4bd5136383..00000000000
--- a/spec/migrations/20221102090943_create_second_partition_for_builds_metadata_spec.rb
+++ /dev/null
@@ -1,61 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-require_migration!
-
-RSpec.describe CreateSecondPartitionForBuildsMetadata, :migration, feature_category: :continuous_integration do
- let(:migration) { described_class.new }
- let(:partitions) { table(:ci_partitions) }
-
- describe '#up' do
- context 'when on sass' do
- before do
- allow(Gitlab).to receive(:com?).and_return(true)
- end
-
- it 'creates a new partition' do
- expect { migrate! }.to change { partitions_count }.by(1)
- end
- end
-
- context 'when self-managed' do
- before do
- allow(Gitlab).to receive(:com?).and_return(false)
- end
-
- it 'does not create the partition' do
- expect { migrate! }.not_to change { partitions_count }
- end
- end
- end
-
- describe '#down' do
- context 'when on sass' do
- before do
- allow(Gitlab).to receive(:com?).and_return(true)
- end
-
- it 'removes the partition' do
- migrate!
-
- expect { migration.down }.to change { partitions_count }.by(-1)
- end
- end
-
- context 'when self-managed' do
- before do
- allow(Gitlab).to receive(:com?).and_return(false)
- end
-
- it 'does not change the partitions count' do
- migrate!
-
- expect { migration.down }.not_to change { partitions_count }
- end
- end
- end
-
- def partitions_count
- Gitlab::Database::PostgresPartition.for_parent_table(:p_ci_builds_metadata).size
- end
-end
diff --git a/spec/migrations/20230802085923_queue_fix_allow_descendants_override_disabled_shared_runners_spec.rb b/spec/migrations/20230802085923_queue_fix_allow_descendants_override_disabled_shared_runners_spec.rb
index c296ba24d9d..f12985bf6c9 100644
--- a/spec/migrations/20230802085923_queue_fix_allow_descendants_override_disabled_shared_runners_spec.rb
+++ b/spec/migrations/20230802085923_queue_fix_allow_descendants_override_disabled_shared_runners_spec.rb
@@ -3,7 +3,7 @@
require 'spec_helper'
require_migration!
-RSpec.describe QueueFixAllowDescendantsOverrideDisabledSharedRunners, feature_category: :runner_fleet do
+RSpec.describe QueueFixAllowDescendantsOverrideDisabledSharedRunners, feature_category: :fleet_visibility do
let!(:batched_migration) { described_class::MIGRATION }
it 'schedules a new batched migration' do
diff --git a/spec/migrations/20231107092912_queue_backfill_branch_protection_namespace_setting_spec.rb b/spec/migrations/20231107092912_queue_backfill_branch_protection_namespace_setting_spec.rb
new file mode 100644
index 00000000000..ddf4fb1e1c4
--- /dev/null
+++ b/spec/migrations/20231107092912_queue_backfill_branch_protection_namespace_setting_spec.rb
@@ -0,0 +1,26 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+require_migration!
+
+RSpec.describe QueueBackfillBranchProtectionNamespaceSetting, feature_category: :database do
+ let!(:batched_migration) { described_class::MIGRATION }
+
+ it 'schedules a new batched migration' do
+ reversible_migration do |migration|
+ migration.before -> {
+ expect(batched_migration).not_to have_scheduled_batched_migration
+ }
+
+ migration.after -> {
+ expect(batched_migration).to have_scheduled_batched_migration(
+ table_name: :namespace_settings,
+ column_name: :namespace_id,
+ interval: described_class::DELAY_INTERVAL,
+ batch_size: described_class::BATCH_SIZE,
+ sub_batch_size: described_class::SUB_BATCH_SIZE
+ )
+ }
+ end
+ end
+end
diff --git a/spec/migrations/20231001105945_requeue_backfill_finding_id_in_vulnerabilities_spec.rb b/spec/migrations/20231115025547_queue_backfill_merge_request_diffs_project_id_spec.rb
index f89fc55b6b8..6c80659e969 100644
--- a/spec/migrations/20231001105945_requeue_backfill_finding_id_in_vulnerabilities_spec.rb
+++ b/spec/migrations/20231115025547_queue_backfill_merge_request_diffs_project_id_spec.rb
@@ -3,7 +3,7 @@
require 'spec_helper'
require_migration!
-RSpec.describe RequeueBackfillFindingIdInVulnerabilities, feature_category: :vulnerability_management do
+RSpec.describe QueueBackfillMergeRequestDiffsProjectId, feature_category: :code_review_workflow do
let!(:batched_migration) { described_class::MIGRATION }
it 'schedules a new batched migration' do
@@ -14,7 +14,7 @@ RSpec.describe RequeueBackfillFindingIdInVulnerabilities, feature_category: :vul
migration.after -> {
expect(batched_migration).to have_scheduled_batched_migration(
- table_name: :vulnerabilities,
+ table_name: :merge_request_diffs,
column_name: :id,
interval: described_class::DELAY_INTERVAL,
batch_size: described_class::BATCH_SIZE,
diff --git a/spec/migrations/20230912105945_queue_backfill_finding_id_in_vulnerabilities_spec.rb b/spec/migrations/20231129105945_requeue_backfill_finding_id_in_vulnerabilities3_spec.rb
index 02c39408d40..ca007e7487c 100644
--- a/spec/migrations/20230912105945_queue_backfill_finding_id_in_vulnerabilities_spec.rb
+++ b/spec/migrations/20231129105945_requeue_backfill_finding_id_in_vulnerabilities3_spec.rb
@@ -3,7 +3,7 @@
require 'spec_helper'
require_migration!
-RSpec.describe QueueBackfillFindingIdInVulnerabilities, feature_category: :vulnerability_management do
+RSpec.describe RequeueBackfillFindingIdInVulnerabilities3, feature_category: :vulnerability_management do
let!(:batched_migration) { described_class::MIGRATION }
it 'schedules a new batched migration' do
diff --git a/spec/migrations/queue_backfill_user_details_fields_spec.rb b/spec/migrations/20231130140901_queue_backfill_vs_code_settings_uuid_spec.rb
index 4613a85be40..3e697d6b1f3 100644
--- a/spec/migrations/queue_backfill_user_details_fields_spec.rb
+++ b/spec/migrations/20231130140901_queue_backfill_vs_code_settings_uuid_spec.rb
@@ -3,7 +3,7 @@
require 'spec_helper'
require_migration!
-RSpec.describe QueueBackfillUserDetailsFields, feature_category: :user_profile do
+RSpec.describe QueueBackfillVsCodeSettingsUuid, feature_category: :web_ide do
let!(:batched_migration) { described_class::MIGRATION }
it 'schedules a new batched migration' do
@@ -14,9 +14,11 @@ RSpec.describe QueueBackfillUserDetailsFields, feature_category: :user_profile d
migration.after -> {
expect(batched_migration).to have_scheduled_batched_migration(
- table_name: :users,
+ table_name: :vs_code_settings,
column_name: :id,
- interval: described_class::INTERVAL
+ interval: described_class::DELAY_INTERVAL,
+ batch_size: described_class::BATCH_SIZE,
+ sub_batch_size: described_class::SUB_BATCH_SIZE
)
}
end
diff --git a/spec/migrations/20231201171229_detect_and_fix_duplicate_organizations_path_spec.rb b/spec/migrations/20231201171229_detect_and_fix_duplicate_organizations_path_spec.rb
new file mode 100644
index 00000000000..259327bec86
--- /dev/null
+++ b/spec/migrations/20231201171229_detect_and_fix_duplicate_organizations_path_spec.rb
@@ -0,0 +1,31 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+require_migration!
+
+RSpec.describe DetectAndFixDuplicateOrganizationsPath, feature_category: :cell do
+ let!(:default_organization) { table(:organizations).create!(name: 'Default', path: 'Default') }
+
+ let(:duplicate_path_name) { 'some_path' }
+ let!(:organization) { table(:organizations).create!(name: '_name_', path: duplicate_path_name) }
+ let!(:organization_duplicate) { table(:organizations).create!(name: '_name_', path: duplicate_path_name.upcase) }
+ let!(:organization_multiple_duplicate) do
+ table(:organizations).create!(name: '_name_', path: duplicate_path_name.upcase_first)
+ end
+
+ describe '#up' do
+ it 'removes the duplication', :aggregate_failures do
+ expect(organization.path).to eq(duplicate_path_name)
+ expect(organization_duplicate.path).to eq(duplicate_path_name.upcase)
+ expect(organization_multiple_duplicate.path).to eq(duplicate_path_name.upcase_first)
+ expect(default_organization.path).to eq('Default')
+
+ migrate!
+
+ expect(organization.reload.path).to eq(duplicate_path_name)
+ expect(organization_duplicate.reload.path).to eq("#{duplicate_path_name.upcase}1")
+ expect(organization_multiple_duplicate.reload.path).to eq("#{duplicate_path_name.upcase_first}2")
+ expect(default_organization.reload.path).to eq('Default')
+ end
+ end
+end
diff --git a/spec/migrations/20231011142714_queue_backfill_has_remediations_of_vulnerability_reads_spec.rb b/spec/migrations/20231201204712_requeue2_backfill_has_remediations_of_vulnerability_reads_spec.rb
index 27ecc255a2a..4299fdc731f 100644
--- a/spec/migrations/20231011142714_queue_backfill_has_remediations_of_vulnerability_reads_spec.rb
+++ b/spec/migrations/20231201204712_requeue2_backfill_has_remediations_of_vulnerability_reads_spec.rb
@@ -3,7 +3,7 @@
require 'spec_helper'
require_migration!
-RSpec.describe QueueBackfillHasRemediationsOfVulnerabilityReads, feature_category: :database do
+RSpec.describe Requeue2BackfillHasRemediationsOfVulnerabilityReads, feature_category: :database do
let!(:batched_migration) { described_class::MIGRATION }
it 'schedules a new batched migration' do
diff --git a/spec/migrations/20231207194620_backfill_catalog_resources_visibility_level_spec.rb b/spec/migrations/20231207194620_backfill_catalog_resources_visibility_level_spec.rb
new file mode 100644
index 00000000000..9023aa705a1
--- /dev/null
+++ b/spec/migrations/20231207194620_backfill_catalog_resources_visibility_level_spec.rb
@@ -0,0 +1,27 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+require_migration!
+
+RSpec.describe BackfillCatalogResourcesVisibilityLevel, feature_category: :pipeline_composition do
+ let(:namespace) { table(:namespaces).create!(name: 'name', path: 'path') }
+
+ let(:project) do
+ table(:projects).create!(
+ visibility_level: Gitlab::VisibilityLevel::INTERNAL,
+ namespace_id: namespace.id, project_namespace_id: namespace.id
+ )
+ end
+
+ let(:resource) { table(:catalog_resources).create!(project_id: project.id) }
+
+ describe '#up' do
+ it 'updates the visibility_level to match the project' do
+ expect(resource.visibility_level).to eq(0)
+
+ migrate!
+
+ expect(resource.reload.visibility_level).to eq(Gitlab::VisibilityLevel::INTERNAL)
+ end
+ end
+end
diff --git a/spec/migrations/cleanup_vulnerability_state_transitions_with_same_from_state_to_state_spec.rb b/spec/migrations/cleanup_vulnerability_state_transitions_with_same_from_state_to_state_spec.rb
deleted file mode 100644
index b270f2b100f..00000000000
--- a/spec/migrations/cleanup_vulnerability_state_transitions_with_same_from_state_to_state_spec.rb
+++ /dev/null
@@ -1,50 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-require_migration!
-
-RSpec.describe CleanupVulnerabilityStateTransitionsWithSameFromStateToState, :migration,
- feature_category: :vulnerability_management do
- let!(:namespace) { table(:namespaces).create!(name: 'namespace', type: 'Group', path: 'namespace') }
- let!(:user) { table(:users).create!(email: 'author@example.com', username: 'author', projects_limit: 10) }
- let!(:project) do
- table(:projects).create!(
- path: 'project',
- namespace_id: namespace.id,
- project_namespace_id: namespace.id
- )
- end
-
- let!(:vulnerability) do
- table(:vulnerabilities).create!(
- project_id: project.id,
- author_id: user.id,
- title: 'test',
- severity: 7,
- confidence: 7,
- report_type: 0
- )
- end
-
- let!(:state_transitions) { table(:vulnerability_state_transitions) }
-
- let!(:state_transition_with_no_state_change) do
- state_transitions.create!(
- vulnerability_id: vulnerability.id,
- from_state: 2,
- to_state: 2
- )
- end
-
- let!(:state_transition_with_state_change) do
- state_transitions.create!(
- vulnerability_id: vulnerability.id,
- from_state: 1,
- to_state: 2
- )
- end
-
- it 'deletes state transitions with no state change' do
- expect { migrate! }.to change(state_transitions, :count).from(2).to(1)
- end
-end
diff --git a/spec/migrations/delete_migrate_shared_vulnerability_scanners_spec.rb b/spec/migrations/delete_migrate_shared_vulnerability_scanners_spec.rb
deleted file mode 100644
index 8a0c0250cdf..00000000000
--- a/spec/migrations/delete_migrate_shared_vulnerability_scanners_spec.rb
+++ /dev/null
@@ -1,73 +0,0 @@
-# frozen_string_literal: true
-
-require "spec_helper"
-
-require_migration!
-
-RSpec.describe DeleteMigrateSharedVulnerabilityScanners, :migration, feature_category: :vulnerability_management do
- let(:batched_background_migrations) { table(:batched_background_migrations) }
- let(:batched_background_migration_jobs) { table(:batched_background_migration_jobs) }
-
- let(:migration) do
- batched_background_migrations.create!(
- created_at: Time.zone.now,
- updated_at: Time.zone.now,
- min_value: 1,
- max_value: 1,
- batch_size: described_class::BATCH_SIZE,
- sub_batch_size: 100,
- interval: 300,
- status: 3,
- job_class_name: described_class::MIGRATION,
- batch_class_name: "PrimaryKeyBatchingStrategy",
- table_name: described_class::TABLE_NAME,
- column_name: described_class::BATCH_COLUMN,
- job_arguments: [],
- pause_ms: 100,
- max_batch_size: 1000,
- gitlab_schema: "gitlab_main"
- )
- end
-
- let(:jobs) do
- Array.new(10) do
- batched_background_migration_jobs.create!(
- batched_background_migration_id: migration.id,
- created_at: Time.zone.now,
- updated_at: Time.zone.now,
- min_value: 1,
- max_value: 1,
- batch_size: 1,
- sub_batch_size: 1,
- status: 0,
- attempts: 0,
- metrics: {},
- pause_ms: 100
- )
- end
- end
-
- describe "#up" do
- it "deletes jobs" do
- expect { migrate! }.to change(batched_background_migration_jobs, :count).from(jobs.count).to(0)
- end
-
- it "deletes the migration" do
- expect { migrate! }.to change { batched_background_migrations.find_by(id: migration.id) }.from(migration).to(nil)
- end
-
- context "when background migration does not exist" do
- before do
- migration.destroy!
- end
-
- it "does not delete jobs" do
- expect { migrate! }.not_to change(batched_background_migration_jobs, :count)
- end
-
- it "does not delete the migration" do
- expect { migrate! }.not_to change { batched_background_migrations.find_by(id: migration.id) }
- end
- end
- end
-end
diff --git a/spec/migrations/finalize_invalid_member_cleanup_spec.rb b/spec/migrations/finalize_invalid_member_cleanup_spec.rb
deleted file mode 100644
index ace973ea1af..00000000000
--- a/spec/migrations/finalize_invalid_member_cleanup_spec.rb
+++ /dev/null
@@ -1,76 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-require_migration!
-
-RSpec.describe FinalizeInvalidMemberCleanup, :migration, feature_category: :groups_and_projects do
- let(:batched_migrations) { table(:batched_background_migrations) }
-
- let!(:migration) { described_class::MIGRATION }
-
- describe '#up' do
- shared_examples 'finalizes the migration' do
- it 'finalizes the migration' do
- allow_next_instance_of(Gitlab::Database::BackgroundMigration::BatchedMigrationRunner) do |runner|
- expect(runner).to receive(:finalize).with('DestroyInvalidMembers', :members, :id, [])
- end
- end
- end
-
- context 'when migration is missing' do
- before do
- batched_migrations.where(job_class_name: migration).delete_all
- end
-
- it 'warns migration not found' do
- expect(Gitlab::AppLogger)
- .to receive(:warn).with(/Could not find batched background migration for the given configuration:/)
-
- migrate!
- end
- end
-
- context 'with migration present' do
- let!(:destroy_invalid_member_migration) do
- batched_migrations.create!(
- job_class_name: 'DestroyInvalidMembers',
- table_name: :members,
- column_name: :id,
- job_arguments: [],
- interval: 2.minutes,
- min_value: 1,
- max_value: 2,
- batch_size: 1000,
- sub_batch_size: 200,
- gitlab_schema: :gitlab_main,
- status: 3 # finished
- )
- end
-
- context 'when migration finished successfully' do
- it 'does not raise exception' do
- expect { migrate! }.not_to raise_error
- end
- end
-
- context 'with different migration statuses' do
- using RSpec::Parameterized::TableSyntax
-
- where(:status, :description) do
- 0 | 'paused'
- 1 | 'active'
- 4 | 'failed'
- 5 | 'finalizing'
- end
-
- with_them do
- before do
- destroy_invalid_member_migration.update!(status: status)
- end
-
- it_behaves_like 'finalizes the migration'
- end
- end
- end
- end
-end
diff --git a/spec/migrations/fix_broken_user_achievements_awarded_spec.rb b/spec/migrations/fix_broken_user_achievements_awarded_spec.rb
new file mode 100644
index 00000000000..cb31ca44a9f
--- /dev/null
+++ b/spec/migrations/fix_broken_user_achievements_awarded_spec.rb
@@ -0,0 +1,46 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+require_migration!
+
+RSpec.describe FixBrokenUserAchievementsAwarded, migration: :gitlab_main, feature_category: :user_profile do
+ let(:migration) { described_class.new }
+
+ let(:users_table) { table(:users) }
+ let(:namespaces_table) { table(:namespaces) }
+ let(:achievements_table) { table(:achievements) }
+ let(:user_achievements_table) { table(:user_achievements) }
+ let(:namespace) { namespaces_table.create!(name: 'something', path: generate(:username)) }
+ let(:achievement) { achievements_table.create!(name: 'something', namespace_id: namespace.id) }
+ let(:user) { users_table.create!(username: generate(:username), projects_limit: 0) }
+ let(:awarding_user) do
+ users_table.create!(username: generate(:username), email: generate(:email), projects_limit: 0)
+ end
+
+ let!(:user_achievement_invalid) do
+ user_achievements_table.create!(user_id: user.id, achievement_id: achievement.id,
+ awarded_by_user_id: awarding_user.id)
+ end
+
+ let!(:user_achievement_valid) do
+ user_achievements_table.create!(user_id: user.id, achievement_id: achievement.id,
+ awarded_by_user_id: user.id)
+ end
+
+ describe '#up' do
+ before do
+ awarding_user.delete
+ end
+
+ it 'migrates the invalid user achievement' do
+ expect { migrate! }
+ .to change { user_achievement_invalid.reload.awarded_by_user_id }
+ .from(nil).to(Users::Internal.ghost.id)
+ end
+
+ it 'does not migrate the valid user achievement' do
+ expect { migrate! }
+ .not_to change { user_achievement_valid.reload.awarded_by_user_id }
+ end
+ end
+end
diff --git a/spec/migrations/fix_broken_user_achievements_revoked_spec.rb b/spec/migrations/fix_broken_user_achievements_revoked_spec.rb
new file mode 100644
index 00000000000..34517ae67b4
--- /dev/null
+++ b/spec/migrations/fix_broken_user_achievements_revoked_spec.rb
@@ -0,0 +1,44 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+require_migration!
+
+RSpec.describe FixBrokenUserAchievementsRevoked, migration: :gitlab_main, feature_category: :user_profile do
+ let(:migration) { described_class.new }
+
+ let(:users_table) { table(:users) }
+ let(:namespaces_table) { table(:namespaces) }
+ let(:achievements_table) { table(:achievements) }
+ let(:user_achievements_table) { table(:user_achievements) }
+ let(:namespace) { namespaces_table.create!(name: 'something', path: generate(:username)) }
+ let(:achievement) { achievements_table.create!(name: 'something', namespace_id: namespace.id) }
+ let(:user) { users_table.create!(username: generate(:username), projects_limit: 0) }
+ let(:revoked_invalid) do
+ user_achievements_table.create!(user_id: user.id, achievement_id: achievement.id, revoked_at: Time.current)
+ end
+
+ let(:revoked_valid) do
+ user_achievements_table.create!(user_id: user.id, achievement_id: achievement.id, revoked_at: Time.current,
+ revoked_by_user_id: user.id)
+ end
+
+ let(:not_revoked) { user_achievements_table.create!(user_id: user.id, achievement_id: achievement.id) }
+
+ describe '#up' do
+ it 'migrates the invalid user achievement' do
+ expect { migrate! }
+ .to change { revoked_invalid.reload.revoked_by_user_id }
+ .from(nil).to(Users::Internal.ghost.id)
+ end
+
+ it 'does not migrate valid revoked user achievement' do
+ expect { migrate! }
+ .not_to change { revoked_valid.reload.revoked_by_user_id }
+ end
+
+ it 'does not migrate the not revoked user achievement' do
+ expect { migrate! }
+ .not_to change { not_revoked.reload.revoked_by_user_id }
+ end
+ end
+end
diff --git a/spec/migrations/queue_populate_projects_star_count_spec.rb b/spec/migrations/queue_populate_projects_star_count_spec.rb
deleted file mode 100644
index b30bb6a578b..00000000000
--- a/spec/migrations/queue_populate_projects_star_count_spec.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-require_migration!
-
-RSpec.describe QueuePopulateProjectsStarCount, feature_category: :user_profile do
- let!(:batched_migration) { described_class::MIGRATION }
-
- it 'schedules a new batched migration' do
- reversible_migration do |migration|
- migration.before -> {
- expect(batched_migration).not_to have_scheduled_batched_migration
- }
-
- migration.after -> {
- expect(batched_migration).to have_scheduled_batched_migration(
- table_name: :projects,
- column_name: :id,
- interval: described_class::DELAY_INTERVAL
- )
- }
- end
- end
-end
diff --git a/spec/migrations/recount_epic_cache_counts_spec.rb b/spec/migrations/recount_epic_cache_counts_spec.rb
deleted file mode 100644
index d065389a726..00000000000
--- a/spec/migrations/recount_epic_cache_counts_spec.rb
+++ /dev/null
@@ -1,32 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-require_migration!
-
-RSpec.describe RecountEpicCacheCounts, :migration, feature_category: :portfolio_management do
- let(:migration) { described_class::MIGRATION }
-
- describe '#up' do
- it 'schedules a batched background migration' do
- migrate!
-
- expect(migration).to have_scheduled_batched_migration(
- table_name: :epics,
- column_name: :id,
- interval: described_class::DELAY_INTERVAL,
- batch_size: described_class::BATCH_SIZE,
- max_batch_size: described_class::MAX_BATCH_SIZE,
- sub_batch_size: described_class::SUB_BATCH_SIZE
- )
- end
- end
-
- describe '#down' do
- it 'deletes all batched migration records' do
- migrate!
- schema_migrate_down!
-
- expect(migration).not_to have_scheduled_batched_migration
- end
- end
-end
diff --git a/spec/migrations/reschedule_migrate_shared_vulnerability_scanners_spec.rb b/spec/migrations/reschedule_migrate_shared_vulnerability_scanners_spec.rb
deleted file mode 100644
index 48422de81fe..00000000000
--- a/spec/migrations/reschedule_migrate_shared_vulnerability_scanners_spec.rb
+++ /dev/null
@@ -1,41 +0,0 @@
-# frozen_string_literal: true
-
-require "spec_helper"
-
-require_migration!
-
-RSpec.describe RescheduleMigrateSharedVulnerabilityScanners, :migration, feature_category: :vulnerability_management do
- include Gitlab::Database::Migrations::BatchedBackgroundMigrationHelpers
-
- def connection
- ApplicationRecord.connection
- end
-
- describe "#up" do
- before do
- migrate!
- end
-
- it "schedules" do
- expect(described_class::MIGRATION).to have_scheduled_batched_migration(
- table_name: described_class::TABLE_NAME,
- column_name: described_class::BATCH_COLUMN,
- interval: described_class::DELAY_INTERVAL,
- batch_size: described_class::BATCH_SIZE,
- max_batch_size: described_class::BATCH_SIZE,
- sub_batch_size: described_class::SUB_BATCH_SIZE,
- gitlab_schema: :gitlab_main
- )
- end
- end
-
- describe '#down' do
- before do
- schema_migrate_down!
- end
-
- it "deletes" do
- expect(described_class::MIGRATION).not_to have_scheduled_batched_migration
- end
- end
-end
diff --git a/spec/migrations/set_email_confirmation_setting_from_send_user_confirmation_email_setting_spec.rb b/spec/migrations/set_email_confirmation_setting_from_send_user_confirmation_email_setting_spec.rb
deleted file mode 100644
index ef1ced530c9..00000000000
--- a/spec/migrations/set_email_confirmation_setting_from_send_user_confirmation_email_setting_spec.rb
+++ /dev/null
@@ -1,41 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-require_migration!
-
-RSpec.describe SetEmailConfirmationSettingFromSendUserConfirmationEmailSetting, feature_category: :user_profile do
- let(:migration) { described_class.new }
- let(:application_settings_table) { table(:application_settings) }
-
- describe '#up' do
- context "when 'send_user_confirmation_email' is set to 'true'" do
- it "updates 'email_confirmation_setting' to '2' (hard)" do
- application_settings_table.create!(send_user_confirmation_email: true, email_confirmation_setting: 0)
-
- migration.up
-
- expect(application_settings_table.last.email_confirmation_setting).to eq 2
- end
- end
-
- context "when 'send_user_confirmation_email' is set to 'false'" do
- it "updates 'email_confirmation_setting' to '0' (off)" do
- application_settings_table.create!(send_user_confirmation_email: false, email_confirmation_setting: 0)
-
- migration.up
-
- expect(application_settings_table.last.email_confirmation_setting).to eq 0
- end
- end
- end
-
- describe '#down' do
- it "updates 'email_confirmation_setting' to default value: '0' (off)" do
- application_settings_table.create!(send_user_confirmation_email: true, email_confirmation_setting: 2)
-
- migration.down
-
- expect(application_settings_table.last.email_confirmation_setting).to eq 0
- end
- end
-end
diff --git a/spec/migrations/sync_new_amount_used_for_ci_namespace_monthly_usages_spec.rb b/spec/migrations/sync_new_amount_used_for_ci_namespace_monthly_usages_spec.rb
deleted file mode 100644
index c60447d04a1..00000000000
--- a/spec/migrations/sync_new_amount_used_for_ci_namespace_monthly_usages_spec.rb
+++ /dev/null
@@ -1,43 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-
-require_migration!
-
-RSpec.describe SyncNewAmountUsedForCiNamespaceMonthlyUsages, migration: :gitlab_ci,
- feature_category: :continuous_integration do
- let(:namespace_usages) { table(:ci_namespace_monthly_usages) }
-
- before do
- # Disabling the trigger temporarily to allow records being created with out-of-sync
- # `new_amount_used` and `amount_used`. This will simulate existing records before
- # we add the trigger.
- ActiveRecord::Base.connection
- .execute("ALTER TABLE ci_namespace_monthly_usages DISABLE TRIGGER sync_namespaces_amount_used_columns")
-
- this_month = Time.now.utc.beginning_of_month
- last_month = 1.month.ago.utc.beginning_of_month
- last_year = 1.year.ago.utc.beginning_of_month
-
- namespace_usages.create!(namespace_id: 1, date: last_year)
- namespace_usages.create!(namespace_id: 1, date: this_month, amount_used: 10, new_amount_used: 0)
- namespace_usages.create!(namespace_id: 1, date: last_month, amount_used: 20, new_amount_used: 0)
-
- namespace_usages.create!(namespace_id: 2, date: last_year)
- namespace_usages.create!(namespace_id: 2, date: this_month, amount_used: 30, new_amount_used: 0)
- namespace_usages.create!(namespace_id: 2, date: last_month, amount_used: 40, new_amount_used: 0)
-
- ActiveRecord::Base.connection
- .execute("ALTER TABLE ci_namespace_monthly_usages ENABLE TRIGGER sync_namespaces_amount_used_columns")
- end
-
- it 'updates `new_amount_used` with values from `amount_used`' do
- expect(namespace_usages.where(new_amount_used: 0).count).to eq(6)
-
- migrate!
-
- expect(namespace_usages.where(new_amount_used: 0).count).to eq(2)
- expect(namespace_usages.order(:id).pluck(:new_amount_used))
- .to contain_exactly(0, 0, 10, 20, 30, 40)
- end
-end
diff --git a/spec/migrations/sync_new_amount_used_for_ci_project_monthly_usages_spec.rb b/spec/migrations/sync_new_amount_used_for_ci_project_monthly_usages_spec.rb
deleted file mode 100644
index d7add66a97f..00000000000
--- a/spec/migrations/sync_new_amount_used_for_ci_project_monthly_usages_spec.rb
+++ /dev/null
@@ -1,43 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-
-require_migration!
-
-RSpec.describe SyncNewAmountUsedForCiProjectMonthlyUsages, migration: :gitlab_ci,
- feature_category: :continuous_integration do
- let(:project_usages) { table(:ci_project_monthly_usages) }
-
- before do
- # Disabling the trigger temporarily to allow records being created with out-of-sync
- # `new_amount_used` and `amount_used`. This will simulate existing records before
- # we add the trigger.
- ActiveRecord::Base.connection
- .execute("ALTER TABLE ci_project_monthly_usages DISABLE TRIGGER sync_projects_amount_used_columns")
-
- this_month = Time.now.utc.beginning_of_month
- last_month = 1.month.ago.utc.beginning_of_month
- last_year = 1.year.ago.utc.beginning_of_month
-
- project_usages.create!(project_id: 1, date: last_year)
- project_usages.create!(project_id: 1, date: this_month, amount_used: 10, new_amount_used: 0)
- project_usages.create!(project_id: 1, date: last_month, amount_used: 20, new_amount_used: 0)
-
- project_usages.create!(project_id: 2, date: last_year)
- project_usages.create!(project_id: 2, date: this_month, amount_used: 30, new_amount_used: 0)
- project_usages.create!(project_id: 2, date: last_month, amount_used: 40, new_amount_used: 0)
-
- ActiveRecord::Base.connection
- .execute("ALTER TABLE ci_project_monthly_usages ENABLE TRIGGER sync_projects_amount_used_columns")
- end
-
- it 'updates `new_amount_used` with values from `amount_used`' do
- expect(project_usages.where(new_amount_used: 0).count).to eq(6)
-
- migrate!
-
- expect(project_usages.where(new_amount_used: 0).count).to eq(2)
- expect(project_usages.order(:id).pluck(:new_amount_used))
- .to contain_exactly(0, 0, 10, 20, 30, 40)
- end
-end