summaryrefslogtreecommitdiff
path: root/spec/migrations
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-10-20 08:43:02 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-10-20 08:43:02 +0000
commitd9ab72d6080f594d0b3cae15f14b3ef2c6c638cb (patch)
tree2341ef426af70ad1e289c38036737e04b0aa5007 /spec/migrations
parentd6e514dd13db8947884cd58fe2a9c2a063400a9b (diff)
downloadgitlab-ce-d9ab72d6080f594d0b3cae15f14b3ef2c6c638cb.tar.gz
Add latest changes from gitlab-org/gitlab@14-4-stable-eev14.4.0-rc42
Diffstat (limited to 'spec/migrations')
-rw-r--r--spec/migrations/20190924152703_migrate_issue_trackers_data_spec.rb64
-rw-r--r--spec/migrations/20191015154408_drop_merge_requests_require_code_owner_approval_from_projects_spec.rb56
-rw-r--r--spec/migrations/20191125114345_add_admin_mode_protected_path_spec.rb49
-rw-r--r--spec/migrations/20191204114127_delete_legacy_triggers_spec.rb23
-rw-r--r--spec/migrations/20210906130643_drop_temporary_columns_and_triggers_for_taggings_spec.rb23
-rw-r--r--spec/migrations/20210907013944_cleanup_bigint_conversion_for_ci_builds_metadata_spec.rb23
-rw-r--r--spec/migrations/20210910194952_update_report_type_for_existing_approval_project_rules_spec.rb48
-rw-r--r--spec/migrations/20210915022415_cleanup_bigint_conversion_for_ci_builds_spec.rb23
-rw-r--r--spec/migrations/20210918201050_remove_old_pending_jobs_for_recalculate_vulnerabilities_occurrences_uuid_spec.rb45
-rw-r--r--spec/migrations/20210918202855_reschedule_pending_jobs_for_recalculate_vulnerabilities_occurrences_uuid_spec.rb30
-rw-r--r--spec/migrations/20210922021816_drop_int4_columns_for_ci_job_artifacts_spec.rb23
-rw-r--r--spec/migrations/20210922025631_drop_int4_column_for_ci_sources_pipelines_spec.rb21
-rw-r--r--spec/migrations/20210922082019_drop_int4_column_for_events_spec.rb21
-rw-r--r--spec/migrations/20210922091402_drop_int4_column_for_push_event_payloads_spec.rb21
-rw-r--r--spec/migrations/20211006060436_schedule_populate_topics_total_projects_count_cache_spec.rb29
-rw-r--r--spec/migrations/add_default_and_free_plans_spec.rb34
-rw-r--r--spec/migrations/add_unique_constraint_to_approvals_user_id_and_merge_request_id_spec.rb57
-rw-r--r--spec/migrations/backfill_and_add_not_null_constraint_to_released_at_column_on_releases_table_spec.rb28
-rw-r--r--spec/migrations/backfill_operations_feature_flags_active_spec.rb52
-rw-r--r--spec/migrations/backfill_releases_table_updated_at_and_add_not_null_constraints_to_timestamps_spec.rb57
-rw-r--r--spec/migrations/backport_enterprise_schema_spec.rb41
-rw-r--r--spec/migrations/change_outbound_local_requests_whitelist_default_spec.rb21
-rw-r--r--spec/migrations/change_packages_size_defaults_in_project_statistics_spec.rb35
-rw-r--r--spec/migrations/clean_up_noteable_id_for_notes_on_commits_spec.rb34
-rw-r--r--spec/migrations/cleanup_legacy_artifact_migration_spec.rb52
-rw-r--r--spec/migrations/drop_project_ci_cd_settings_merge_trains_enabled_spec.rb21
-rw-r--r--spec/migrations/encrypt_feature_flags_clients_tokens_spec.rb36
-rw-r--r--spec/migrations/encrypt_plaintext_attributes_on_application_settings_spec.rb58
-rw-r--r--spec/migrations/enqueue_reset_merge_status_second_run_spec.rb52
-rw-r--r--spec/migrations/enqueue_reset_merge_status_spec.rb52
-rw-r--r--spec/migrations/fill_productivity_analytics_start_date_spec.rb39
-rw-r--r--spec/migrations/fix_max_pages_size_spec.rb19
-rw-r--r--spec/migrations/fix_null_type_labels_spec.rb36
-rw-r--r--spec/migrations/fix_pool_repository_source_project_id_spec.rb29
-rw-r--r--spec/migrations/fix_wrong_pages_access_level_spec.rb99
-rw-r--r--spec/migrations/generate_lets_encrypt_private_key_spec.rb14
-rw-r--r--spec/migrations/insert_project_hooks_plan_limits_spec.rb67
-rw-r--r--spec/migrations/migrate_auto_dev_ops_domain_to_cluster_domain_spec.rb114
-rw-r--r--spec/migrations/migrate_code_owner_approval_status_to_protected_branches_in_batches_spec.rb63
-rw-r--r--spec/migrations/migrate_discussion_id_on_promoted_epics_spec.rb81
-rw-r--r--spec/migrations/migrate_k8s_service_integration_spec.rb162
-rw-r--r--spec/migrations/migrate_legacy_managed_clusters_to_unmanaged_spec.rb55
-rw-r--r--spec/migrations/migrate_managed_clusters_with_no_token_to_unmanaged_spec.rb59
-rw-r--r--spec/migrations/migrate_ops_feature_flags_scopes_target_user_ids_spec.rb135
-rw-r--r--spec/migrations/migrate_storage_migrator_sidekiq_queue_spec.rb43
-rw-r--r--spec/migrations/move_limits_from_plans_spec.rb35
-rw-r--r--spec/migrations/nullify_users_role_spec.rb33
-rw-r--r--spec/migrations/populate_project_statistics_packages_size_spec.rb37
-rw-r--r--spec/migrations/populate_rule_type_on_approval_merge_request_rules_spec.rb39
-rw-r--r--spec/migrations/recreate_index_security_ci_builds_on_name_and_id_parser_features_spec.rb28
-rw-r--r--spec/migrations/remove_empty_github_service_templates_spec.rb55
-rw-r--r--spec/migrations/remove_schedule_and_status_from_pending_alert_escalations_spec.rb37
-rw-r--r--spec/migrations/schedule_fill_valid_time_for_pages_domain_certificates_spec.rb48
-rw-r--r--spec/migrations/schedule_pages_metadata_migration_spec.rb29
-rw-r--r--spec/migrations/schedule_populate_merge_request_assignees_table_spec.rb47
-rw-r--r--spec/migrations/schedule_populate_status_column_of_security_scans_spec.rb48
-rw-r--r--spec/migrations/schedule_sync_issuables_state_id_spec.rb81
-rw-r--r--spec/migrations/schedule_sync_issuables_state_id_where_nil_spec.rb57
-rw-r--r--spec/migrations/set_issue_id_for_all_versions_spec.rb38
-rw-r--r--spec/migrations/sync_issuables_state_id_spec.rb41
-rw-r--r--spec/migrations/truncate_user_fullname_spec.rb23
-rw-r--r--spec/migrations/update_minimum_password_length_spec.rb30
62 files changed, 420 insertions, 2430 deletions
diff --git a/spec/migrations/20190924152703_migrate_issue_trackers_data_spec.rb b/spec/migrations/20190924152703_migrate_issue_trackers_data_spec.rb
deleted file mode 100644
index dad95760306..00000000000
--- a/spec/migrations/20190924152703_migrate_issue_trackers_data_spec.rb
+++ /dev/null
@@ -1,64 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-require_migration!('migrate_issue_trackers_data')
-
-RSpec.describe MigrateIssueTrackersData do
- let(:services) { table(:services) }
- let(:migration_class) { Gitlab::BackgroundMigration::MigrateIssueTrackersSensitiveData }
- let(:migration_name) { migration_class.to_s.demodulize }
-
- let(:properties) do
- {
- 'url' => 'http://example.com'
- }
- end
-
- let!(:jira_integration) do
- services.create!(type: 'JiraService', properties: properties, category: 'issue_tracker')
- end
-
- let!(:jira_integration_nil) do
- services.create!(type: 'JiraService', properties: nil, category: 'issue_tracker')
- end
-
- let!(:bugzilla_integration) do
- services.create!(type: 'BugzillaService', properties: properties, category: 'issue_tracker')
- end
-
- let!(:youtrack_integration) do
- services.create!(type: 'YoutrackService', properties: properties, category: 'issue_tracker')
- end
-
- let!(:youtrack_integration_empty) do
- services.create!(type: 'YoutrackService', properties: '', category: 'issue_tracker')
- end
-
- let!(:gitlab_service) do
- services.create!(type: 'GitlabIssueTrackerService', properties: properties, category: 'issue_tracker')
- end
-
- let!(:gitlab_service_empty) do
- services.create!(type: 'GitlabIssueTrackerService', properties: {}, category: 'issue_tracker')
- end
-
- let!(:other_service) do
- services.create!(type: 'OtherService', properties: properties, category: 'other_category')
- end
-
- before do
- stub_const("#{described_class}::BATCH_SIZE", 2)
- end
-
- it 'schedules background migrations at correct time' do
- Sidekiq::Testing.fake! do
- freeze_time do
- migrate!
-
- expect(migration_name).to be_scheduled_delayed_migration(3.minutes, jira_integration.id, bugzilla_integration.id)
- expect(migration_name).to be_scheduled_delayed_migration(6.minutes, youtrack_integration.id, gitlab_service.id)
- expect(BackgroundMigrationWorker.jobs.size).to eq(2)
- end
- end
- end
-end
diff --git a/spec/migrations/20191015154408_drop_merge_requests_require_code_owner_approval_from_projects_spec.rb b/spec/migrations/20191015154408_drop_merge_requests_require_code_owner_approval_from_projects_spec.rb
deleted file mode 100644
index 731bc923910..00000000000
--- a/spec/migrations/20191015154408_drop_merge_requests_require_code_owner_approval_from_projects_spec.rb
+++ /dev/null
@@ -1,56 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-require_migration!('drop_merge_requests_require_code_owner_approval_from_projects')
-
-RSpec.describe DropMergeRequestsRequireCodeOwnerApprovalFromProjects do
- let(:projects_table) { table(:projects) }
-
- subject(:migration) { described_class.new }
-
- describe "without running the migration" do
- it "project_table has a :merge_requests_require_code_owner_approval column" do
- expect(projects_table.column_names)
- .to include("merge_requests_require_code_owner_approval")
- end
-
- it "project_table has a :projects_requiring_code_owner_approval index" do
- expect(ActiveRecord::Base.connection.indexes(:projects).collect(&:name))
- .to include("projects_requiring_code_owner_approval")
- end
- end
-
- describe '#up' do
- context "without running "
- before do
- migrate!
- end
-
- it "drops the :merge_requests_require_code_owner_approval column" do
- expect(projects_table.column_names)
- .not_to include("merge_requests_require_code_owner_approval")
- end
-
- it "drops the :projects_requiring_code_owner_approval index" do
- expect(ActiveRecord::Base.connection.indexes(:projects).collect(&:name))
- .not_to include("projects_requiring_code_owner_approval")
- end
- end
-
- describe "#down" do
- before do
- migration.up
- migration.down
- end
-
- it "project_table has a :merge_requests_require_code_owner_approval column" do
- expect(projects_table.column_names)
- .to include("merge_requests_require_code_owner_approval")
- end
-
- it "project_table has a :projects_requiring_code_owner_approval index" do
- expect(ActiveRecord::Base.connection.indexes(:projects).collect(&:name))
- .to include("projects_requiring_code_owner_approval")
- end
- end
-end
diff --git a/spec/migrations/20191125114345_add_admin_mode_protected_path_spec.rb b/spec/migrations/20191125114345_add_admin_mode_protected_path_spec.rb
deleted file mode 100644
index 222a000c134..00000000000
--- a/spec/migrations/20191125114345_add_admin_mode_protected_path_spec.rb
+++ /dev/null
@@ -1,49 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-require_migration!('add_admin_mode_protected_path')
-
-RSpec.describe AddAdminModeProtectedPath do
- subject(:migration) { described_class.new }
-
- let(:admin_mode_endpoint) { '/admin/session' }
- let(:application_settings) { table(:application_settings) }
-
- context 'no settings available' do
- it 'makes no changes' do
- expect { migrate! }.not_to change { application_settings.count }
- end
- end
-
- context 'protected_paths is null' do
- before do
- application_settings.create!(protected_paths: nil)
- end
-
- it 'makes no changes' do
- expect { migrate! }.not_to change { application_settings.first.protected_paths }
- end
- end
-
- it 'appends admin mode endpoint' do
- application_settings.create!(protected_paths: '{a,b,c}')
-
- protected_paths_before = %w[a b c]
- protected_paths_after = protected_paths_before.dup << admin_mode_endpoint
-
- expect { migrate! }.to change { application_settings.first.protected_paths }.from(protected_paths_before).to(protected_paths_after)
- end
-
- it 'new default includes admin mode endpoint' do
- settings_before = application_settings.create!
-
- expect(settings_before.protected_paths).not_to include(admin_mode_endpoint)
-
- migrate!
-
- application_settings.reset_column_information
- settings_after = application_settings.create!
-
- expect(settings_after.protected_paths).to include(admin_mode_endpoint)
- end
-end
diff --git a/spec/migrations/20191204114127_delete_legacy_triggers_spec.rb b/spec/migrations/20191204114127_delete_legacy_triggers_spec.rb
deleted file mode 100644
index aba3a902888..00000000000
--- a/spec/migrations/20191204114127_delete_legacy_triggers_spec.rb
+++ /dev/null
@@ -1,23 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-require_migration!('delete_legacy_triggers')
-
-RSpec.describe DeleteLegacyTriggers, schema: 2019_11_25_140458 do
- let(:ci_trigger_table) { table(:ci_triggers) }
- let(:user) { table(:users).create!(name: 'test', email: 'test@example.com', projects_limit: 1) }
-
- before do
- @trigger_with_user = ci_trigger_table.create!(owner_id: user.id)
- ci_trigger_table.create!(owner_id: nil)
- ci_trigger_table.create!(owner_id: nil)
- end
-
- it 'removes legacy triggers which has null owner_id' do
- expect do
- migrate!
- end.to change(ci_trigger_table, :count).by(-2)
-
- expect(ci_trigger_table.all).to eq([@trigger_with_user])
- end
-end
diff --git a/spec/migrations/20210906130643_drop_temporary_columns_and_triggers_for_taggings_spec.rb b/spec/migrations/20210906130643_drop_temporary_columns_and_triggers_for_taggings_spec.rb
new file mode 100644
index 00000000000..2e7ce733373
--- /dev/null
+++ b/spec/migrations/20210906130643_drop_temporary_columns_and_triggers_for_taggings_spec.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+require_migration!('drop_temporary_columns_and_triggers_for_taggings')
+
+RSpec.describe DropTemporaryColumnsAndTriggersForTaggings do
+ let(:taggings_table) { table(:taggings) }
+
+ it 'correctly migrates up and down' do
+ reversible_migration do |migration|
+ migration.before -> {
+ expect(taggings_table.column_names).to include('id_convert_to_bigint')
+ expect(taggings_table.column_names).to include('taggable_id_convert_to_bigint')
+ }
+
+ migration.after -> {
+ taggings_table.reset_column_information
+ expect(taggings_table.column_names).not_to include('id_convert_to_bigint')
+ expect(taggings_table.column_names).not_to include('taggable_id_convert_to_bigint')
+ }
+ end
+ end
+end
diff --git a/spec/migrations/20210907013944_cleanup_bigint_conversion_for_ci_builds_metadata_spec.rb b/spec/migrations/20210907013944_cleanup_bigint_conversion_for_ci_builds_metadata_spec.rb
new file mode 100644
index 00000000000..ece5ed8251d
--- /dev/null
+++ b/spec/migrations/20210907013944_cleanup_bigint_conversion_for_ci_builds_metadata_spec.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+require_migration!('cleanup_bigint_conversion_for_ci_builds_metadata')
+
+RSpec.describe CleanupBigintConversionForCiBuildsMetadata do
+ let(:ci_builds_metadata) { table(:ci_builds_metadata) }
+
+ it 'correctly migrates up and down' do
+ reversible_migration do |migration|
+ migration.before -> {
+ expect(ci_builds_metadata.column_names).to include('id_convert_to_bigint')
+ expect(ci_builds_metadata.column_names).to include('build_id_convert_to_bigint')
+ }
+
+ migration.after -> {
+ ci_builds_metadata.reset_column_information
+ expect(ci_builds_metadata.column_names).not_to include('id_convert_to_bigint')
+ expect(ci_builds_metadata.column_names).not_to include('build_id_convert_to_bigint')
+ }
+ end
+ end
+end
diff --git a/spec/migrations/20210910194952_update_report_type_for_existing_approval_project_rules_spec.rb b/spec/migrations/20210910194952_update_report_type_for_existing_approval_project_rules_spec.rb
new file mode 100644
index 00000000000..46a6d8d92ec
--- /dev/null
+++ b/spec/migrations/20210910194952_update_report_type_for_existing_approval_project_rules_spec.rb
@@ -0,0 +1,48 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+require_migration!('update_report_type_for_existing_approval_project_rules')
+
+RSpec.describe UpdateReportTypeForExistingApprovalProjectRules, :migration do
+ using RSpec::Parameterized::TableSyntax
+
+ let(:group) { table(:namespaces).create!(name: 'user', path: 'user') }
+ let(:project) { table(:projects).create!(namespace_id: group.id) }
+ let(:approval_project_rule) { table(:approval_project_rules).create!(name: rule_name, rule_type: rule_type, project_id: project.id) }
+ let(:rule_type) { 2 }
+ let(:rule_name) { 'Vulnerability-Check' }
+
+ context 'with rule_type set to :report_approver' do
+ where(:rule_name, :report_type) do
+ [
+ ['Vulnerability-Check', 1],
+ ['License-Check', 2],
+ ['Coverage-Check', 3]
+ ]
+ end
+
+ with_them do
+ context "with names associated with report type" do
+ it 'updates report_type' do
+ expect { migrate! }.to change { approval_project_rule.reload.report_type }.from(nil).to(report_type)
+ end
+ end
+ end
+ end
+
+ context 'with rule_type set to another value (e.g., :regular)' do
+ let(:rule_type) { 0 }
+
+ it 'does not update report_type' do
+ expect { migrate! }.not_to change { approval_project_rule.reload.report_type }
+ end
+ end
+
+ context 'with the rule name set to another value (e.g., Test Rule)' do
+ let(:rule_name) { 'Test Rule'}
+
+ it 'does not update report_type' do
+ expect { migrate! }.not_to change { approval_project_rule.reload.report_type }
+ end
+ end
+end
diff --git a/spec/migrations/20210915022415_cleanup_bigint_conversion_for_ci_builds_spec.rb b/spec/migrations/20210915022415_cleanup_bigint_conversion_for_ci_builds_spec.rb
new file mode 100644
index 00000000000..ee71322433d
--- /dev/null
+++ b/spec/migrations/20210915022415_cleanup_bigint_conversion_for_ci_builds_spec.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+require_migration!('cleanup_bigint_conversion_for_ci_builds')
+
+RSpec.describe CleanupBigintConversionForCiBuilds do
+ let(:ci_builds) { table(:ci_builds) }
+
+ it 'correctly migrates up and down' do
+ reversible_migration do |migration|
+ migration.before -> {
+ expect(ci_builds.column_names).to include('id_convert_to_bigint')
+ expect(ci_builds.column_names).to include('stage_id_convert_to_bigint')
+ }
+
+ migration.after -> {
+ ci_builds.reset_column_information
+ expect(ci_builds.column_names).not_to include('id_convert_to_bigint')
+ expect(ci_builds.column_names).not_to include('stage_id_convert_to_bigint')
+ }
+ end
+ end
+end
diff --git a/spec/migrations/20210918201050_remove_old_pending_jobs_for_recalculate_vulnerabilities_occurrences_uuid_spec.rb b/spec/migrations/20210918201050_remove_old_pending_jobs_for_recalculate_vulnerabilities_occurrences_uuid_spec.rb
new file mode 100644
index 00000000000..9addaaf2551
--- /dev/null
+++ b/spec/migrations/20210918201050_remove_old_pending_jobs_for_recalculate_vulnerabilities_occurrences_uuid_spec.rb
@@ -0,0 +1,45 @@
+# frozen_string_literal: true
+require 'spec_helper'
+require Rails.root.join('db', 'post_migrate', '20210918201050_remove_old_pending_jobs_for_recalculate_vulnerabilities_occurrences_uuid.rb')
+
+def create_background_migration_jobs(ids, status, created_at)
+ proper_status = case status
+ when :pending
+ Gitlab::Database::BackgroundMigrationJob.statuses['pending']
+ when :succeeded
+ Gitlab::Database::BackgroundMigrationJob.statuses['succeeded']
+ else
+ raise ArgumentError
+ end
+
+ background_migration_jobs.create!(
+ class_name: 'RecalculateVulnerabilitiesOccurrencesUuid',
+ arguments: Array(ids),
+ status: proper_status,
+ created_at: created_at
+ )
+end
+
+RSpec.describe RemoveOldPendingJobsForRecalculateVulnerabilitiesOccurrencesUuid, :migration do
+ let_it_be(:background_migration_jobs) { table(:background_migration_jobs) }
+ let_it_be(:before_target_date) { -Float::INFINITY..(DateTime.new(2021, 8, 17, 23, 59, 59)) }
+ let_it_be(:after_target_date) { (DateTime.new(2021, 8, 18, 0, 0, 0))..Float::INFINITY }
+
+ context 'when old RecalculateVulnerabilitiesOccurrencesUuid jobs are pending' do
+ before do
+ create_background_migration_jobs([1, 2, 3], :succeeded, DateTime.new(2021, 5, 5, 0, 2))
+ create_background_migration_jobs([4, 5, 6], :pending, DateTime.new(2021, 5, 5, 0, 4))
+
+ create_background_migration_jobs([1, 2, 3], :succeeded, DateTime.new(2021, 8, 18, 0, 0))
+ create_background_migration_jobs([4, 5, 6], :pending, DateTime.new(2021, 8, 18, 0, 2))
+ create_background_migration_jobs([7, 8, 9], :pending, DateTime.new(2021, 8, 18, 0, 4))
+ end
+
+ it 'removes old, pending jobs' do
+ migrate!
+
+ expect(background_migration_jobs.where(created_at: before_target_date).count).to eq(1)
+ expect(background_migration_jobs.where(created_at: after_target_date).count).to eq(3)
+ end
+ end
+end
diff --git a/spec/migrations/20210918202855_reschedule_pending_jobs_for_recalculate_vulnerabilities_occurrences_uuid_spec.rb b/spec/migrations/20210918202855_reschedule_pending_jobs_for_recalculate_vulnerabilities_occurrences_uuid_spec.rb
new file mode 100644
index 00000000000..5a2531bb63f
--- /dev/null
+++ b/spec/migrations/20210918202855_reschedule_pending_jobs_for_recalculate_vulnerabilities_occurrences_uuid_spec.rb
@@ -0,0 +1,30 @@
+# frozen_string_literal: true
+require 'spec_helper'
+require Rails.root.join('db', 'post_migrate', '20210918202855_reschedule_pending_jobs_for_recalculate_vulnerabilities_occurrences_uuid.rb')
+
+RSpec.describe ReschedulePendingJobsForRecalculateVulnerabilitiesOccurrencesUuid, :migration do
+ let_it_be(:background_migration_jobs) { table(:background_migration_jobs) }
+
+ context 'when RecalculateVulnerabilitiesOccurrencesUuid jobs are pending' do
+ before do
+ background_migration_jobs.create!(
+ class_name: 'RecalculateVulnerabilitiesOccurrencesUuid',
+ arguments: [1, 2, 3],
+ status: Gitlab::Database::BackgroundMigrationJob.statuses['pending']
+ )
+ background_migration_jobs.create!(
+ class_name: 'RecalculateVulnerabilitiesOccurrencesUuid',
+ arguments: [4, 5, 6],
+ status: Gitlab::Database::BackgroundMigrationJob.statuses['succeeded']
+ )
+ end
+
+ it 'queues pending jobs' do
+ migrate!
+
+ expect(BackgroundMigrationWorker.jobs.length).to eq(1)
+ expect(BackgroundMigrationWorker.jobs[0]['args']).to eq(['RecalculateVulnerabilitiesOccurrencesUuid', [1, 2, 3]])
+ expect(BackgroundMigrationWorker.jobs[0]['at']).to be_nil
+ end
+ end
+end
diff --git a/spec/migrations/20210922021816_drop_int4_columns_for_ci_job_artifacts_spec.rb b/spec/migrations/20210922021816_drop_int4_columns_for_ci_job_artifacts_spec.rb
new file mode 100644
index 00000000000..cf326cf0c0a
--- /dev/null
+++ b/spec/migrations/20210922021816_drop_int4_columns_for_ci_job_artifacts_spec.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+require_migration!('drop_int4_columns_for_ci_job_artifacts')
+
+RSpec.describe DropInt4ColumnsForCiJobArtifacts do
+ let(:ci_job_artifacts) { table(:ci_job_artifacts) }
+
+ it 'correctly migrates up and down' do
+ reversible_migration do |migration|
+ migration.before -> {
+ expect(ci_job_artifacts.column_names).to include('id_convert_to_bigint')
+ expect(ci_job_artifacts.column_names).to include('job_id_convert_to_bigint')
+ }
+
+ migration.after -> {
+ ci_job_artifacts.reset_column_information
+ expect(ci_job_artifacts.column_names).not_to include('id_convert_to_bigint')
+ expect(ci_job_artifacts.column_names).not_to include('job_id_convert_to_bigint')
+ }
+ end
+ end
+end
diff --git a/spec/migrations/20210922025631_drop_int4_column_for_ci_sources_pipelines_spec.rb b/spec/migrations/20210922025631_drop_int4_column_for_ci_sources_pipelines_spec.rb
new file mode 100644
index 00000000000..00b922ee4f8
--- /dev/null
+++ b/spec/migrations/20210922025631_drop_int4_column_for_ci_sources_pipelines_spec.rb
@@ -0,0 +1,21 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+require_migration!('drop_int4_column_for_ci_sources_pipelines')
+
+RSpec.describe DropInt4ColumnForCiSourcesPipelines do
+ let(:ci_sources_pipelines) { table(:ci_sources_pipelines) }
+
+ it 'correctly migrates up and down' do
+ reversible_migration do |migration|
+ migration.before -> {
+ expect(ci_sources_pipelines.column_names).to include('source_job_id_convert_to_bigint')
+ }
+
+ migration.after -> {
+ ci_sources_pipelines.reset_column_information
+ expect(ci_sources_pipelines.column_names).not_to include('source_job_id_convert_to_bigint')
+ }
+ end
+ end
+end
diff --git a/spec/migrations/20210922082019_drop_int4_column_for_events_spec.rb b/spec/migrations/20210922082019_drop_int4_column_for_events_spec.rb
new file mode 100644
index 00000000000..412556fc283
--- /dev/null
+++ b/spec/migrations/20210922082019_drop_int4_column_for_events_spec.rb
@@ -0,0 +1,21 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+require_migration!('drop_int4_column_for_events')
+
+RSpec.describe DropInt4ColumnForEvents do
+ let(:events) { table(:events) }
+
+ it 'correctly migrates up and down' do
+ reversible_migration do |migration|
+ migration.before -> {
+ expect(events.column_names).to include('id_convert_to_bigint')
+ }
+
+ migration.after -> {
+ events.reset_column_information
+ expect(events.column_names).not_to include('id_convert_to_bigint')
+ }
+ end
+ end
+end
diff --git a/spec/migrations/20210922091402_drop_int4_column_for_push_event_payloads_spec.rb b/spec/migrations/20210922091402_drop_int4_column_for_push_event_payloads_spec.rb
new file mode 100644
index 00000000000..2b286e3e5e0
--- /dev/null
+++ b/spec/migrations/20210922091402_drop_int4_column_for_push_event_payloads_spec.rb
@@ -0,0 +1,21 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+require_migration!('drop_int4_column_for_push_event_payloads')
+
+RSpec.describe DropInt4ColumnForPushEventPayloads do
+ let(:push_event_payloads) { table(:push_event_payloads) }
+
+ it 'correctly migrates up and down' do
+ reversible_migration do |migration|
+ migration.before -> {
+ expect(push_event_payloads.column_names).to include('event_id_convert_to_bigint')
+ }
+
+ migration.after -> {
+ push_event_payloads.reset_column_information
+ expect(push_event_payloads.column_names).not_to include('event_id_convert_to_bigint')
+ }
+ end
+ end
+end
diff --git a/spec/migrations/20211006060436_schedule_populate_topics_total_projects_count_cache_spec.rb b/spec/migrations/20211006060436_schedule_populate_topics_total_projects_count_cache_spec.rb
new file mode 100644
index 00000000000..d07d9a71b06
--- /dev/null
+++ b/spec/migrations/20211006060436_schedule_populate_topics_total_projects_count_cache_spec.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+require_migration!('schedule_populate_topics_total_projects_count_cache')
+
+RSpec.describe SchedulePopulateTopicsTotalProjectsCountCache do
+ let(:topics) { table(:topics) }
+ let!(:topic_1) { topics.create!(name: 'Topic1') }
+ let!(:topic_2) { topics.create!(name: 'Topic2') }
+ let!(:topic_3) { topics.create!(name: 'Topic3') }
+
+ describe '#up' do
+ before do
+ stub_const("#{described_class}::BATCH_SIZE", 2)
+ end
+
+ it 'schedules BackfillProjectsWithCoverage background jobs', :aggregate_failures do
+ Sidekiq::Testing.fake! do
+ freeze_time do
+ migrate!
+
+ expect(described_class::MIGRATION).to be_scheduled_delayed_migration(2.minutes, topic_1.id, topic_2.id)
+ expect(described_class::MIGRATION).to be_scheduled_delayed_migration(4.minutes, topic_3.id, topic_3.id)
+ expect(BackgroundMigrationWorker.jobs.size).to eq(2)
+ end
+ end
+ end
+ end
+end
diff --git a/spec/migrations/add_default_and_free_plans_spec.rb b/spec/migrations/add_default_and_free_plans_spec.rb
deleted file mode 100644
index 7256e4928af..00000000000
--- a/spec/migrations/add_default_and_free_plans_spec.rb
+++ /dev/null
@@ -1,34 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-require_migration!('add_default_and_free_plans')
-
-RSpec.describe AddDefaultAndFreePlans do
- describe 'migrate' do
- let(:plans) { table(:plans) }
-
- context 'when on Gitlab.com' do
- before do
- expect(Gitlab).to receive(:com?) { true }
- end
-
- it 'creates free and default plans' do
- expect { migrate! }.to change { plans.count }.by 2
-
- expect(plans.last(2).pluck(:name)).to eq %w[free default]
- end
- end
-
- context 'when on self-hosted' do
- before do
- expect(Gitlab).to receive(:com?) { false }
- end
-
- it 'creates only a default plan' do
- expect { migrate! }.to change { plans.count }.by 1
-
- expect(plans.last.name).to eq 'default'
- end
- end
- end
-end
diff --git a/spec/migrations/add_unique_constraint_to_approvals_user_id_and_merge_request_id_spec.rb b/spec/migrations/add_unique_constraint_to_approvals_user_id_and_merge_request_id_spec.rb
deleted file mode 100644
index 795de51d387..00000000000
--- a/spec/migrations/add_unique_constraint_to_approvals_user_id_and_merge_request_id_spec.rb
+++ /dev/null
@@ -1,57 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-require_migration!
-
-RSpec.describe AddUniqueConstraintToApprovalsUserIdAndMergeRequestId do
- let(:migration) { described_class.new }
- let(:namespaces) { table(:namespaces) }
- let(:projects) { table(:projects) }
- let(:merge_requests) { table(:merge_requests) }
- let(:approvals) { table(:approvals) }
-
- describe '#up' do
- before do
- namespaces.create!(id: 1, name: 'ns', path: 'ns')
- projects.create!(id: 1, namespace_id: 1)
- merge_requests.create!(id: 1, target_branch: 'master', source_branch: 'feature-1', target_project_id: 1)
- merge_requests.create!(id: 2, target_branch: 'master', source_branch: 'feature-2', target_project_id: 1)
- end
-
- it 'deletes duplicate records and keeps the first one' do
- first_approval = approvals.create!(id: 1, merge_request_id: 1, user_id: 1)
- approvals.create!(id: 2, merge_request_id: 1, user_id: 1)
-
- migration.up
-
- expect(approvals.all.to_a).to contain_exactly(first_approval)
- end
-
- it 'does not delete unique records' do
- unique_approvals = [
- approvals.create(id: 1, merge_request_id: 1, user_id: 1),
- approvals.create(id: 2, merge_request_id: 1, user_id: 2),
- approvals.create(id: 3, merge_request_id: 2, user_id: 1)
- ]
-
- migration.up
-
- expect(approvals.all.to_a).to contain_exactly(*unique_approvals)
- end
-
- it 'creates unique index' do
- migration.up
-
- expect(migration.index_exists?(:approvals, [:user_id, :merge_request_id], unique: true)).to be_truthy
- end
- end
-
- describe '#down' do
- it 'removes unique index' do
- migration.up
- migration.down
-
- expect(migration.index_exists?(:approvals, [:user_id, :merge_request_id], unique: true)).to be_falsey
- end
- end
-end
diff --git a/spec/migrations/backfill_and_add_not_null_constraint_to_released_at_column_on_releases_table_spec.rb b/spec/migrations/backfill_and_add_not_null_constraint_to_released_at_column_on_releases_table_spec.rb
deleted file mode 100644
index ea6599fc122..00000000000
--- a/spec/migrations/backfill_and_add_not_null_constraint_to_released_at_column_on_releases_table_spec.rb
+++ /dev/null
@@ -1,28 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-require_migration!
-
-RSpec.describe BackfillAndAddNotNullConstraintToReleasedAtColumnOnReleasesTable do
- let(:releases) { table(:releases) }
- let(:namespaces) { table(:namespaces) }
- let(:projects) { table(:projects) }
-
- subject(:migration) { described_class.new }
-
- it 'fills released_at with the value of created_at' do
- created_at_a = Time.zone.parse('2019-02-10T08:00:00Z')
- created_at_b = Time.zone.parse('2019-03-10T18:00:00Z')
- namespace = namespaces.create!(name: 'foo', path: 'foo')
- project = projects.create!(namespace_id: namespace.id)
- release_a = releases.create!(project_id: project.id, created_at: created_at_a)
- release_b = releases.create!(project_id: project.id, created_at: created_at_b)
-
- disable_migrations_output { migration.up }
-
- release_a.reload
- release_b.reload
- expect(release_a.released_at).to eq(created_at_a)
- expect(release_b.released_at).to eq(created_at_b)
- end
-end
diff --git a/spec/migrations/backfill_operations_feature_flags_active_spec.rb b/spec/migrations/backfill_operations_feature_flags_active_spec.rb
deleted file mode 100644
index a28f648c75a..00000000000
--- a/spec/migrations/backfill_operations_feature_flags_active_spec.rb
+++ /dev/null
@@ -1,52 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-require_migration!
-
-RSpec.describe BackfillOperationsFeatureFlagsActive do
- let(:namespaces) { table(:namespaces) }
- let(:projects) { table(:projects) }
- let(:flags) { table(:operations_feature_flags) }
-
- def setup
- namespace = namespaces.create!(name: 'foo', path: 'foo')
- projects.create!(namespace_id: namespace.id)
- end
-
- it 'executes successfully when there are no flags in the table' do
- setup
-
- disable_migrations_output { migrate! }
-
- expect(flags.count).to eq(0)
- end
-
- it 'updates active to true' do
- project = setup
- flag = flags.create!(project_id: project.id, name: 'test_flag', active: false)
-
- disable_migrations_output { migrate! }
-
- expect(flag.reload.active).to eq(true)
- end
-
- it 'updates active to true for multiple flags' do
- project = setup
- flag_a = flags.create!(project_id: project.id, name: 'test_flag', active: false)
- flag_b = flags.create!(project_id: project.id, name: 'other_flag', active: false)
-
- disable_migrations_output { migrate! }
-
- expect(flag_a.reload.active).to eq(true)
- expect(flag_b.reload.active).to eq(true)
- end
-
- it 'leaves active true if it is already true' do
- project = setup
- flag = flags.create!(project_id: project.id, name: 'test_flag', active: true)
-
- disable_migrations_output { migrate! }
-
- expect(flag.reload.active).to eq(true)
- end
-end
diff --git a/spec/migrations/backfill_releases_table_updated_at_and_add_not_null_constraints_to_timestamps_spec.rb b/spec/migrations/backfill_releases_table_updated_at_and_add_not_null_constraints_to_timestamps_spec.rb
deleted file mode 100644
index 6e8bcfc050d..00000000000
--- a/spec/migrations/backfill_releases_table_updated_at_and_add_not_null_constraints_to_timestamps_spec.rb
+++ /dev/null
@@ -1,57 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-require_migration!
-
-RSpec.describe BackfillReleasesTableUpdatedAtAndAddNotNullConstraintsToTimestamps do
- let(:releases) { table(:releases) }
- let(:namespaces) { table(:namespaces) }
- let(:projects) { table(:projects) }
-
- subject(:migration) { described_class.new }
-
- it 'fills null updated_at rows with the value of created_at' do
- created_at_a = Time.zone.parse('2014-03-11T04:30:00Z')
- created_at_b = Time.zone.parse('2019-09-10T12:00:00Z')
- namespace = namespaces.create!(name: 'foo', path: 'foo')
- project = projects.create!(namespace_id: namespace.id)
- release_a = releases.create!(project_id: project.id,
- released_at: Time.zone.parse('2014-12-10T06:00:00Z'),
- created_at: created_at_a)
- release_b = releases.create!(project_id: project.id,
- released_at: Time.zone.parse('2019-09-11T06:00:00Z'),
- created_at: created_at_b)
- release_a.update!(updated_at: nil)
- release_b.update!(updated_at: nil)
-
- disable_migrations_output { migrate! }
-
- release_a.reload
- release_b.reload
- expect(release_a.updated_at).to eq(created_at_a)
- expect(release_b.updated_at).to eq(created_at_b)
- end
-
- it 'does not change updated_at columns with a value' do
- created_at_a = Time.zone.parse('2014-03-11T04:30:00Z')
- updated_at_a = Time.zone.parse('2015-01-16T10:00:00Z')
- created_at_b = Time.zone.parse('2019-09-10T12:00:00Z')
- namespace = namespaces.create!(name: 'foo', path: 'foo')
- project = projects.create!(namespace_id: namespace.id)
- release_a = releases.create!(project_id: project.id,
- released_at: Time.zone.parse('2014-12-10T06:00:00Z'),
- created_at: created_at_a,
- updated_at: updated_at_a)
- release_b = releases.create!(project_id: project.id,
- released_at: Time.zone.parse('2019-09-11T06:00:00Z'),
- created_at: created_at_b)
- release_b.update!(updated_at: nil)
-
- disable_migrations_output { migrate! }
-
- release_a.reload
- release_b.reload
- expect(release_a.updated_at).to eq(updated_at_a)
- expect(release_b.updated_at).to eq(created_at_b)
- end
-end
diff --git a/spec/migrations/backport_enterprise_schema_spec.rb b/spec/migrations/backport_enterprise_schema_spec.rb
deleted file mode 100644
index de6821001b4..00000000000
--- a/spec/migrations/backport_enterprise_schema_spec.rb
+++ /dev/null
@@ -1,41 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-
-require_migration!
-
-RSpec.describe BackportEnterpriseSchema, schema: 20190329085614 do
- include MigrationsHelpers
-
- def drop_if_exists(table)
- active_record_base.connection.drop_table(table) if active_record_base.connection.table_exists?(table)
- end
-
- describe '#up' do
- it 'creates new EE tables' do
- migrate!
-
- expect(active_record_base.connection.table_exists?(:epics)).to be true
- expect(active_record_base.connection.table_exists?(:geo_nodes)).to be true
- end
-
- context 'missing EE columns' do
- before do
- drop_if_exists(:epics)
-
- active_record_base.connection.create_table "epics" do |t|
- t.integer :group_id, null: false, index: true
- t.integer :author_id, null: false, index: true
- end
- end
-
- after do
- drop_if_exists(:epics)
- end
-
- it 'flags an error' do
- expect { migrate! }.to raise_error(/Your database is missing.*that is present for GitLab EE/)
- end
- end
- end
-end
diff --git a/spec/migrations/change_outbound_local_requests_whitelist_default_spec.rb b/spec/migrations/change_outbound_local_requests_whitelist_default_spec.rb
deleted file mode 100644
index 24e6f3480f9..00000000000
--- a/spec/migrations/change_outbound_local_requests_whitelist_default_spec.rb
+++ /dev/null
@@ -1,21 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-require_migration!
-
-RSpec.describe ChangeOutboundLocalRequestsWhitelistDefault do
- let(:application_settings) { table(:application_settings) }
-
- it 'defaults to empty array' do
- setting = application_settings.create!
- setting_with_value = application_settings.create!(outbound_local_requests_whitelist: '{a,b}')
-
- expect(application_settings.where(outbound_local_requests_whitelist: nil).count).to eq(1)
-
- migrate!
-
- expect(application_settings.where(outbound_local_requests_whitelist: nil).count).to eq(0)
- expect(setting.reload.outbound_local_requests_whitelist).to eq([])
- expect(setting_with_value.reload.outbound_local_requests_whitelist).to eq(%w[a b])
- end
-end
diff --git a/spec/migrations/change_packages_size_defaults_in_project_statistics_spec.rb b/spec/migrations/change_packages_size_defaults_in_project_statistics_spec.rb
deleted file mode 100644
index 5e3118b0dea..00000000000
--- a/spec/migrations/change_packages_size_defaults_in_project_statistics_spec.rb
+++ /dev/null
@@ -1,35 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-require_migration!
-
-RSpec.describe ChangePackagesSizeDefaultsInProjectStatistics do
- let(:project_statistics) { table(:project_statistics) }
- let(:projects) { table(:projects) }
-
- it 'removes null packages_size' do
- stats_to_migrate = 10
-
- stats_to_migrate.times do |i|
- p = projects.create!(name: "project #{i}", namespace_id: 1)
- project_statistics.create!(project_id: p.id, namespace_id: p.namespace_id)
- end
-
- expect { migrate! }
- .to change { ProjectStatistics.where(packages_size: nil).count }
- .from(stats_to_migrate)
- .to(0)
- end
-
- it 'defaults packages_size to 0' do
- project = projects.create!(name: 'a new project', namespace_id: 2)
- stat = project_statistics.create!(project_id: project.id, namespace_id: project.namespace_id)
-
- expect(stat.packages_size).to be_nil
-
- migrate!
-
- stat.reload
- expect(stat.packages_size).to eq(0)
- end
-end
diff --git a/spec/migrations/clean_up_noteable_id_for_notes_on_commits_spec.rb b/spec/migrations/clean_up_noteable_id_for_notes_on_commits_spec.rb
deleted file mode 100644
index 8de30af13fd..00000000000
--- a/spec/migrations/clean_up_noteable_id_for_notes_on_commits_spec.rb
+++ /dev/null
@@ -1,34 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-require_migration!
-
-RSpec.describe CleanUpNoteableIdForNotesOnCommits do
- let(:notes) { table(:notes) }
-
- before do
- notes.create!(noteable_type: 'Commit', commit_id: '3d0a182204cece4857f81c6462720e0ad1af39c9', noteable_id: 3, note: 'Test')
- notes.create!(noteable_type: 'Commit', commit_id: '3d0a182204cece4857f81c6462720e0ad1af39c9', noteable_id: 3, note: 'Test')
- notes.create!(noteable_type: 'Commit', commit_id: '3d0a182204cece4857f81c6462720e0ad1af39c9', noteable_id: 3, note: 'Test')
-
- notes.create!(noteable_type: 'Issue', noteable_id: 1, note: 'Test')
- notes.create!(noteable_type: 'MergeRequest', noteable_id: 1, note: 'Test')
- notes.create!(noteable_type: 'Snippet', noteable_id: 1, note: 'Test')
- end
-
- it 'clears noteable_id for notes on commits' do
- expect { migrate! }.to change { dirty_notes_on_commits.count }.from(3).to(0)
- end
-
- it 'does not clear noteable_id for other notes' do
- expect { migrate! }.not_to change { other_notes.count }
- end
-
- def dirty_notes_on_commits
- notes.where(noteable_type: 'Commit').where.not(noteable_id: nil)
- end
-
- def other_notes
- notes.where("noteable_type != 'Commit' AND noteable_id IS NOT NULL")
- end
-end
diff --git a/spec/migrations/cleanup_legacy_artifact_migration_spec.rb b/spec/migrations/cleanup_legacy_artifact_migration_spec.rb
deleted file mode 100644
index 6362965cc31..00000000000
--- a/spec/migrations/cleanup_legacy_artifact_migration_spec.rb
+++ /dev/null
@@ -1,52 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-require_migration!('cleanup_legacy_artifact_migration')
-
-RSpec.describe CleanupLegacyArtifactMigration, :redis do
- let(:migration) { spy('migration') }
-
- context 'when still legacy artifacts exist' do
- let(:namespaces) { table(:namespaces) }
- let(:projects) { table(:projects) }
- let(:pipelines) { table(:ci_pipelines) }
- let(:jobs) { table(:ci_builds) }
- let(:job_artifacts) { table(:ci_job_artifacts) }
- let(:namespace) { namespaces.create!(name: 'gitlab', path: 'gitlab-org') }
- let(:project) { projects.create!(name: 'gitlab', path: 'gitlab-ce', namespace_id: namespace.id) }
- let(:pipeline) { pipelines.create!(project_id: project.id, ref: 'master', sha: 'adf43c3a') }
- let(:archive_file_type) { Gitlab::BackgroundMigration::MigrateLegacyArtifacts::ARCHIVE_FILE_TYPE }
- let(:metadata_file_type) { Gitlab::BackgroundMigration::MigrateLegacyArtifacts::METADATA_FILE_TYPE }
- let(:local_store) { ::ObjectStorage::Store::LOCAL }
- let(:remote_store) { ::ObjectStorage::Store::REMOTE }
- let(:legacy_location) { Gitlab::BackgroundMigration::MigrateLegacyArtifacts::LEGACY_PATH_FILE_LOCATION }
-
- before do
- jobs.create!(id: 1, commit_id: pipeline.id, project_id: project.id, status: :success, artifacts_file: 'archive.zip')
- jobs.create!(id: 2, commit_id: pipeline.id, project_id: project.id, status: :failed, artifacts_metadata: 'metadata.gz')
- jobs.create!(id: 3, commit_id: pipeline.id, project_id: project.id, status: :failed, artifacts_file: 'archive.zip', artifacts_metadata: 'metadata.gz')
- jobs.create!(id: 4, commit_id: pipeline.id, project_id: project.id, status: :running)
- jobs.create!(id: 5, commit_id: pipeline.id, project_id: project.id, status: :success, artifacts_file: 'archive.zip', artifacts_file_store: remote_store, artifacts_metadata: 'metadata.gz')
- jobs.create!(id: 6, commit_id: pipeline.id, project_id: project.id, status: :failed, artifacts_file: 'archive.zip', artifacts_metadata: 'metadata.gz')
- end
-
- it 'steals sidekiq jobs from MigrateLegacyArtifacts background migration' do
- expect(Gitlab::BackgroundMigration).to receive(:steal).with('MigrateLegacyArtifacts')
-
- migrate!
- end
-
- it 'migrates legacy artifacts to ci_job_artifacts table' do
- migrate!
-
- expect(job_artifacts.order(:job_id, :file_type).pluck('project_id, job_id, file_type, file_store, size, expire_at, file, file_sha256, file_location'))
- .to eq([[project.id, 1, archive_file_type, local_store, nil, nil, 'archive.zip', nil, legacy_location],
- [project.id, 3, archive_file_type, local_store, nil, nil, 'archive.zip', nil, legacy_location],
- [project.id, 3, metadata_file_type, local_store, nil, nil, 'metadata.gz', nil, legacy_location],
- [project.id, 5, archive_file_type, remote_store, nil, nil, 'archive.zip', nil, legacy_location],
- [project.id, 5, metadata_file_type, local_store, nil, nil, 'metadata.gz', nil, legacy_location],
- [project.id, 6, archive_file_type, local_store, nil, nil, 'archive.zip', nil, legacy_location],
- [project.id, 6, metadata_file_type, local_store, nil, nil, 'metadata.gz', nil, legacy_location]])
- end
- end
-end
diff --git a/spec/migrations/drop_project_ci_cd_settings_merge_trains_enabled_spec.rb b/spec/migrations/drop_project_ci_cd_settings_merge_trains_enabled_spec.rb
deleted file mode 100644
index 3093cd85ced..00000000000
--- a/spec/migrations/drop_project_ci_cd_settings_merge_trains_enabled_spec.rb
+++ /dev/null
@@ -1,21 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-require_migration!
-
-RSpec.describe DropProjectCiCdSettingsMergeTrainsEnabled do
- let!(:project_ci_cd_setting) { table(:project_ci_cd_settings) }
-
- it 'correctly migrates up and down' do
- reversible_migration do |migration|
- migration.before -> {
- expect(project_ci_cd_setting.column_names).to include("merge_trains_enabled")
- }
-
- migration.after -> {
- project_ci_cd_setting.reset_column_information
- expect(project_ci_cd_setting.column_names).not_to include("merge_trains_enabled")
- }
- end
- end
-end
diff --git a/spec/migrations/encrypt_feature_flags_clients_tokens_spec.rb b/spec/migrations/encrypt_feature_flags_clients_tokens_spec.rb
deleted file mode 100644
index 62bd0dafb8e..00000000000
--- a/spec/migrations/encrypt_feature_flags_clients_tokens_spec.rb
+++ /dev/null
@@ -1,36 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-require_migration!
-
-RSpec.describe EncryptFeatureFlagsClientsTokens do
- let(:migration) { described_class.new }
- let(:feature_flags_clients) { table(:operations_feature_flags_clients) }
- let(:projects) { table(:projects) }
- let(:plaintext) { "secret-token" }
- let(:ciphertext) { Gitlab::CryptoHelper.aes256_gcm_encrypt(plaintext, nonce: Gitlab::CryptoHelper::AES256_GCM_IV_STATIC) }
-
- describe '#up' do
- it 'keeps plaintext token the same and populates token_encrypted if not present' do
- project = projects.create!(id: 123, name: 'gitlab1', path: 'gitlab1', namespace_id: 123)
- feature_flags_client = feature_flags_clients.create!(project_id: project.id, token: plaintext)
-
- migration.up
-
- expect(feature_flags_client.reload.token).to eq(plaintext)
- expect(feature_flags_client.reload.token_encrypted).to eq(ciphertext)
- end
- end
-
- describe '#down' do
- it 'decrypts encrypted token and saves it' do
- project = projects.create!(id: 123, name: 'gitlab1', path: 'gitlab1', namespace_id: 123)
- feature_flags_client = feature_flags_clients.create!(project_id: project.id, token_encrypted: ciphertext)
-
- migration.down
-
- expect(feature_flags_client.reload.token).to eq(plaintext)
- expect(feature_flags_client.reload.token_encrypted).to eq(ciphertext)
- end
- end
-end
diff --git a/spec/migrations/encrypt_plaintext_attributes_on_application_settings_spec.rb b/spec/migrations/encrypt_plaintext_attributes_on_application_settings_spec.rb
deleted file mode 100644
index 2e233816b8b..00000000000
--- a/spec/migrations/encrypt_plaintext_attributes_on_application_settings_spec.rb
+++ /dev/null
@@ -1,58 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-require_migration!
-
-RSpec.describe EncryptPlaintextAttributesOnApplicationSettings do
- let(:migration) { described_class.new }
- let(:application_settings) { table(:application_settings) }
- let(:plaintext) { 'secret-token' }
-
- plaintext_attributes = %w[
- akismet_api_key
- elasticsearch_aws_secret_access_key
- recaptcha_private_key
- recaptcha_site_key
- slack_app_secret
- slack_app_verification_token
- ].freeze
-
- describe '#up' do
- it 'encrypts token and saves it' do
- application_setting = application_settings.create!
- application_setting.update_columns(
- plaintext_attributes.each_with_object({}) do |plaintext_attribute, attributes|
- attributes[plaintext_attribute] = plaintext
- end
- )
-
- migration.up
-
- application_setting.reload
- plaintext_attributes.each do |plaintext_attribute|
- expect(application_setting[plaintext_attribute]).not_to be_nil
- expect(application_setting["encrypted_#{plaintext_attribute}"]).not_to be_nil
- expect(application_setting["encrypted_#{plaintext_attribute}_iv"]).not_to be_nil
- end
- end
- end
-
- describe '#down' do
- it 'decrypts encrypted token and saves it' do
- application_setting = application_settings.create!(
- plaintext_attributes.each_with_object({}) do |plaintext_attribute, attributes|
- attributes[plaintext_attribute] = plaintext
- end
- )
-
- migration.down
-
- application_setting.reload
- plaintext_attributes.each do |plaintext_attribute|
- expect(application_setting[plaintext_attribute]).to eq(plaintext)
- expect(application_setting["encrypted_#{plaintext_attribute}"]).to be_nil
- expect(application_setting["encrypted_#{plaintext_attribute}_iv"]).to be_nil
- end
- end
- end
-end
diff --git a/spec/migrations/enqueue_reset_merge_status_second_run_spec.rb b/spec/migrations/enqueue_reset_merge_status_second_run_spec.rb
deleted file mode 100644
index 49698f60964..00000000000
--- a/spec/migrations/enqueue_reset_merge_status_second_run_spec.rb
+++ /dev/null
@@ -1,52 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-require_migration!
-
-RSpec.describe EnqueueResetMergeStatusSecondRun do
- let(:namespaces) { table(:namespaces) }
- let(:projects) { table(:projects) }
- let(:namespace) { namespaces.create!(name: 'gitlab', path: 'gitlab-org') }
- let(:project) { projects.create!(namespace_id: namespace.id, name: 'foo') }
- let(:merge_requests) { table(:merge_requests) }
-
- def create_merge_request(id, extra_params = {})
- params = {
- id: id,
- target_project_id: project.id,
- target_branch: 'master',
- source_project_id: project.id,
- source_branch: 'mr name',
- title: "mr name#{id}"
- }.merge(extra_params)
-
- merge_requests.create!(params)
- end
-
- it 'correctly schedules background migrations' do
- create_merge_request(1, state: 'opened', merge_status: 'can_be_merged')
- create_merge_request(2, state: 'opened', merge_status: 'can_be_merged')
- create_merge_request(3, state: 'opened', merge_status: 'can_be_merged')
- create_merge_request(4, state: 'merged', merge_status: 'can_be_merged')
- create_merge_request(5, state: 'opened', merge_status: 'unchecked')
-
- stub_const("#{described_class.name}::BATCH_SIZE", 2)
-
- Sidekiq::Testing.fake! do
- freeze_time do
- migrate!
-
- expect(described_class::MIGRATION)
- .to be_scheduled_delayed_migration(5.minutes, 1, 2)
-
- expect(described_class::MIGRATION)
- .to be_scheduled_delayed_migration(10.minutes, 3, 4)
-
- expect(described_class::MIGRATION)
- .to be_scheduled_delayed_migration(15.minutes, 5, 5)
-
- expect(BackgroundMigrationWorker.jobs.size).to eq(3)
- end
- end
- end
-end
diff --git a/spec/migrations/enqueue_reset_merge_status_spec.rb b/spec/migrations/enqueue_reset_merge_status_spec.rb
deleted file mode 100644
index d62c99b80bc..00000000000
--- a/spec/migrations/enqueue_reset_merge_status_spec.rb
+++ /dev/null
@@ -1,52 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-require_migration!
-
-RSpec.describe EnqueueResetMergeStatus do
- let(:namespaces) { table(:namespaces) }
- let(:projects) { table(:projects) }
- let(:namespace) { namespaces.create!(name: 'gitlab', path: 'gitlab-org') }
- let(:project) { projects.create!(namespace_id: namespace.id, name: 'foo') }
- let(:merge_requests) { table(:merge_requests) }
-
- def create_merge_request(id, extra_params = {})
- params = {
- id: id,
- target_project_id: project.id,
- target_branch: 'master',
- source_project_id: project.id,
- source_branch: 'mr name',
- title: "mr name#{id}"
- }.merge(extra_params)
-
- merge_requests.create!(params)
- end
-
- it 'correctly schedules background migrations' do
- create_merge_request(1, state: 'opened', merge_status: 'can_be_merged')
- create_merge_request(2, state: 'opened', merge_status: 'can_be_merged')
- create_merge_request(3, state: 'opened', merge_status: 'can_be_merged')
- create_merge_request(4, state: 'merged', merge_status: 'can_be_merged')
- create_merge_request(5, state: 'opened', merge_status: 'unchecked')
-
- stub_const("#{described_class.name}::BATCH_SIZE", 2)
-
- Sidekiq::Testing.fake! do
- freeze_time do
- migrate!
-
- expect(described_class::MIGRATION)
- .to be_scheduled_delayed_migration(5.minutes, 1, 2)
-
- expect(described_class::MIGRATION)
- .to be_scheduled_delayed_migration(10.minutes, 3, 4)
-
- expect(described_class::MIGRATION)
- .to be_scheduled_delayed_migration(15.minutes, 5, 5)
-
- expect(BackgroundMigrationWorker.jobs.size).to eq(3)
- end
- end
- end
-end
diff --git a/spec/migrations/fill_productivity_analytics_start_date_spec.rb b/spec/migrations/fill_productivity_analytics_start_date_spec.rb
deleted file mode 100644
index b348067a752..00000000000
--- a/spec/migrations/fill_productivity_analytics_start_date_spec.rb
+++ /dev/null
@@ -1,39 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-require_migration!
-
-RSpec.describe FillProductivityAnalyticsStartDate do
- let(:settings_table) { table('application_settings') }
- let(:metrics_table) { table('merge_request_metrics') }
-
- before do
- settings_table.create!
- end
-
- context 'with NO productivity analytics data available' do
- it 'sets start_date to NOW' do
- expect { migrate! }.to change {
- settings_table.first&.productivity_analytics_start_date
- }.to(be_like_time(Time.now))
- end
- end
-
- context 'with productivity analytics data available' do
- before do
- ActiveRecord::Base.transaction do
- ActiveRecord::Base.connection.execute('ALTER TABLE merge_request_metrics DISABLE TRIGGER ALL')
- metrics_table.create!(merged_at: Time.parse('2019-09-09'), commits_count: nil, merge_request_id: 3)
- metrics_table.create!(merged_at: Time.parse('2019-10-10'), commits_count: 5, merge_request_id: 1)
- metrics_table.create!(merged_at: Time.parse('2019-11-11'), commits_count: 10, merge_request_id: 2)
- ActiveRecord::Base.connection.execute('ALTER TABLE merge_request_metrics ENABLE TRIGGER ALL')
- end
- end
-
- it 'set start_date to earliest merged_at value with PA data available' do
- expect { migrate! }.to change {
- settings_table.first&.productivity_analytics_start_date
- }.to(be_like_time(Time.parse('2019-10-10')))
- end
- end
-end
diff --git a/spec/migrations/fix_max_pages_size_spec.rb b/spec/migrations/fix_max_pages_size_spec.rb
deleted file mode 100644
index 97cf026df5c..00000000000
--- a/spec/migrations/fix_max_pages_size_spec.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-require_migration!
-
-RSpec.describe FixMaxPagesSize do
- let(:application_settings) { table(:application_settings) }
- let!(:default_setting) { application_settings.create! }
- let!(:max_possible_setting) { application_settings.create!(max_pages_size: described_class::MAX_SIZE) }
- let!(:higher_than_maximum_setting) { application_settings.create!(max_pages_size: described_class::MAX_SIZE + 1) }
-
- it 'correctly updates settings only if needed' do
- migrate!
-
- expect(default_setting.reload.max_pages_size).to eq(100)
- expect(max_possible_setting.reload.max_pages_size).to eq(described_class::MAX_SIZE)
- expect(higher_than_maximum_setting.reload.max_pages_size).to eq(described_class::MAX_SIZE)
- end
-end
diff --git a/spec/migrations/fix_null_type_labels_spec.rb b/spec/migrations/fix_null_type_labels_spec.rb
deleted file mode 100644
index 4f902b92393..00000000000
--- a/spec/migrations/fix_null_type_labels_spec.rb
+++ /dev/null
@@ -1,36 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-require_migration!
-
-RSpec.describe FixNullTypeLabels do
- let(:migration) { described_class.new }
- let(:projects) { table(:projects) }
- let(:namespaces) { table(:namespaces) }
- let(:labels) { table(:labels) }
-
- before do
- group = namespaces.create!(name: 'labels-test-project', path: 'labels-test-project', type: 'Group')
- project = projects.create!(namespace_id: group.id, name: 'labels-test-group', path: 'labels-test-group')
-
- @template_label = labels.create!(title: 'template', template: true)
- @project_label = labels.create!(title: 'project label', project_id: project.id, type: 'ProjectLabel')
- @group_label = labels.create!(title: 'group_label', group_id: group.id, type: 'GroupLabel')
- @broken_label_1 = labels.create!(title: 'broken 1', project_id: project.id)
- @broken_label_2 = labels.create!(title: 'broken 2', project_id: project.id)
- end
-
- describe '#up' do
- it 'fix labels with type missing' do
- migration.up
-
- # Labels that requires type change
- expect(@broken_label_1.reload.type).to eq('ProjectLabel')
- expect(@broken_label_2.reload.type).to eq('ProjectLabel')
- # Labels out of scope
- expect(@template_label.reload.type).to be_nil
- expect(@project_label.reload.type).to eq('ProjectLabel')
- expect(@group_label.reload.type).to eq('GroupLabel')
- end
- end
-end
diff --git a/spec/migrations/fix_pool_repository_source_project_id_spec.rb b/spec/migrations/fix_pool_repository_source_project_id_spec.rb
deleted file mode 100644
index 2ee4c458c3c..00000000000
--- a/spec/migrations/fix_pool_repository_source_project_id_spec.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-require_migration!
-
-RSpec.describe FixPoolRepositorySourceProjectId do
- let(:projects) { table(:projects) }
- let(:pool_repositories) { table(:pool_repositories) }
- let(:shards) { table(:shards) }
-
- it 'fills in source_project_ids' do
- shard = shards.create!(name: 'default')
-
- # gitaly is a project with a pool repository that has a source_project_id
- gitaly = projects.create!(name: 'gitaly', path: 'gitlab-org/gitaly', namespace_id: 1)
- pool_repository = pool_repositories.create!(shard_id: shard.id, source_project_id: gitaly.id)
- gitaly.update_column(:pool_repository_id, pool_repository.id)
-
- # gitlab is a project with a pool repository that's missing a source_project_id
- pool_repository_without_source_project = pool_repositories.create!(shard_id: shard.id, source_project_id: nil)
- gitlab = projects.create!(name: 'gitlab', path: 'gitlab-org/gitlab-ce', namespace_id: 1, pool_repository_id: pool_repository_without_source_project.id)
- projects.create!(name: 'gitlab-fork-1', path: 'my-org-1/gitlab-ce', namespace_id: 1, pool_repository_id: pool_repository_without_source_project.id)
-
- migrate!
-
- expect(pool_repositories.find(pool_repository_without_source_project.id).source_project_id).to eq(gitlab.id)
- expect(pool_repositories.find(pool_repository.id).source_project_id).to eq(gitaly.id)
- end
-end
diff --git a/spec/migrations/fix_wrong_pages_access_level_spec.rb b/spec/migrations/fix_wrong_pages_access_level_spec.rb
deleted file mode 100644
index 00a620b4426..00000000000
--- a/spec/migrations/fix_wrong_pages_access_level_spec.rb
+++ /dev/null
@@ -1,99 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-require_migration!
-
-RSpec.describe FixWrongPagesAccessLevel, :sidekiq_might_not_need_inline, schema: 20190628185004 do
- using RSpec::Parameterized::TableSyntax
-
- let(:migration_class) { described_class::MIGRATION }
- let(:migration_name) { migration_class.to_s.demodulize }
-
- project_class = ::Gitlab::BackgroundMigration::FixPagesAccessLevel::Project
- feature_class = ::Gitlab::BackgroundMigration::FixPagesAccessLevel::ProjectFeature
-
- let(:namespaces_table) { table(:namespaces) }
- let(:projects_table) { table(:projects) }
- let(:features_table) { table(:project_features) }
-
- let(:subgroup) do
- root_group = namespaces_table.create!(path: "group", name: "group")
- namespaces_table.create!(path: "subgroup", name: "group", parent_id: root_group.id)
- end
-
- def create_project_feature(path, project_visibility, pages_access_level)
- project = projects_table.create!(path: path, visibility_level: project_visibility,
- namespace_id: subgroup.id)
- features_table.create!(project_id: project.id, pages_access_level: pages_access_level)
- end
-
- it 'correctly schedules background migrations' do
- Sidekiq::Testing.fake! do
- freeze_time do
- first_id = create_project_feature("project1", project_class::PRIVATE, feature_class::PRIVATE).id
- last_id = create_project_feature("project2", project_class::PRIVATE, feature_class::PUBLIC).id
-
- migrate!
-
- expect(migration_name).to be_scheduled_delayed_migration(2.minutes, first_id, last_id)
- expect(BackgroundMigrationWorker.jobs.size).to eq(1)
- end
- end
- end
-
- def expect_migration
- expect do
- perform_enqueued_jobs do
- migrate!
- end
- end
- end
-
- where(:project_visibility, :pages_access_level, :access_control_is_enabled,
- :pages_deployed, :resulting_pages_access_level) do
- # update settings for public projects regardless of access_control being enabled
- project_class::PUBLIC | feature_class::PUBLIC | true | true | feature_class::ENABLED
- project_class::PUBLIC | feature_class::PUBLIC | false | true | feature_class::ENABLED
- # don't update public level for private and internal projects
- project_class::PRIVATE | feature_class::PUBLIC | true | true | feature_class::PUBLIC
- project_class::INTERNAL | feature_class::PUBLIC | true | true | feature_class::PUBLIC
-
- # if access control is disabled but pages are deployed we make them public
- project_class::INTERNAL | feature_class::ENABLED | false | true | feature_class::PUBLIC
- # don't change anything if one of the conditions is not satisfied
- project_class::INTERNAL | feature_class::ENABLED | true | true | feature_class::ENABLED
- project_class::INTERNAL | feature_class::ENABLED | true | false | feature_class::ENABLED
-
- # private projects
- # if access control is enabled update pages_access_level to private regardless of deployment
- project_class::PRIVATE | feature_class::ENABLED | true | true | feature_class::PRIVATE
- project_class::PRIVATE | feature_class::ENABLED | true | false | feature_class::PRIVATE
- # if access control is disabled and pages are deployed update pages_access_level to public
- project_class::PRIVATE | feature_class::ENABLED | false | true | feature_class::PUBLIC
- # if access control is disabled but pages aren't deployed update pages_access_level to private
- project_class::PRIVATE | feature_class::ENABLED | false | false | feature_class::PRIVATE
- end
-
- with_them do
- let!(:project_feature) do
- create_project_feature("projectpath", project_visibility, pages_access_level)
- end
-
- before do
- tested_path = File.join(Settings.pages.path, "group/subgroup/projectpath", "public")
- allow(Dir).to receive(:exist?).with(tested_path).and_return(pages_deployed)
-
- stub_pages_setting(access_control: access_control_is_enabled)
- end
-
- it "sets proper pages_access_level" do
- expect(project_feature.reload.pages_access_level).to eq(pages_access_level)
-
- perform_enqueued_jobs do
- migrate!
- end
-
- expect(project_feature.reload.pages_access_level).to eq(resulting_pages_access_level)
- end
- end
-end
diff --git a/spec/migrations/generate_lets_encrypt_private_key_spec.rb b/spec/migrations/generate_lets_encrypt_private_key_spec.rb
deleted file mode 100644
index 8525a7bbd1c..00000000000
--- a/spec/migrations/generate_lets_encrypt_private_key_spec.rb
+++ /dev/null
@@ -1,14 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-require_migration!
-
-RSpec.describe GenerateLetsEncryptPrivateKey do
- describe '#up' do
- it 'does not fail' do
- expect do
- described_class.new.up
- end.not_to raise_error
- end
- end
-end
diff --git a/spec/migrations/insert_project_hooks_plan_limits_spec.rb b/spec/migrations/insert_project_hooks_plan_limits_spec.rb
deleted file mode 100644
index 365dd679d76..00000000000
--- a/spec/migrations/insert_project_hooks_plan_limits_spec.rb
+++ /dev/null
@@ -1,67 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-require_migration!
-
-RSpec.describe InsertProjectHooksPlanLimits do
- let(:migration) { described_class.new }
- let(:plans) { table(:plans) }
- let(:plan_limits) { table(:plan_limits) }
-
- before do
- plans.create!(id: 34, name: 'free')
- plans.create!(id: 2, name: 'bronze')
- plans.create!(id: 3, name: 'silver')
- plans.create!(id: 4, name: 'gold')
- plan_limits.create!(plan_id: 34, ci_active_jobs: 5)
- end
-
- context 'when on Gitlab.com' do
- before do
- expect(Gitlab).to receive(:com?).at_most(:twice).and_return(true)
- end
-
- describe '#up' do
- it 'updates the project_hooks plan limits' do
- migration.up
-
- expect(plan_limits.pluck(:plan_id, :project_hooks, :ci_active_jobs))
- .to match_array([[34, 10, 5], [2, 20, 0], [3, 30, 0], [4, 100, 0]])
- end
- end
-
- describe '#down' do
- it 'updates the project_hooks plan limits to 0' do
- migration.up
- migration.down
-
- expect(plan_limits.pluck(:plan_id, :project_hooks, :ci_active_jobs))
- .to match_array([[34, 0, 5], [2, 0, 0], [3, 0, 0], [4, 0, 0]])
- end
- end
- end
-
- context 'when on self-hosted' do
- before do
- expect(Gitlab).to receive(:com?).and_return(false)
- end
-
- describe '#up' do
- it 'does not update the plan limits' do
- migration.up
-
- expect(plan_limits.pluck(:plan_id, :project_hooks, :ci_active_jobs))
- .to match_array([[34, 0, 5]])
- end
- end
-
- describe '#down' do
- it 'does not update the plan limits' do
- migration.down
-
- expect(plan_limits.pluck(:plan_id, :project_hooks, :ci_active_jobs))
- .to match_array([[34, 0, 5]])
- end
- end
- end
-end
diff --git a/spec/migrations/migrate_auto_dev_ops_domain_to_cluster_domain_spec.rb b/spec/migrations/migrate_auto_dev_ops_domain_to_cluster_domain_spec.rb
deleted file mode 100644
index a836fb4bfb9..00000000000
--- a/spec/migrations/migrate_auto_dev_ops_domain_to_cluster_domain_spec.rb
+++ /dev/null
@@ -1,114 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-require_migration!
-
-RSpec.describe MigrateAutoDevOpsDomainToClusterDomain do
- include MigrationHelpers::ClusterHelpers
-
- let(:migration) { described_class.new }
- let(:project_auto_devops_table) { table(:project_auto_devops) }
- let(:clusters_table) { table(:clusters) }
- let(:cluster_projects_table) { table(:cluster_projects) }
-
- # Following lets are needed by MigrationHelpers::ClusterHelpers
- let(:cluster_kubernetes_namespaces_table) { table(:clusters_kubernetes_namespaces) }
- let(:projects_table) { table(:projects) }
- let(:namespaces_table) { table(:namespaces) }
- let(:provider_gcp_table) { table(:cluster_providers_gcp) }
- let(:platform_kubernetes_table) { table(:cluster_platforms_kubernetes) }
-
- before do
- setup_cluster_projects_with_domain(quantity: 20, domain: domain)
- end
-
- context 'with ProjectAutoDevOps with no domain' do
- let(:domain) { nil }
-
- it 'does not update cluster project' do
- migrate!
-
- expect(clusters_without_domain.count).to eq(clusters_table.count)
- end
- end
-
- context 'with ProjectAutoDevOps with domain' do
- let(:domain) { 'example-domain.com' }
-
- it 'updates all cluster projects' do
- migrate!
-
- expect(clusters_with_domain.count).to eq(clusters_table.count)
- end
- end
-
- context 'when only some ProjectAutoDevOps have domain set' do
- let(:domain) { 'example-domain.com' }
-
- before do
- setup_cluster_projects_with_domain(quantity: 25, domain: nil)
- end
-
- it 'only updates specific cluster projects' do
- migrate!
-
- expect(clusters_with_domain.count).to eq(20)
-
- project_auto_devops_with_domain.each do |project_auto_devops|
- cluster_project = find_cluster_project(project_auto_devops.project_id)
- cluster = find_cluster(cluster_project.cluster_id)
-
- expect(cluster.domain).to be_present
- end
-
- expect(clusters_without_domain.count).to eq(25)
-
- project_auto_devops_without_domain.each do |project_auto_devops|
- cluster_project = find_cluster_project(project_auto_devops.project_id)
- cluster = find_cluster(cluster_project.cluster_id)
-
- expect(cluster.domain).not_to be_present
- end
- end
- end
-
- def setup_cluster_projects_with_domain(quantity:, domain:)
- create_cluster_project_list(quantity)
-
- cluster_projects = cluster_projects_table.last(quantity)
-
- cluster_projects.each do |cluster_project|
- specific_domain = "#{cluster_project.id}-#{domain}" if domain
-
- project_auto_devops_table.create!(
- project_id: cluster_project.project_id,
- enabled: true,
- domain: specific_domain
- )
- end
- end
-
- def find_cluster_project(project_id)
- cluster_projects_table.find_by(project_id: project_id)
- end
-
- def find_cluster(cluster_id)
- clusters_table.find_by(id: cluster_id)
- end
-
- def project_auto_devops_with_domain
- project_auto_devops_table.where.not("domain IS NULL OR domain = ''")
- end
-
- def project_auto_devops_without_domain
- project_auto_devops_table.where("domain IS NULL OR domain = ''")
- end
-
- def clusters_with_domain
- clusters_table.where.not("domain IS NULL OR domain = ''")
- end
-
- def clusters_without_domain
- clusters_table.where("domain IS NULL OR domain = ''")
- end
-end
diff --git a/spec/migrations/migrate_code_owner_approval_status_to_protected_branches_in_batches_spec.rb b/spec/migrations/migrate_code_owner_approval_status_to_protected_branches_in_batches_spec.rb
deleted file mode 100644
index 121ff3d6622..00000000000
--- a/spec/migrations/migrate_code_owner_approval_status_to_protected_branches_in_batches_spec.rb
+++ /dev/null
@@ -1,63 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-require_migration!
-
-RSpec.describe MigrateCodeOwnerApprovalStatusToProtectedBranchesInBatches do
- let(:namespaces) { table(:namespaces) }
- let(:projects) { table(:projects) }
- let(:protected_branches) { table(:protected_branches) }
-
- let(:namespace) do
- namespaces.create!(
- path: 'gitlab-instance-administrators',
- name: 'GitLab Instance Administrators'
- )
- end
-
- let(:project) do
- projects.create!(
- namespace_id: namespace.id,
- name: 'GitLab Instance Administration'
- )
- end
-
- let!(:protected_branch_1) do
- protected_branches.create!(
- name: "branch name",
- project_id: project.id
- )
- end
-
- describe '#up' do
- context "when there's no projects needing approval" do
- it "doesn't change any protected branch records" do
- expect { migrate! }
- .not_to change { ProtectedBranch.where(code_owner_approval_required: true).count }
- end
- end
-
- context "when there's a project needing approval" do
- let!(:project_needing_approval) do
- projects.create!(
- namespace_id: namespace.id,
- name: 'GitLab Instance Administration',
- merge_requests_require_code_owner_approval: true
- )
- end
-
- let!(:protected_branch_2) do
- protected_branches.create!(
- name: "branch name",
- project_id: project_needing_approval.id
- )
- end
-
- it "changes N protected branch records" do
- expect { migrate! }
- .to change { ProtectedBranch.where(code_owner_approval_required: true).count }
- .by(1)
- end
- end
- end
-end
diff --git a/spec/migrations/migrate_discussion_id_on_promoted_epics_spec.rb b/spec/migrations/migrate_discussion_id_on_promoted_epics_spec.rb
deleted file mode 100644
index e42baab9927..00000000000
--- a/spec/migrations/migrate_discussion_id_on_promoted_epics_spec.rb
+++ /dev/null
@@ -1,81 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-require_migration!
-
-RSpec.describe MigrateDiscussionIdOnPromotedEpics do
- let(:migration_class) { described_class::MIGRATION }
- let(:migration_name) { migration_class.to_s.demodulize }
-
- let(:namespaces) { table(:namespaces) }
- let(:projects) { table(:projects) }
- let(:users) { table(:users) }
- let(:issues) { table(:issues) }
- let(:epics) { table(:epics) }
- let(:notes) { table(:notes) }
- let(:system_note_metadata) { table(:system_note_metadata) }
-
- let(:user) { users.create!(email: 'test@example.com', projects_limit: 100, username: 'test') }
- let(:namespace) { namespaces.create!(name: 'gitlab', path: 'gitlab-org') }
-
- def create_promotion_note(model, id)
- note = create_note(model, id, { system: true,
- note: 'promoted from issue XXX' })
- system_note_metadata.create!(note_id: note.id, action: 'moved')
- end
-
- def create_epic
- epics.create!(author_id: user.id, iid: epics.maximum(:iid).to_i + 1,
- group_id: namespace.id,
- title: 'Epic with discussion',
- title_html: 'Epic with discussion')
- end
-
- def create_note(model, id, extra_params = {})
- params = {
- note: 'note',
- noteable_id: model.id,
- noteable_type: model.class.name,
- discussion_id: id
- }.merge(extra_params)
-
- notes.create!(params)
- end
-
- context 'with promoted epic' do
- let(:epic1) { create_epic }
- let!(:note1) { create_promotion_note(epic1, 'id1') }
-
- it 'correctly schedules background migrations in batches' do
- create_note(epic1, 'id2')
- create_note(epic1, 'id3')
-
- stub_const("#{described_class.name}::BATCH_SIZE", 2)
-
- Sidekiq::Testing.fake! do
- freeze_time do
- migrate!
-
- expect(migration_name).to be_scheduled_delayed_migration(2.minutes, %w(id1 id2))
- expect(migration_name).to be_scheduled_delayed_migration(4.minutes, %w(id3))
- expect(BackgroundMigrationWorker.jobs.size).to eq(2)
- end
- end
- end
-
- it 'schedules only promoted epics' do
- issue = issues.create!(description: 'first', state: 'opened')
- create_promotion_note(issue, 'id2')
- create_note(create_epic, 'id3')
-
- Sidekiq::Testing.fake! do
- freeze_time do
- migrate!
-
- expect(migration_name).to be_scheduled_delayed_migration(2.minutes, %w(id1))
- expect(BackgroundMigrationWorker.jobs.size).to eq(1)
- end
- end
- end
- end
-end
diff --git a/spec/migrations/migrate_k8s_service_integration_spec.rb b/spec/migrations/migrate_k8s_service_integration_spec.rb
deleted file mode 100644
index ba6071b72e4..00000000000
--- a/spec/migrations/migrate_k8s_service_integration_spec.rb
+++ /dev/null
@@ -1,162 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-require_migration!
-
-RSpec.describe MigrateK8sServiceIntegration do
- context 'template service' do
- context 'with namespace' do
- let!(:service) do
- MigrateK8sServiceIntegration::Service.create!(
- active: true,
- template: true,
- category: 'deployment',
- type: 'KubernetesService',
- properties: "{\"namespace\":\"prod\",\"api_url\":\"https://sample.kubernetes.com\",\"ca_pem\":\"ca_pem-sample\",\"token\":\"token-sample\"}"
- )
- end
-
- let(:cluster) { MigrateK8sServiceIntegration::Cluster.instance_type.last! }
- let(:platform) { cluster.platform_kubernetes }
-
- it 'migrates the KubernetesService template to Platform::Kubernetes' do
- expect { migrate! }.to change { MigrateK8sServiceIntegration::Cluster.count }.by(1)
-
- expect(cluster).to be_enabled
- expect(cluster).to be_user
- expect(cluster).not_to be_managed
- expect(cluster.environment_scope).to eq('*')
- expect(platform.api_url).to eq('https://sample.kubernetes.com')
- expect(platform.ca_cert).to eq('ca_pem-sample')
- expect(platform.namespace).to eq('prod')
- expect(platform.token).to eq('token-sample')
- end
- end
-
- context 'without namespace' do
- let!(:service) do
- MigrateK8sServiceIntegration::Service.create!(
- active: true,
- template: true,
- category: 'deployment',
- type: 'KubernetesService',
- properties: "{\"namespace\":\"\",\"api_url\":\"https://sample.kubernetes.com\",\"ca_pem\":\"ca_pem-sample\",\"token\":\"token-sample\"}"
- )
- end
-
- let(:cluster) { MigrateK8sServiceIntegration::Cluster.instance_type.last! }
- let(:platform) { cluster.platform_kubernetes }
-
- it 'migrates the KubernetesService template to Platform::Kubernetes' do
- expect { migrate! }.to change { MigrateK8sServiceIntegration::Cluster.count }.by(1)
-
- expect(cluster).to be_enabled
- expect(cluster).to be_user
- expect(cluster).not_to be_managed
- expect(cluster.environment_scope).to eq('*')
- expect(platform.api_url).to eq('https://sample.kubernetes.com')
- expect(platform.ca_cert).to eq('ca_pem-sample')
- expect(platform.namespace).to be_nil
- expect(platform.token).to eq('token-sample')
- end
- end
-
- context 'with nullified parameters' do
- let!(:service) do
- MigrateK8sServiceIntegration::Service.create!(
- active: true,
- template: true,
- category: 'deployment',
- type: 'KubernetesService',
- properties: "{}"
- )
- end
-
- it 'does not migrate the KubernetesService' do
- expect { migrate! }.not_to change { MigrateK8sServiceIntegration::Cluster.count }
- end
- end
-
- context 'when disabled' do
- let!(:service) do
- MigrateK8sServiceIntegration::Service.create!(
- active: false,
- template: true,
- category: 'deployment',
- type: 'KubernetesService',
- properties: "{\"namespace\":\"prod\",\"api_url\":\"https://sample.kubernetes.com\",\"ca_pem\":\"ca_pem-sample\",\"token\":\"token-sample\"}"
- )
- end
-
- let(:cluster) { MigrateK8sServiceIntegration::Cluster.instance_type.last! }
- let(:platform) { cluster.platform_kubernetes }
-
- it 'migrates the KubernetesService template to Platform::Kubernetes' do
- expect { migrate! }.to change { MigrateK8sServiceIntegration::Cluster.count }.by(1)
-
- expect(cluster).not_to be_enabled
- expect(cluster).to be_user
- expect(cluster).not_to be_managed
- expect(cluster.environment_scope).to eq('*')
- expect(platform.api_url).to eq('https://sample.kubernetes.com')
- expect(platform.ca_cert).to eq('ca_pem-sample')
- expect(platform.namespace).to eq('prod')
- expect(platform.token).to eq('token-sample')
- end
- end
-
- context 'when an instance cluster already exists' do
- let!(:service) do
- MigrateK8sServiceIntegration::Service.create!(
- active: true,
- template: true,
- category: 'deployment',
- type: 'KubernetesService',
- properties: "{\"namespace\":\"prod\",\"api_url\":\"https://sample.kubernetes.com\",\"ca_pem\":\"ca_pem-sample\",\"token\":\"token-sample\"}"
- )
- end
-
- let!(:existing_cluster) do
- MigrateK8sServiceIntegration::Cluster.create!(
- name: 'test-cluster',
- cluster_type: :instance_type,
- managed: true,
- provider_type: :user,
- platform_type: :kubernetes
- )
- end
-
- let(:new_cluster) { MigrateK8sServiceIntegration::Cluster.instance_type.last! }
- let(:platform) { new_cluster.platform_kubernetes }
-
- it 'migrates the KubernetesService template to disabled Platform::Kubernetes' do
- expect { migrate! }.to change { MigrateK8sServiceIntegration::Cluster.count }.by(1)
-
- expect(new_cluster).not_to be_enabled
- expect(new_cluster).to be_user
- expect(new_cluster).not_to be_managed
- expect(new_cluster.environment_scope).to eq('*')
- expect(platform.api_url).to eq('https://sample.kubernetes.com')
- expect(platform.ca_cert).to eq('ca_pem-sample')
- expect(platform.namespace).to eq('prod')
- expect(platform.token).to eq('token-sample')
- end
- end
- end
-
- context 'non-template service' do
- let!(:service) do
- MigrateK8sServiceIntegration::Service.create!(
- active: true,
- template: false,
- category: 'deployment',
- type: 'KubernetesService',
- properties: "{\"namespace\":\"prod\",\"api_url\":\"https://sample.kubernetes.com\",\"ca_pem\":\"ca_pem-sample\",\"token\":\"token-sample\"}"
- )
- end
-
- it 'does not migrate the KubernetesService' do
- expect { migrate! }.not_to change { MigrateK8sServiceIntegration::Cluster.count }
- end
- end
-end
diff --git a/spec/migrations/migrate_legacy_managed_clusters_to_unmanaged_spec.rb b/spec/migrations/migrate_legacy_managed_clusters_to_unmanaged_spec.rb
deleted file mode 100644
index 3d8685c7619..00000000000
--- a/spec/migrations/migrate_legacy_managed_clusters_to_unmanaged_spec.rb
+++ /dev/null
@@ -1,55 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-require_migration!
-
-RSpec.describe MigrateLegacyManagedClustersToUnmanaged do
- let(:cluster_type) { 'project_type' }
- let(:created_at) { 1.hour.ago }
-
- let!(:cluster) do
- table(:clusters).create!(
- name: 'cluster',
- cluster_type: described_class::Cluster.cluster_types[cluster_type],
- managed: true,
- created_at: created_at
- )
- end
-
- it 'marks the cluster as unmanaged' do
- migrate!
- expect(cluster.reload).not_to be_managed
- end
-
- context 'cluster is not project type' do
- let(:cluster_type) { 'group_type' }
-
- it 'does not update the cluster' do
- migrate!
- expect(cluster.reload).to be_managed
- end
- end
-
- context 'cluster has a kubernetes namespace associated' do
- before do
- table(:clusters_kubernetes_namespaces).create!(
- cluster_id: cluster.id,
- namespace: 'namespace'
- )
- end
-
- it 'does not update the cluster' do
- migrate!
- expect(cluster.reload).to be_managed
- end
- end
-
- context 'cluster was recently created' do
- let(:created_at) { 2.minutes.ago }
-
- it 'does not update the cluster' do
- migrate!
- expect(cluster.reload).to be_managed
- end
- end
-end
diff --git a/spec/migrations/migrate_managed_clusters_with_no_token_to_unmanaged_spec.rb b/spec/migrations/migrate_managed_clusters_with_no_token_to_unmanaged_spec.rb
deleted file mode 100644
index b753b84ae55..00000000000
--- a/spec/migrations/migrate_managed_clusters_with_no_token_to_unmanaged_spec.rb
+++ /dev/null
@@ -1,59 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-require_migration!
-
-RSpec.describe MigrateManagedClustersWithNoTokenToUnmanaged do
- let(:cluster_type) { 'project_type' }
- let(:created_at) { Date.new(2018, 11, 1).midnight }
-
- let!(:cluster) do
- table(:clusters).create!(
- name: 'cluster',
- cluster_type: described_class::Cluster.cluster_types[cluster_type],
- managed: true,
- created_at: created_at
- )
- end
-
- let!(:kubernetes_namespace) do
- table(:clusters_kubernetes_namespaces).create!(
- cluster_id: cluster.id,
- namespace: 'namespace'
- )
- end
-
- it 'marks the cluster as unmanaged' do
- migrate!
- expect(cluster.reload).not_to be_managed
- end
-
- context 'cluster is not project type' do
- let(:cluster_type) { 'group_type' }
-
- it 'does not update the cluster' do
- migrate!
- expect(cluster.reload).to be_managed
- end
- end
-
- context 'kubernetes namespace has a service account token' do
- before do
- kubernetes_namespace.update!(encrypted_service_account_token: "TOKEN")
- end
-
- it 'does not update the cluster' do
- migrate!
- expect(cluster.reload).to be_managed
- end
- end
-
- context 'cluster was created after the cutoff' do
- let(:created_at) { Date.new(2019, 1, 1).midnight }
-
- it 'does not update the cluster' do
- migrate!
- expect(cluster.reload).to be_managed
- end
- end
-end
diff --git a/spec/migrations/migrate_ops_feature_flags_scopes_target_user_ids_spec.rb b/spec/migrations/migrate_ops_feature_flags_scopes_target_user_ids_spec.rb
deleted file mode 100644
index 5caf03992dd..00000000000
--- a/spec/migrations/migrate_ops_feature_flags_scopes_target_user_ids_spec.rb
+++ /dev/null
@@ -1,135 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-require_migration!
-
-RSpec.describe MigrateOpsFeatureFlagsScopesTargetUserIds do
- let(:namespaces) { table(:namespaces) }
- let(:projects) { table(:projects) }
- let(:flags) { table(:operations_feature_flags) }
- let(:scopes) { table(:operations_feature_flag_scopes) }
-
- def setup
- namespace = namespaces.create!(name: 'foo', path: 'foo')
- project = projects.create!(namespace_id: namespace.id)
- flags.create!(project_id: project.id, active: true, name: 'test_flag')
- end
-
- it 'migrates successfully when there are no scopes in the database' do
- setup
-
- disable_migrations_output { migrate! }
-
- expect(scopes.count).to eq(0)
- end
-
- it 'migrates a disabled scope with gradualRolloutUserId and userWithId strategies' do
- flag = setup
- scope = scopes.create!(feature_flag_id: flag.id, active: false, strategies: [
- { name: 'gradualRolloutUserId', parameters: { groupId: 'default', percentage: '50' } },
- { name: 'userWithId', parameters: { userIds: '5' } }
- ])
-
- disable_migrations_output { migrate! }
-
- scope.reload
- expect(scope.active).to eq(true)
- expect(scope.strategies).to eq([{ 'name' => 'userWithId', 'parameters' => { 'userIds' => '5' } }])
- end
-
- it 'migrates a disabled scope with default and userWithId strategies' do
- flag = setup
- scope = scopes.create!(feature_flag_id: flag.id, active: false, strategies: [
- { name: 'default', parameters: {} },
- { name: 'userWithId', parameters: { userIds: 'amy@gmail.com,karen@gmail.com' } }
- ])
-
- disable_migrations_output { migrate! }
-
- scope.reload
- expect(scope.active).to eq(true)
- expect(scope.strategies).to eq([{ 'name' => 'userWithId', 'parameters' => { 'userIds' => 'amy@gmail.com,karen@gmail.com' } }])
- end
-
- it 'migrates an enabled scope with default and userWithId strategies' do
- flag = setup
- scope = scopes.create!(feature_flag_id: flag.id, active: true, strategies: [
- { name: 'default', parameters: {} },
- { name: 'userWithId', parameters: { userIds: 'tim' } }
- ])
-
- disable_migrations_output { migrate! }
-
- scope.reload
- expect(scope.active).to eq(true)
- expect(scope.strategies).to eq([{ 'name' => 'default', 'parameters' => {} }])
- end
-
- it 'does not alter an enabled scope with gradualRolloutUserId and userWithId strategies' do
- flag = setup
- scope = scopes.create!(feature_flag_id: flag.id, active: true, strategies: [
- { name: 'gradualRolloutUserId', parameters: { groupId: 'default', percentage: '50' } },
- { name: 'userWithId', parameters: { userIds: '5' } }
- ])
-
- disable_migrations_output { migrate! }
-
- scope.reload
- expect(scope.active).to eq(true)
- expect(scope.strategies).to eq([
- { 'name' => 'gradualRolloutUserId', 'parameters' => { 'groupId' => 'default', 'percentage' => '50' } },
- { 'name' => 'userWithId', 'parameters' => { 'userIds' => '5' } }
- ])
- end
-
- it 'does not alter a disabled scope without a userWithId strategy' do
- flag = setup
- scope = scopes.create!(feature_flag_id: flag.id, active: false, strategies: [
- { name: 'gradualRolloutUserId', parameters: { percentage: '60' } }
- ])
-
- disable_migrations_output { migrate! }
-
- scope.reload
- expect(scope.active).to eq(false)
- expect(scope.strategies).to eq([
- { 'name' => 'gradualRolloutUserId', 'parameters' => { 'percentage' => '60' } }
- ])
- end
-
- it 'does not alter an enabled scope without a userWithId strategy' do
- flag = setup
- scope = scopes.create!(feature_flag_id: flag.id, active: true, strategies: [
- { name: 'default', parameters: {} }
- ])
-
- disable_migrations_output { migrate! }
-
- scope.reload
- expect(scope.active).to eq(true)
- expect(scope.strategies).to eq([
- { 'name' => 'default', 'parameters' => {} }
- ])
- end
-
- it 'migrates multiple scopes' do
- flag = setup
- scope_a = scopes.create!(feature_flag_id: flag.id, active: false, strategies: [
- { name: 'gradualRolloutUserId', parameters: { groupId: 'default', percentage: '50' } },
- { name: 'userWithId', parameters: { userIds: '5,6,7' } }
- ])
- scope_b = scopes.create!(feature_flag_id: flag.id, active: false, environment_scope: 'production', strategies: [
- { name: 'default', parameters: {} },
- { name: 'userWithId', parameters: { userIds: 'lisa,carol' } }
- ])
-
- disable_migrations_output { migrate! }
-
- scope_a.reload
- scope_b.reload
- expect(scope_a.active).to eq(true)
- expect(scope_a.strategies).to eq([{ 'name' => 'userWithId', 'parameters' => { 'userIds' => '5,6,7' } }])
- expect(scope_b.active).to eq(true)
- expect(scope_b.strategies).to eq([{ 'name' => 'userWithId', 'parameters' => { 'userIds' => 'lisa,carol' } }])
- end
-end
diff --git a/spec/migrations/migrate_storage_migrator_sidekiq_queue_spec.rb b/spec/migrations/migrate_storage_migrator_sidekiq_queue_spec.rb
deleted file mode 100644
index 4db819f2fa1..00000000000
--- a/spec/migrations/migrate_storage_migrator_sidekiq_queue_spec.rb
+++ /dev/null
@@ -1,43 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-require_migration!
-
-RSpec.describe MigrateStorageMigratorSidekiqQueue, :redis do
- include Gitlab::Database::MigrationHelpers
- include StubWorker
-
- context 'when there are jobs in the queues' do
- it 'correctly migrates queue when migrating up' do
- Sidekiq::Testing.disable! do
- stub_worker(queue: :storage_migrator).perform_async(1, 5)
-
- described_class.new.up
-
- expect(sidekiq_queue_length('storage_migrator')).to eq 0
- expect(sidekiq_queue_length('hashed_storage:hashed_storage_migrator')).to eq 1
- end
- end
-
- it 'correctly migrates queue when migrating down' do
- Sidekiq::Testing.disable! do
- stub_worker(queue: :'hashed_storage:hashed_storage_migrator').perform_async(1, 5)
-
- described_class.new.down
-
- expect(sidekiq_queue_length('storage_migrator')).to eq 1
- expect(sidekiq_queue_length('hashed_storage:hashed_storage_migrator')).to eq 0
- end
- end
- end
-
- context 'when there are no jobs in the queues' do
- it 'does not raise error when migrating up' do
- expect { described_class.new.up }.not_to raise_error
- end
-
- it 'does not raise error when migrating down' do
- expect { described_class.new.down }.not_to raise_error
- end
- end
-end
diff --git a/spec/migrations/move_limits_from_plans_spec.rb b/spec/migrations/move_limits_from_plans_spec.rb
deleted file mode 100644
index 92ac804733f..00000000000
--- a/spec/migrations/move_limits_from_plans_spec.rb
+++ /dev/null
@@ -1,35 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-require_migration!
-
-RSpec.describe MoveLimitsFromPlans do
- let(:plans) { table(:plans) }
- let(:plan_limits) { table(:plan_limits) }
-
- let!(:gold_plan) { plans.create!(name: 'gold', title: 'Gold', active_pipelines_limit: 20, pipeline_size_limit: 21, active_jobs_limit: 22) }
- let!(:silver_plan) { plans.create!(name: 'silver', title: 'Silver', active_pipelines_limit: 30, pipeline_size_limit: 31, active_jobs_limit: 32) }
- let!(:bronze_plan) { plans.create!(name: 'bronze', title: 'Bronze', active_pipelines_limit: 40, pipeline_size_limit: 41, active_jobs_limit: 42) }
- let!(:free_plan) { plans.create!(name: 'free', title: 'Free', active_pipelines_limit: 50, pipeline_size_limit: 51, active_jobs_limit: 52) }
- let!(:other_plan) { plans.create!(name: 'other', title: 'Other', active_pipelines_limit: nil, pipeline_size_limit: nil, active_jobs_limit: 0) }
-
- describe 'migrate' do
- it 'populates plan_limits from all the records in plans' do
- expect { migrate! }.to change { plan_limits.count }.by 5
- end
-
- it 'copies plan limits and plan.id into to plan_limits table' do
- migrate!
-
- new_data = plan_limits.pluck(:plan_id, :ci_active_pipelines, :ci_pipeline_size, :ci_active_jobs)
- expected_data = [
- [gold_plan.id, 20, 21, 22],
- [silver_plan.id, 30, 31, 32],
- [bronze_plan.id, 40, 41, 42],
- [free_plan.id, 50, 51, 52],
- [other_plan.id, 0, 0, 0]
- ]
- expect(new_data).to contain_exactly(*expected_data)
- end
- end
-end
diff --git a/spec/migrations/nullify_users_role_spec.rb b/spec/migrations/nullify_users_role_spec.rb
deleted file mode 100644
index 11056d9cf0c..00000000000
--- a/spec/migrations/nullify_users_role_spec.rb
+++ /dev/null
@@ -1,33 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-require_migration!
-
-RSpec.describe NullifyUsersRole do
- let(:users) { table(:users) }
-
- before do
- allow(Gitlab).to receive(:com?).and_return(true)
-
- users.create!(role: 0, updated_at: '2019-11-04 12:08:00', projects_limit: 0, email: '1')
- users.create!(role: 1, updated_at: '2019-11-04 12:08:00', projects_limit: 0, email: '2')
- users.create!(role: 0, updated_at: '2019-11-06 12:08:00', projects_limit: 0, email: '3')
-
- migrate!
- end
-
- it 'nullifies the role of the user with updated_at < 2019-11-05 12:08:00 and a role of 0' do
- expect(users.where(role: nil).count).to eq(1)
- expect(users.find_by(role: nil).email).to eq('1')
- end
-
- it 'leaves the user with role of 1' do
- expect(users.where(role: 1).count).to eq(1)
- expect(users.find_by(role: 1).email).to eq('2')
- end
-
- it 'leaves the user with updated_at > 2019-11-05 12:08:00' do
- expect(users.where(role: 0).count).to eq(1)
- expect(users.find_by(role: 0).email).to eq('3')
- end
-end
diff --git a/spec/migrations/populate_project_statistics_packages_size_spec.rb b/spec/migrations/populate_project_statistics_packages_size_spec.rb
deleted file mode 100644
index af9237f4bd6..00000000000
--- a/spec/migrations/populate_project_statistics_packages_size_spec.rb
+++ /dev/null
@@ -1,37 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-require_migration!
-
-RSpec.describe PopulateProjectStatisticsPackagesSize do
- let(:project_statistics) { table(:project_statistics) }
- let(:namespaces) { table(:namespaces) }
- let(:projects) { table(:projects) }
- let(:packages) { table(:packages_packages) }
- let(:package_files) { table(:packages_package_files) }
-
- let(:file_size) { 1.kilobyte }
- let(:repo_size) { 2.megabytes }
- let(:lfs_size) { 3.gigabytes }
- let(:artifacts_size) { 4.terabytes }
- let(:storage_size) { repo_size + lfs_size + artifacts_size }
-
- let(:namespace) { namespaces.create!(name: 'foo', path: 'foo') }
- let(:package) { packages.create!(project_id: project.id, name: 'a package', package_type: 1) }
- let(:project) { projects.create!(namespace_id: namespace.id) }
-
- let!(:statistics) { project_statistics.create!(project_id: project.id, namespace_id: namespace.id, storage_size: storage_size, repository_size: repo_size, lfs_objects_size: lfs_size, build_artifacts_size: artifacts_size) }
- let!(:package_file) { package_files.create!(package_id: package.id, file: 'a file.txt', file_name: 'a file.txt', size: file_size)}
-
- it 'backfills ProjectStatistics packages_size' do
- expect { migrate! }
- .to change { statistics.reload.packages_size }
- .from(nil).to(file_size)
- end
-
- it 'updates ProjectStatistics storage_size' do
- expect { migrate! }
- .to change { statistics.reload.storage_size }
- .by(file_size)
- end
-end
diff --git a/spec/migrations/populate_rule_type_on_approval_merge_request_rules_spec.rb b/spec/migrations/populate_rule_type_on_approval_merge_request_rules_spec.rb
deleted file mode 100644
index 7dc3f5a1004..00000000000
--- a/spec/migrations/populate_rule_type_on_approval_merge_request_rules_spec.rb
+++ /dev/null
@@ -1,39 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-require_migration!
-
-RSpec.describe PopulateRuleTypeOnApprovalMergeRequestRules do
- let(:migration) { described_class.new }
-
- describe '#up' do
- let(:namespaces) { table(:namespaces) }
- let(:projects) { table(:projects) }
- let(:merge_requests) { table(:merge_requests) }
- let(:approval_rules) { table(:approval_merge_request_rules) }
-
- # We use integers here since at the time of writing CE does not yet have the
- # appropriate models and enum definitions.
- let(:regular_rule_type) { 1 }
- let(:code_owner_rule_type) { 2 }
-
- before do
- namespaces.create!(id: 11, name: 'gitlab', path: 'gitlab')
- projects.create!(id: 101, namespace_id: 11, name: 'gitlab', path: 'gitlab')
- merge_requests.create!(id: 1, target_project_id: 101, source_project_id: 101, target_branch: 'feature', source_branch: 'master')
-
- approval_rules.create!(id: 1, merge_request_id: 1, name: "Default", code_owner: false, rule_type: regular_rule_type)
- approval_rules.create!(id: 2, merge_request_id: 1, name: "Code Owners", code_owner: true, rule_type: regular_rule_type)
- end
-
- it 'backfills ApprovalMergeRequestRules code_owner rule_type' do
- expect(approval_rules.where(rule_type: regular_rule_type).pluck(:id)).to contain_exactly(1, 2)
- expect(approval_rules.where(rule_type: code_owner_rule_type).pluck(:id)).to be_empty
-
- migrate!
-
- expect(approval_rules.where(rule_type: regular_rule_type).pluck(:id)).to contain_exactly(1)
- expect(approval_rules.where(rule_type: code_owner_rule_type).pluck(:id)).to contain_exactly(2)
- end
- end
-end
diff --git a/spec/migrations/recreate_index_security_ci_builds_on_name_and_id_parser_features_spec.rb b/spec/migrations/recreate_index_security_ci_builds_on_name_and_id_parser_features_spec.rb
new file mode 100644
index 00000000000..77824a743fb
--- /dev/null
+++ b/spec/migrations/recreate_index_security_ci_builds_on_name_and_id_parser_features_spec.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+require_migration!
+
+RSpec.describe RecreateIndexSecurityCiBuildsOnNameAndIdParserFeatures, :migration do
+ let(:db) { described_class.new }
+ let(:pg_class) { table(:pg_class) }
+ let(:pg_index) { table(:pg_index) }
+ let(:async_indexes) { table(:postgres_async_indexes) }
+
+ it "recreates index" do
+ reversible_migration do |migration|
+ migration.before -> {
+ expect(async_indexes.where(name: described_class::OLD_INDEX_NAME).exists?).to be false
+ expect(db.index_exists?(described_class::TABLE, described_class::COLUMNS, name: described_class::OLD_INDEX_NAME)).to be true
+ expect(db.index_exists?(described_class::TABLE, described_class::COLUMNS, name: described_class::NEW_INDEX_NAME)).to be false
+ }
+
+ migration.after -> {
+ expect(async_indexes.where(name: described_class::OLD_INDEX_NAME).exists?).to be true
+ expect(db.index_exists?(described_class::TABLE, described_class::COLUMNS, name: described_class::OLD_INDEX_NAME)).to be false
+ expect(db.index_exists?(described_class::TABLE, described_class::COLUMNS, name: described_class::NEW_INDEX_NAME)).to be true
+ }
+ end
+ end
+end
diff --git a/spec/migrations/remove_empty_github_service_templates_spec.rb b/spec/migrations/remove_empty_github_service_templates_spec.rb
deleted file mode 100644
index ad84187c298..00000000000
--- a/spec/migrations/remove_empty_github_service_templates_spec.rb
+++ /dev/null
@@ -1,55 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-require_migration!
-
-RSpec.describe RemoveEmptyGithubServiceTemplates do
- subject(:migration) { described_class.new }
-
- let(:services) do
- table(:services).tap do |klass|
- klass.class_eval do
- serialize :properties, JSON
- end
- end
- end
-
- before do
- services.delete_all
-
- create_service(properties: nil)
- create_service(properties: {})
- create_service(properties: { some: :value })
- create_service(properties: {}, template: false)
- create_service(properties: {}, type: 'SomeType')
- end
-
- def all_service_properties
- services.where(template: true, type: 'GithubService').pluck(:properties)
- end
-
- it 'correctly migrates up and down service templates' do
- reversible_migration do |migration|
- migration.before -> do
- expect(services.count).to eq(5)
-
- expect(all_service_properties)
- .to match(a_collection_containing_exactly(nil, {}, { 'some' => 'value' }))
- end
-
- migration.after -> do
- expect(services.count).to eq(4)
-
- expect(all_service_properties)
- .to match(a_collection_containing_exactly(nil, { 'some' => 'value' }))
- end
- end
- end
-
- def create_service(params)
- data = { template: true, type: 'GithubService' }
- data.merge!(params)
-
- services.create!(data)
- end
-end
diff --git a/spec/migrations/remove_schedule_and_status_from_pending_alert_escalations_spec.rb b/spec/migrations/remove_schedule_and_status_from_pending_alert_escalations_spec.rb
new file mode 100644
index 00000000000..f595261ff90
--- /dev/null
+++ b/spec/migrations/remove_schedule_and_status_from_pending_alert_escalations_spec.rb
@@ -0,0 +1,37 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+require_migration!
+
+RSpec.describe RemoveScheduleAndStatusFromPendingAlertEscalations do
+ let(:escalations) { table(:incident_management_pending_alert_escalations) }
+ let(:schedule_index) { 'index_incident_management_pending_alert_escalations_on_schedule' }
+ let(:schedule_foreign_key) { 'fk_rails_fcbfd9338b' }
+
+ it 'correctly migrates up and down' do
+ reversible_migration do |migration|
+ migration.before -> {
+ expect(escalations.column_names).to include('schedule_id', 'status')
+ expect(escalations_indexes).to include(schedule_index)
+ expect(escalations_constraints).to include(schedule_foreign_key)
+ }
+
+ migration.after -> {
+ escalations.reset_column_information
+ expect(escalations.column_names).not_to include('schedule_id', 'status')
+ expect(escalations_indexes).not_to include(schedule_index)
+ expect(escalations_constraints).not_to include(schedule_foreign_key)
+ }
+ end
+ end
+
+ private
+
+ def escalations_indexes
+ ActiveRecord::Base.connection.indexes(:incident_management_pending_alert_escalations).collect(&:name)
+ end
+
+ def escalations_constraints
+ ActiveRecord::Base.connection.foreign_keys(:incident_management_pending_alert_escalations).collect(&:name)
+ end
+end
diff --git a/spec/migrations/schedule_fill_valid_time_for_pages_domain_certificates_spec.rb b/spec/migrations/schedule_fill_valid_time_for_pages_domain_certificates_spec.rb
deleted file mode 100644
index 45bd5073d55..00000000000
--- a/spec/migrations/schedule_fill_valid_time_for_pages_domain_certificates_spec.rb
+++ /dev/null
@@ -1,48 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-require_migration!
-
-RSpec.describe ScheduleFillValidTimeForPagesDomainCertificates do
- let(:migration_class) { described_class::MIGRATION }
- let(:migration_name) { migration_class.to_s.demodulize }
-
- let(:domains_table) { table(:pages_domains) }
-
- let(:certificate) do
- File.read('spec/fixtures/passphrase_x509_certificate.crt')
- end
-
- before do
- domains_table.create!(domain: "domain1.example.com", verification_code: "123")
- domains_table.create!(domain: "domain2.example.com", verification_code: "123", certificate: '')
- domains_table.create!(domain: "domain3.example.com", verification_code: "123", certificate: certificate)
- domains_table.create!(domain: "domain4.example.com", verification_code: "123", certificate: certificate)
- end
-
- it 'correctly schedules background migrations' do
- Sidekiq::Testing.fake! do
- freeze_time do
- migrate!
-
- first_id = domains_table.find_by_domain("domain3.example.com").id
- last_id = domains_table.find_by_domain("domain4.example.com").id
-
- expect(migration_name).to be_scheduled_delayed_migration(5.minutes, first_id, last_id)
- expect(BackgroundMigrationWorker.jobs.size).to eq(1)
- end
- end
- end
-
- it 'sets certificate valid_not_before/not_after', :sidekiq_might_not_need_inline do
- perform_enqueued_jobs do
- migrate!
-
- domain = domains_table.find_by_domain("domain3.example.com")
- expect(domain.certificate_valid_not_before)
- .to eq(Time.parse("2018-03-23 14:02:08 UTC"))
- expect(domain.certificate_valid_not_after)
- .to eq(Time.parse("2019-03-23 14:02:08 UTC"))
- end
- end
-end
diff --git a/spec/migrations/schedule_pages_metadata_migration_spec.rb b/spec/migrations/schedule_pages_metadata_migration_spec.rb
deleted file mode 100644
index 96fbc1f9f51..00000000000
--- a/spec/migrations/schedule_pages_metadata_migration_spec.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-require_migration!
-
-RSpec.describe SchedulePagesMetadataMigration do
- let(:namespaces) { table(:namespaces) }
- let(:projects) { table(:projects) }
-
- before do
- stub_const("#{described_class.name}::BATCH_SIZE", 1)
-
- namespaces.create!(id: 11, name: 'gitlab', path: 'gitlab-org')
- projects.create!(id: 111, namespace_id: 11, name: 'Project 111')
- projects.create!(id: 114, namespace_id: 11, name: 'Project 114')
- end
-
- it 'schedules pages metadata migration' do
- Sidekiq::Testing.fake! do
- freeze_time do
- migrate!
-
- expect(described_class::MIGRATION).to be_scheduled_delayed_migration(2.minutes, 111, 111)
- expect(described_class::MIGRATION).to be_scheduled_delayed_migration(4.minutes, 114, 114)
- expect(BackgroundMigrationWorker.jobs.size).to eq(2)
- end
- end
- end
-end
diff --git a/spec/migrations/schedule_populate_merge_request_assignees_table_spec.rb b/spec/migrations/schedule_populate_merge_request_assignees_table_spec.rb
deleted file mode 100644
index 3caab64a72d..00000000000
--- a/spec/migrations/schedule_populate_merge_request_assignees_table_spec.rb
+++ /dev/null
@@ -1,47 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-require_migration!
-
-RSpec.describe SchedulePopulateMergeRequestAssigneesTable do
- let(:namespaces) { table(:namespaces) }
- let(:projects) { table(:projects) }
- let(:namespace) { namespaces.create!(name: 'gitlab', path: 'gitlab-org') }
- let(:project) { projects.create!(namespace_id: namespace.id, name: 'foo') }
- let(:merge_requests) { table(:merge_requests) }
-
- def create_merge_request(id)
- params = {
- id: id,
- target_project_id: project.id,
- target_branch: 'master',
- source_project_id: project.id,
- source_branch: 'mr name',
- title: "mr name#{id}"
- }
-
- merge_requests.create!(params)
- end
-
- it 'correctly schedules background migrations' do
- create_merge_request(1)
- create_merge_request(2)
- create_merge_request(3)
-
- stub_const("#{described_class.name}::BATCH_SIZE", 2)
-
- Sidekiq::Testing.fake! do
- freeze_time do
- migrate!
-
- expect(described_class::MIGRATION)
- .to be_scheduled_delayed_migration(8.minutes, 1, 2)
-
- expect(described_class::MIGRATION)
- .to be_scheduled_delayed_migration(16.minutes, 3, 3)
-
- expect(BackgroundMigrationWorker.jobs.size).to eq(2)
- end
- end
- end
-end
diff --git a/spec/migrations/schedule_populate_status_column_of_security_scans_spec.rb b/spec/migrations/schedule_populate_status_column_of_security_scans_spec.rb
new file mode 100644
index 00000000000..601935db8db
--- /dev/null
+++ b/spec/migrations/schedule_populate_status_column_of_security_scans_spec.rb
@@ -0,0 +1,48 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+require_migration!
+
+RSpec.describe SchedulePopulateStatusColumnOfSecurityScans do
+ before do
+ allow(Gitlab).to receive(:ee?).and_return(ee?)
+ stub_const("#{described_class.name}::BATCH_SIZE", 1)
+ end
+
+ context 'when the Gitlab instance is CE' do
+ let(:ee?) { false }
+
+ it 'does not run the migration' do
+ expect { migrate! }.not_to change { BackgroundMigrationWorker.jobs.size }
+ end
+ end
+
+ context 'when the Gitlab instance is EE' do
+ let(:ee?) { true }
+ let(:namespaces) { table(:namespaces) }
+ let(:projects) { table(:projects) }
+ let(:pipelines) { table(:ci_pipelines) }
+ let(:builds) { table(:ci_builds) }
+ let(:security_scans) { table(:security_scans) }
+
+ let(:namespace) { namespaces.create!(name: "foo", path: "bar") }
+ let(:project) { projects.create!(namespace_id: namespace.id) }
+ let(:pipeline) { pipelines.create!(project_id: project.id, ref: 'master', sha: 'adf43c3a', status: 'success') }
+ let(:ci_build) { builds.create!(commit_id: pipeline.id, retried: false, type: 'Ci::Build') }
+
+ let!(:security_scan_1) { security_scans.create!(build_id: ci_build.id, scan_type: 1) }
+ let!(:security_scan_2) { security_scans.create!(build_id: ci_build.id, scan_type: 2) }
+
+ around do |example|
+ freeze_time { Sidekiq::Testing.fake! { example.run } }
+ end
+
+ it 'schedules the background jobs', :aggregate_failures do
+ migrate!
+
+ expect(BackgroundMigrationWorker.jobs.size).to be(2)
+ expect(described_class::MIGRATION).to be_scheduled_delayed_migration(2.minutes, security_scan_1.id, security_scan_1.id)
+ expect(described_class::MIGRATION).to be_scheduled_delayed_migration(4.minutes, security_scan_2.id, security_scan_2.id)
+ end
+ end
+end
diff --git a/spec/migrations/schedule_sync_issuables_state_id_spec.rb b/spec/migrations/schedule_sync_issuables_state_id_spec.rb
deleted file mode 100644
index 5a7105a0c84..00000000000
--- a/spec/migrations/schedule_sync_issuables_state_id_spec.rb
+++ /dev/null
@@ -1,81 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-require_migration!
-
-RSpec.describe ScheduleSyncIssuablesStateId do
- let(:namespaces) { table(:namespaces) }
- let(:projects) { table(:projects) }
- let(:merge_requests) { table(:merge_requests) }
- let(:issues) { table(:issues) }
- let(:migration) { described_class.new }
- let(:group) { namespaces.create!(name: 'gitlab', path: 'gitlab') }
- let(:project) { projects.create!(namespace_id: group.id) }
-
- shared_examples 'scheduling migrations' do
- before do
- Sidekiq::Worker.clear_all
- stub_const("#{described_class.name}::BATCH_SIZE", 2)
- end
-
- it 'correctly schedules issuable sync background migration' do
- Sidekiq::Testing.fake! do
- freeze_time do
- migrate!
-
- expect(migration).to be_scheduled_delayed_migration(120.seconds, resource_1.id, resource_2.id)
- expect(migration).to be_scheduled_delayed_migration(240.seconds, resource_3.id, resource_4.id)
- expect(BackgroundMigrationWorker.jobs.size).to eq(2)
- end
- end
- end
- end
-
- describe '#up' do
- context 'issues' do
- it 'migrates state column to integer', :sidekiq_might_not_need_inline do
- opened_issue = issues.create!(description: 'first', state: 'opened')
- closed_issue = issues.create!(description: 'second', state: 'closed')
- invalid_state_issue = issues.create!(description: 'fourth', state: 'not valid')
-
- migrate!
-
- expect(opened_issue.reload.state_id).to eq(Issue.available_states[:opened])
- expect(closed_issue.reload.state_id).to eq(Issue.available_states[:closed])
- expect(invalid_state_issue.reload.state_id).to be_nil
- end
-
- it_behaves_like 'scheduling migrations' do
- let(:migration) { described_class::ISSUES_MIGRATION }
- let!(:resource_1) { issues.create!(description: 'first', state: 'opened') }
- let!(:resource_2) { issues.create!(description: 'second', state: 'closed') }
- let!(:resource_3) { issues.create!(description: 'third', state: 'closed') }
- let!(:resource_4) { issues.create!(description: 'fourth', state: 'closed') }
- end
- end
-
- context 'merge requests' do
- it 'migrates state column to integer', :sidekiq_might_not_need_inline do
- opened_merge_request = merge_requests.create!(state: 'opened', target_project_id: project.id, target_branch: 'feature1', source_branch: 'master')
- closed_merge_request = merge_requests.create!(state: 'closed', target_project_id: project.id, target_branch: 'feature2', source_branch: 'master')
- merged_merge_request = merge_requests.create!(state: 'merged', target_project_id: project.id, target_branch: 'feature3', source_branch: 'master')
- locked_merge_request = merge_requests.create!(state: 'locked', target_project_id: project.id, target_branch: 'feature4', source_branch: 'master')
-
- migrate!
-
- expect(opened_merge_request.reload.state_id).to eq(MergeRequest.available_states[:opened])
- expect(closed_merge_request.reload.state_id).to eq(MergeRequest.available_states[:closed])
- expect(merged_merge_request.reload.state_id).to eq(MergeRequest.available_states[:merged])
- expect(locked_merge_request.reload.state_id).to eq(MergeRequest.available_states[:locked])
- end
-
- it_behaves_like 'scheduling migrations' do
- let(:migration) { described_class::MERGE_REQUESTS_MIGRATION }
- let!(:resource_1) { merge_requests.create!(state: 'opened', target_project_id: project.id, target_branch: 'feature1', source_branch: 'master') }
- let!(:resource_2) { merge_requests.create!(state: 'closed', target_project_id: project.id, target_branch: 'feature2', source_branch: 'master') }
- let!(:resource_3) { merge_requests.create!(state: 'merged', target_project_id: project.id, target_branch: 'feature3', source_branch: 'master') }
- let!(:resource_4) { merge_requests.create!(state: 'locked', target_project_id: project.id, target_branch: 'feature4', source_branch: 'master') }
- end
- end
- end
-end
diff --git a/spec/migrations/schedule_sync_issuables_state_id_where_nil_spec.rb b/spec/migrations/schedule_sync_issuables_state_id_where_nil_spec.rb
deleted file mode 100644
index d8eaaa1df04..00000000000
--- a/spec/migrations/schedule_sync_issuables_state_id_where_nil_spec.rb
+++ /dev/null
@@ -1,57 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-require_migration!
-
-RSpec.describe ScheduleSyncIssuablesStateIdWhereNil do
- let(:namespaces) { table(:namespaces) }
- let(:projects) { table(:projects) }
- let(:merge_requests) { table(:merge_requests) }
- let(:issues) { table(:issues) }
- let(:migration) { described_class.new }
- let(:group) { namespaces.create!(name: 'gitlab', path: 'gitlab') }
- let(:project) { projects.create!(namespace_id: group.id) }
-
- shared_examples 'scheduling migrations' do
- before do
- Sidekiq::Worker.clear_all
- stub_const("#{described_class.name}::BATCH_SIZE", 2)
- end
-
- it 'correctly schedules issuable sync background migration' do
- Sidekiq::Testing.fake! do
- freeze_time do
- migrate!
-
- expect(migration).to be_scheduled_delayed_migration(120.seconds, resource_1.id, resource_3.id)
- expect(migration).to be_scheduled_delayed_migration(240.seconds, resource_5.id, resource_5.id)
- expect(BackgroundMigrationWorker.jobs.size).to eq(2)
- end
- end
- end
- end
-
- describe '#up' do
- context 'issues' do
- it_behaves_like 'scheduling migrations' do
- let(:migration) { described_class::ISSUES_MIGRATION }
- let!(:resource_1) { issues.create!(description: 'first', state: 'opened', state_id: nil) }
- let!(:resource_2) { issues.create!(description: 'second', state: 'closed', state_id: 2) }
- let!(:resource_3) { issues.create!(description: 'third', state: 'closed', state_id: nil) }
- let!(:resource_4) { issues.create!(description: 'fourth', state: 'closed', state_id: 2) }
- let!(:resource_5) { issues.create!(description: 'fifth', state: 'closed', state_id: nil) }
- end
- end
-
- context 'merge requests' do
- it_behaves_like 'scheduling migrations' do
- let(:migration) { described_class::MERGE_REQUESTS_MIGRATION }
- let!(:resource_1) { merge_requests.create!(state: 'opened', state_id: nil, target_project_id: project.id, target_branch: 'feature1', source_branch: 'master') }
- let!(:resource_2) { merge_requests.create!(state: 'closed', state_id: 2, target_project_id: project.id, target_branch: 'feature2', source_branch: 'master') }
- let!(:resource_3) { merge_requests.create!(state: 'merged', state_id: nil, target_project_id: project.id, target_branch: 'feature3', source_branch: 'master') }
- let!(:resource_4) { merge_requests.create!(state: 'locked', state_id: 3, target_project_id: project.id, target_branch: 'feature4', source_branch: 'master') }
- let!(:resource_5) { merge_requests.create!(state: 'locked', state_id: nil, target_project_id: project.id, target_branch: 'feature4', source_branch: 'master') }
- end
- end
- end
-end
diff --git a/spec/migrations/set_issue_id_for_all_versions_spec.rb b/spec/migrations/set_issue_id_for_all_versions_spec.rb
deleted file mode 100644
index 78bc4bbce1c..00000000000
--- a/spec/migrations/set_issue_id_for_all_versions_spec.rb
+++ /dev/null
@@ -1,38 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-require_migration!
-
-RSpec.describe SetIssueIdForAllVersions do
- let(:projects) { table(:projects) }
- let(:issues) { table(:issues) }
- let(:designs) { table(:design_management_designs) }
- let(:designs_versions) { table(:design_management_designs_versions) }
- let(:versions) { table(:design_management_versions) }
-
- before do
- @project = projects.create!(name: 'gitlab', path: 'gitlab-org/gitlab-ce', namespace_id: 1)
-
- @issue_1 = issues.create!(description: 'first', project_id: @project.id)
- @issue_2 = issues.create!(description: 'second', project_id: @project.id)
-
- @design_1 = designs.create!(issue_id: @issue_1.id, filename: 'homepage-1.jpg', project_id: @project.id)
- @design_2 = designs.create!(issue_id: @issue_2.id, filename: 'homepage-2.jpg', project_id: @project.id)
-
- @version_1 = versions.create!(sha: 'foo')
- @version_2 = versions.create!(sha: 'bar')
-
- designs_versions.create!(version_id: @version_1.id, design_id: @design_1.id)
- designs_versions.create!(version_id: @version_2.id, design_id: @design_2.id)
- end
-
- it 'correctly sets issue_id' do
- expect(versions.where(issue_id: nil).count).to eq(2)
-
- migrate!
-
- expect(versions.where(issue_id: nil).count).to eq(0)
- expect(versions.find(@version_1.id).issue_id).to eq(@issue_1.id)
- expect(versions.find(@version_2.id).issue_id).to eq(@issue_2.id)
- end
-end
diff --git a/spec/migrations/sync_issuables_state_id_spec.rb b/spec/migrations/sync_issuables_state_id_spec.rb
deleted file mode 100644
index 67403893f74..00000000000
--- a/spec/migrations/sync_issuables_state_id_spec.rb
+++ /dev/null
@@ -1,41 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-require_migration!
-
-RSpec.describe SyncIssuablesStateId do
- let(:migration) { described_class.new }
-
- describe '#up' do
- let(:issues) { table(:issues) }
- let(:namespaces) { table(:namespaces) }
- let(:projects) { table(:projects) }
- let(:merge_requests) { table(:merge_requests) }
- let(:group) { namespaces.create!(name: 'gitlab', path: 'gitlab') }
- let(:project) { projects.create!(namespace_id: group.id) }
- # These state_ids should be the same defined on Issue/MergeRequest models
- let(:state_ids) { { opened: 1, closed: 2, merged: 3, locked: 4 } }
-
- it 'migrates state column to state_id as integer' do
- opened_issue = issues.create!(description: 'first', state: 'opened')
- closed_issue = issues.create!(description: 'second', state: 'closed')
- unknown_state_issue = issues.create!(description: 'second', state: 'unknown')
- opened_merge_request = merge_requests.create!(state: 'opened', target_project_id: project.id, target_branch: 'feature1', source_branch: 'master')
- closed_merge_request = merge_requests.create!(state: 'closed', target_project_id: project.id, target_branch: 'feature2', source_branch: 'master')
- merged_merge_request = merge_requests.create!(state: 'merged', target_project_id: project.id, target_branch: 'feature3', source_branch: 'master')
- locked_merge_request = merge_requests.create!(state: 'locked', target_project_id: project.id, target_branch: 'feature4', source_branch: 'master')
- unknown_state_merge_request = merge_requests.create!(state: 'unknown', target_project_id: project.id, target_branch: 'feature4', source_branch: 'master')
-
- migrate!
-
- expect(opened_issue.reload.state_id).to eq(state_ids[:opened])
- expect(closed_issue.reload.state_id).to eq(state_ids[:closed])
- expect(unknown_state_issue.reload.state_id).to eq(state_ids[:closed])
- expect(opened_merge_request.reload.state_id).to eq(state_ids[:opened])
- expect(closed_merge_request.reload.state_id).to eq(state_ids[:closed])
- expect(merged_merge_request.reload.state_id).to eq(state_ids[:merged])
- expect(locked_merge_request.reload.state_id).to eq(state_ids[:locked])
- expect(unknown_state_merge_request.reload.state_id).to eq(state_ids[:closed])
- end
- end
-end
diff --git a/spec/migrations/truncate_user_fullname_spec.rb b/spec/migrations/truncate_user_fullname_spec.rb
deleted file mode 100644
index dc5bef06cdc..00000000000
--- a/spec/migrations/truncate_user_fullname_spec.rb
+++ /dev/null
@@ -1,23 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-require_migration!
-
-RSpec.describe TruncateUserFullname do
- let(:users) { table(:users) }
-
- let(:user_short) { create_user(name: 'abc', email: 'test_short@example.com') }
- let(:user_long) { create_user(name: 'a' * 200 + 'z', email: 'test_long@example.com') }
-
- def create_user(params)
- users.create!(params.merge(projects_limit: 0))
- end
-
- it 'truncates user full name to the first 128 characters' do
- expect { migrate! }.to change { user_long.reload.name }.to('a' * 128)
- end
-
- it 'does not truncate short names' do
- expect { migrate! }.not_to change { user_short.reload.name.length }
- end
-end
diff --git a/spec/migrations/update_minimum_password_length_spec.rb b/spec/migrations/update_minimum_password_length_spec.rb
deleted file mode 100644
index e40d090fd77..00000000000
--- a/spec/migrations/update_minimum_password_length_spec.rb
+++ /dev/null
@@ -1,30 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-require_migration!
-
-RSpec.describe UpdateMinimumPasswordLength do
- let(:application_settings) { table(:application_settings) }
- let(:application_setting) do
- application_settings.create!(
- minimum_password_length: ApplicationSetting::DEFAULT_MINIMUM_PASSWORD_LENGTH
- )
- end
-
- before do
- stub_const('ApplicationSetting::DEFAULT_MINIMUM_PASSWORD_LENGTH', 10)
- allow(Devise).to receive(:password_length).and_return(12..20)
- end
-
- it 'correctly migrates minimum_password_length' do
- reversible_migration do |migration|
- migration.before -> {
- expect(application_setting.reload.minimum_password_length).to eq(10)
- }
-
- migration.after -> {
- expect(application_setting.reload.minimum_password_length).to eq(12)
- }
- end
- end
-end