Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2024-01-19 00:08:06 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2024-01-19 00:08:06 +0300
commitaf7558b036a53ebb0484e7978694a0b419c38c70 (patch)
tree198bc423fd5bb7ca04e652f5a0c1d66c7d42d2c4 /spec/lib/gitlab
parent055b4c04d5cef7029625c08619df4f3bcdccc6c2 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab')
-rw-r--r--spec/lib/gitlab/background_migration/backfill_admin_mode_scope_for_personal_access_tokens_spec.rb2
-rw-r--r--spec/lib/gitlab/background_migration/backfill_environment_tiers_spec.rb2
-rw-r--r--spec/lib/gitlab/background_migration/backfill_imported_issue_search_data_spec.rb109
-rw-r--r--spec/lib/gitlab/background_migration/backfill_integrations_enable_ssl_verification_spec.rb2
-rw-r--r--spec/lib/gitlab/background_migration/backfill_namespace_id_of_vulnerability_reads_spec.rb2
-rw-r--r--spec/lib/gitlab/background_migration/backfill_project_namespace_on_issues_spec.rb76
-rw-r--r--spec/lib/gitlab/background_migration/backfill_releases_author_id_spec.rb2
-rw-r--r--spec/lib/gitlab/background_migration/backfill_topics_title_spec.rb2
-rw-r--r--spec/lib/gitlab/background_migration/backfill_user_details_fields_spec.rb222
-rw-r--r--spec/lib/gitlab/background_migration/backfill_vulnerability_reads_cluster_agent_spec.rb2
-rw-r--r--spec/lib/gitlab/background_migration/backfill_work_item_type_id_for_issues_spec.rb102
-rw-r--r--spec/lib/gitlab/background_migration/destroy_invalid_members_spec.rb4
-rw-r--r--spec/lib/gitlab/background_migration/disable_legacy_open_source_license_for_no_issues_no_repo_projects_spec.rb63
-rw-r--r--spec/lib/gitlab/background_migration/disable_legacy_open_source_license_for_one_member_no_repo_projects_spec.rb2
-rw-r--r--spec/lib/gitlab/background_migration/disable_legacy_open_source_license_for_projects_less_than_five_mb_spec.rb2
-rw-r--r--spec/lib/gitlab/background_migration/disable_legacy_open_source_license_for_projects_less_than_one_mb_spec.rb2
-rw-r--r--spec/lib/gitlab/background_migration/expire_o_auth_tokens_spec.rb36
-rw-r--r--spec/lib/gitlab/background_migration/nullify_creator_id_column_of_orphaned_projects_spec.rb2
-rw-r--r--spec/lib/gitlab/background_migration/populate_projects_star_count_spec.rb2
-rw-r--r--spec/lib/gitlab/background_migration/remove_project_group_link_with_missing_groups_spec.rb124
-rw-r--r--spec/lib/gitlab/background_migration/remove_self_managed_wiki_notes_spec.rb2
-rw-r--r--spec/lib/gitlab/background_migration/reset_too_many_tags_skipped_registry_imports_spec.rb2
-rw-r--r--spec/lib/gitlab/background_migration/set_legacy_open_source_license_available_for_non_public_projects_spec.rb2
-rw-r--r--spec/lib/gitlab/background_migration/truncate_overlong_vulnerability_html_titles_spec.rb2
-rw-r--r--spec/lib/gitlab/database/migration_helpers_spec.rb11
25 files changed, 26 insertions, 753 deletions
diff --git a/spec/lib/gitlab/background_migration/backfill_admin_mode_scope_for_personal_access_tokens_spec.rb b/spec/lib/gitlab/background_migration/backfill_admin_mode_scope_for_personal_access_tokens_spec.rb
index 92fec48454c..5aa02e5f8d7 100644
--- a/spec/lib/gitlab/background_migration/backfill_admin_mode_scope_for_personal_access_tokens_spec.rb
+++ b/spec/lib/gitlab/background_migration/backfill_admin_mode_scope_for_personal_access_tokens_spec.rb
@@ -3,7 +3,7 @@
require 'spec_helper'
RSpec.describe Gitlab::BackgroundMigration::BackfillAdminModeScopeForPersonalAccessTokens,
- :migration, schema: 20221228103133, feature_category: :system_access do
+ :migration, schema: 20230216060333, feature_category: :system_access do
let(:users) { table(:users) }
let(:personal_access_tokens) { table(:personal_access_tokens) }
diff --git a/spec/lib/gitlab/background_migration/backfill_environment_tiers_spec.rb b/spec/lib/gitlab/background_migration/backfill_environment_tiers_spec.rb
index 9026c327e3c..3801ccf0f0d 100644
--- a/spec/lib/gitlab/background_migration/backfill_environment_tiers_spec.rb
+++ b/spec/lib/gitlab/background_migration/backfill_environment_tiers_spec.rb
@@ -3,7 +3,7 @@
require 'spec_helper'
RSpec.describe Gitlab::BackgroundMigration::BackfillEnvironmentTiers,
- :migration, schema: 20221205151917, feature_category: :continuous_delivery do
+ :migration, schema: 20230216060333, feature_category: :continuous_delivery do
let!(:namespace) { table(:namespaces).create!(name: 'user', path: 'user') }
let!(:project) { table(:projects).create!(namespace_id: namespace.id, project_namespace_id: namespace.id) }
diff --git a/spec/lib/gitlab/background_migration/backfill_imported_issue_search_data_spec.rb b/spec/lib/gitlab/background_migration/backfill_imported_issue_search_data_spec.rb
deleted file mode 100644
index edf972189b2..00000000000
--- a/spec/lib/gitlab/background_migration/backfill_imported_issue_search_data_spec.rb
+++ /dev/null
@@ -1,109 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-
-RSpec.describe Gitlab::BackgroundMigration::BackfillImportedIssueSearchData,
- :migration,
- schema: 20221111123146 do
- let!(:namespace) { table(:namespaces).create!(name: 'user', path: 'user') }
- let!(:issue_search_data_table) { table(:issue_search_data) }
-
- let!(:user) { table(:users).create!(email: 'author@example.com', username: 'author', projects_limit: 10) }
- let!(:project) do
- table(:projects)
- .create!(
- namespace_id: namespace.id,
- creator_id: user.id,
- name: 'projecty',
- path: 'path',
- project_namespace_id: namespace.id)
- end
-
- let!(:issue) do
- table(:issues).create!(
- project_id: project.id,
- namespace_id: project.project_namespace_id,
- title: 'Patterson',
- description: FFaker::HipsterIpsum.paragraph
- )
- end
-
- let(:migration) do
- described_class.new(
- start_id: issue.id,
- end_id: issue.id + 30,
- batch_table: :issues,
- batch_column: :id,
- sub_batch_size: 2,
- pause_ms: 0,
- connection: ApplicationRecord.connection
- )
- end
-
- let(:perform_migration) { migration.perform }
-
- context 'when issue has search data record' do
- let!(:issue_search_data) { issue_search_data_table.create!(project_id: project.id, issue_id: issue.id) }
-
- it 'does not create or update any search data records' do
- expect { perform_migration }
- .to not_change { issue_search_data_table.count }
- .and not_change { issue_search_data }
-
- expect(issue_search_data_table.count).to eq(1)
- end
- end
-
- context 'when issue has no search data record' do
- let(:title_node) { "'#{issue.title.downcase}':1A" }
-
- it 'creates search data records' do
- expect { perform_migration }
- .to change { issue_search_data_table.count }.from(0).to(1)
-
- expect(issue_search_data_table.find_by(project_id: project.id).issue_id)
- .to eq(issue.id)
-
- expect(issue_search_data_table.find_by(project_id: project.id).search_vector)
- .to include(title_node)
- end
- end
-
- context 'error handling' do
- let!(:issue2) do
- table(:issues).create!(
- project_id: project.id,
- namespace_id: project.project_namespace_id,
- title: 'Chatterton',
- description: FFaker::HipsterIpsum.paragraph
- )
- end
-
- before do
- issue.update!(description: Array.new(30_000) { SecureRandom.hex }.join(' '))
- end
-
- let(:title_node2) { "'#{issue2.title.downcase}':1A" }
-
- it 'skips insertion for that issue but continues with migration' do
- expect_next_instance_of(Gitlab::BackgroundMigration::Logger) do |logger|
- expect(logger)
- .to receive(:error)
- .with(a_hash_including(message: /string is too long for tsvector/, model_id: issue.id))
- end
-
- expect { perform_migration }.to change { issue_search_data_table.count }.from(0).to(1)
- expect(issue_search_data_table.find_by(issue_id: issue.id)).to eq(nil)
- expect(issue_search_data_table.find_by(issue_id: issue2.id).search_vector)
- .to include(title_node2)
- end
-
- it 're-raises exceptions' do
- allow(migration)
- .to receive(:update_search_data_individually)
- .and_raise(ActiveRecord::StatementTimeout)
-
- expect { perform_migration }.to raise_error(ActiveRecord::StatementTimeout)
- end
- end
-end
diff --git a/spec/lib/gitlab/background_migration/backfill_integrations_enable_ssl_verification_spec.rb b/spec/lib/gitlab/background_migration/backfill_integrations_enable_ssl_verification_spec.rb
index 925fb0c9a20..9813e92edc0 100644
--- a/spec/lib/gitlab/background_migration/backfill_integrations_enable_ssl_verification_spec.rb
+++ b/spec/lib/gitlab/background_migration/backfill_integrations_enable_ssl_verification_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-RSpec.describe Gitlab::BackgroundMigration::BackfillIntegrationsEnableSslVerification, schema: 20221111123146 do
+RSpec.describe Gitlab::BackgroundMigration::BackfillIntegrationsEnableSslVerification, schema: 20230216060333 do
let(:migration) { described_class.new }
let(:integrations) { described_class::Integration }
diff --git a/spec/lib/gitlab/background_migration/backfill_namespace_id_of_vulnerability_reads_spec.rb b/spec/lib/gitlab/background_migration/backfill_namespace_id_of_vulnerability_reads_spec.rb
index c2c5c3e9de0..f92ec7e028b 100644
--- a/spec/lib/gitlab/background_migration/backfill_namespace_id_of_vulnerability_reads_spec.rb
+++ b/spec/lib/gitlab/background_migration/backfill_namespace_id_of_vulnerability_reads_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-RSpec.describe Gitlab::BackgroundMigration::BackfillNamespaceIdOfVulnerabilityReads, schema: 20221111123146 do
+RSpec.describe Gitlab::BackgroundMigration::BackfillNamespaceIdOfVulnerabilityReads, schema: 20230216060333 do
let(:namespaces) { table(:namespaces) }
let(:projects) { table(:projects) }
let(:users) { table(:users) }
diff --git a/spec/lib/gitlab/background_migration/backfill_project_namespace_on_issues_spec.rb b/spec/lib/gitlab/background_migration/backfill_project_namespace_on_issues_spec.rb
deleted file mode 100644
index 5fa92759cf9..00000000000
--- a/spec/lib/gitlab/background_migration/backfill_project_namespace_on_issues_spec.rb
+++ /dev/null
@@ -1,76 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-
-RSpec.describe Gitlab::BackgroundMigration::BackfillProjectNamespaceOnIssues,
- :migration, schema: 20221118103352, feature_category: :team_planning do
- let(:namespaces) { table(:namespaces) }
- let(:projects) { table(:projects) }
- let(:issues) { table(:issues) }
- let(:issue_base_type_enum_value) { 0 }
- let(:issue_type) { table(:work_item_types).find_by!(namespace_id: nil, base_type: issue_base_type_enum_value) }
-
- let(:namespace1) { namespaces.create!(name: 'batchtest1', type: 'Group', path: 'space1') }
- let(:namespace2) { namespaces.create!(name: 'batchtest2', type: 'Group', parent_id: namespace1.id, path: 'space2') }
-
- let(:proj_namespace1) { namespaces.create!(name: 'proj1', path: 'proj1', type: 'Project', parent_id: namespace1.id) }
- let(:proj_namespace2) { namespaces.create!(name: 'proj2', path: 'proj2', type: 'Project', parent_id: namespace2.id) }
-
- # rubocop:disable Layout/LineLength
- let(:proj1) { projects.create!(name: 'proj1', path: 'proj1', namespace_id: namespace1.id, project_namespace_id: proj_namespace1.id) }
- let(:proj2) { projects.create!(name: 'proj2', path: 'proj2', namespace_id: namespace2.id, project_namespace_id: proj_namespace2.id) }
-
- let!(:proj1_issue_with_namespace) { issues.create!(title: 'issue1', project_id: proj1.id, namespace_id: proj_namespace1.id, work_item_type_id: issue_type.id) }
- let!(:proj1_issue_without_namespace1) { issues.create!(title: 'issue2', project_id: proj1.id, work_item_type_id: issue_type.id) }
- let!(:proj1_issue_without_namespace2) { issues.create!(title: 'issue3', project_id: proj1.id, work_item_type_id: issue_type.id) }
- let!(:proj2_issue_with_namespace) { issues.create!(title: 'issue4', project_id: proj2.id, namespace_id: proj_namespace2.id, work_item_type_id: issue_type.id) }
- let!(:proj2_issue_without_namespace1) { issues.create!(title: 'issue5', project_id: proj2.id, work_item_type_id: issue_type.id) }
- let!(:proj2_issue_without_namespace2) { issues.create!(title: 'issue6', project_id: proj2.id, work_item_type_id: issue_type.id) }
- # rubocop:enable Layout/LineLength
-
- let(:migration) do
- described_class.new(
- start_id: proj1_issue_with_namespace.id,
- end_id: proj2_issue_without_namespace2.id,
- batch_table: :issues,
- batch_column: :id,
- sub_batch_size: 2,
- pause_ms: 2,
- connection: ApplicationRecord.connection
- )
- end
-
- subject(:perform_migration) { migration.perform }
-
- it 'backfills namespace_id for the selected records', :aggregate_failures do
- perform_migration
-
- expected_namespaces = [proj_namespace1.id, proj_namespace2.id]
-
- expect(issues.where.not(namespace_id: nil).count).to eq(6)
- expect(issues.where.not(namespace_id: nil).pluck(:namespace_id).uniq).to match_array(expected_namespaces)
- end
-
- it 'tracks timings of queries' do
- expect(migration.batch_metrics.timings).to be_empty
-
- expect { perform_migration }.to change { migration.batch_metrics.timings }
- end
-
- context 'when database timeouts' do
- using RSpec::Parameterized::TableSyntax
-
- where(error_class: [ActiveRecord::StatementTimeout, ActiveRecord::QueryCanceled])
-
- with_them do
- it 'retries on timeout error' do
- expect(migration).to receive(:update_batch).exactly(3).times.and_raise(error_class)
- expect(migration).to receive(:sleep).with(5).twice
-
- expect do
- perform_migration
- end.to raise_error(error_class)
- end
- end
- end
-end
diff --git a/spec/lib/gitlab/background_migration/backfill_releases_author_id_spec.rb b/spec/lib/gitlab/background_migration/backfill_releases_author_id_spec.rb
index 898f241a930..b86cfa005cd 100644
--- a/spec/lib/gitlab/background_migration/backfill_releases_author_id_spec.rb
+++ b/spec/lib/gitlab/background_migration/backfill_releases_author_id_spec.rb
@@ -3,7 +3,7 @@
require 'spec_helper'
RSpec.describe Gitlab::BackgroundMigration::BackfillReleasesAuthorId,
- :migration, schema: 20221215151822, feature_category: :release_orchestration do
+ :migration, schema: 20230216060333, feature_category: :release_orchestration do
let(:releases_table) { table(:releases) }
let(:user_table) { table(:users) }
let(:date_time) { DateTime.now }
diff --git a/spec/lib/gitlab/background_migration/backfill_topics_title_spec.rb b/spec/lib/gitlab/background_migration/backfill_topics_title_spec.rb
index 3eb0000877d..d1852d726e0 100644
--- a/spec/lib/gitlab/background_migration/backfill_topics_title_spec.rb
+++ b/spec/lib/gitlab/background_migration/backfill_topics_title_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-RSpec.describe Gitlab::BackgroundMigration::BackfillTopicsTitle, schema: 20221111123146 do
+RSpec.describe Gitlab::BackgroundMigration::BackfillTopicsTitle, schema: 20230216060333 do
it 'correctly backfills the title of the topics' do
topics = table(:topics)
diff --git a/spec/lib/gitlab/background_migration/backfill_user_details_fields_spec.rb b/spec/lib/gitlab/background_migration/backfill_user_details_fields_spec.rb
deleted file mode 100644
index 1d1853b032c..00000000000
--- a/spec/lib/gitlab/background_migration/backfill_user_details_fields_spec.rb
+++ /dev/null
@@ -1,222 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-
-RSpec.describe Gitlab::BackgroundMigration::BackfillUserDetailsFields, :migration, schema: 20221111123146 do
- let(:users) { table(:users) }
- let(:user_details) { table(:user_details) }
-
- let!(:user_all_fields_backfill) do
- users.create!(
- name: generate(:name),
- email: generate(:email),
- projects_limit: 1,
- linkedin: 'linked-in',
- twitter: '@twitter',
- skype: 'skype',
- website_url: 'https://example.com',
- location: 'Antarctica',
- organization: 'Gitlab'
- )
- end
-
- let!(:user_long_details_fields) do
- length = UserDetail::DEFAULT_FIELD_LENGTH + 1
- users.create!(
- name: generate(:name),
- email: generate(:email),
- projects_limit: 1,
- linkedin: 'l' * length,
- twitter: 't' * length,
- skype: 's' * length,
- website_url: "https://#{'a' * (length - 12)}.com",
- location: 'l' * length,
- organization: 'o' * length
- )
- end
-
- let!(:user_nil_details_fields) do
- users.create!(
- name: generate(:name),
- email: generate(:email),
- projects_limit: 1
- )
- end
-
- let!(:user_empty_details_fields) do
- users.create!(
- name: generate(:name),
- email: generate(:email),
- projects_limit: 1,
- linkedin: '',
- twitter: '',
- skype: '',
- website_url: '',
- location: '',
- organization: ''
- )
- end
-
- let!(:user_with_bio) do
- users.create!(
- name: generate(:name),
- email: generate(:email),
- projects_limit: 1,
- linkedin: 'linked-in',
- twitter: '@twitter',
- skype: 'skype',
- website_url: 'https://example.com',
- location: 'Antarctica',
- organization: 'Gitlab'
- )
- end
-
- let!(:bio_user_details) do
- user_details
- .find_or_create_by!(user_id: user_with_bio.id)
- .update!(bio: 'bio')
- end
-
- let!(:user_with_details) do
- users.create!(
- name: generate(:name),
- email: generate(:email),
- projects_limit: 1,
- linkedin: 'linked-in',
- twitter: '@twitter',
- skype: 'skype',
- website_url: 'https://example.com',
- location: 'Antarctica',
- organization: 'Gitlab'
- )
- end
-
- let!(:existing_user_details) do
- user_details
- .find_or_create_by!(user_id: user_with_details.id)
- .update!(
- linkedin: 'linked-in',
- twitter: '@twitter',
- skype: 'skype',
- website_url: 'https://example.com',
- location: 'Antarctica',
- organization: 'Gitlab'
- )
- end
-
- let!(:user_different_details) do
- users.create!(
- name: generate(:name),
- email: generate(:email),
- projects_limit: 1,
- linkedin: 'linked-in',
- twitter: '@twitter',
- skype: 'skype',
- website_url: 'https://example.com',
- location: 'Antarctica',
- organization: 'Gitlab'
- )
- end
-
- let!(:differing_details) do
- user_details
- .find_or_create_by!(user_id: user_different_details.id)
- .update!(
- linkedin: 'details-in',
- twitter: '@details',
- skype: 'details_skype',
- website_url: 'https://details.site',
- location: 'Details Location',
- organization: 'Details Organization'
- )
- end
-
- let(:user_ids) do
- [
- user_all_fields_backfill,
- user_long_details_fields,
- user_nil_details_fields,
- user_empty_details_fields,
- user_with_bio,
- user_with_details,
- user_different_details
- ].map(&:id)
- end
-
- subject do
- described_class.new(
- start_id: user_ids.min,
- end_id: user_ids.max,
- batch_table: 'users',
- batch_column: 'id',
- sub_batch_size: 1_000,
- pause_ms: 0,
- connection: ApplicationRecord.connection
- )
- end
-
- it 'processes all relevant records' do
- expect { subject.perform }.to change { user_details.all.size }.to(5)
- end
-
- it 'backfills new user_details fields' do
- subject.perform
-
- user_detail = user_details.find_by!(user_id: user_all_fields_backfill.id)
- expect(user_detail.linkedin).to eq('linked-in')
- expect(user_detail.twitter).to eq('@twitter')
- expect(user_detail.skype).to eq('skype')
- expect(user_detail.website_url).to eq('https://example.com')
- expect(user_detail.location).to eq('Antarctica')
- expect(user_detail.organization).to eq('Gitlab')
- end
-
- it 'does not migrate nil fields' do
- subject.perform
-
- expect(user_details.find_by(user_id: user_nil_details_fields)).to be_nil
- end
-
- it 'does not migrate empty fields' do
- subject.perform
-
- expect(user_details.find_by(user_id: user_empty_details_fields)).to be_nil
- end
-
- it 'backfills new fields without overwriting existing `bio` field' do
- subject.perform
-
- user_detail = user_details.find_by!(user_id: user_with_bio.id)
- expect(user_detail.bio).to eq('bio')
- expect(user_detail.linkedin).to eq('linked-in')
- expect(user_detail.twitter).to eq('@twitter')
- expect(user_detail.skype).to eq('skype')
- expect(user_detail.website_url).to eq('https://example.com')
- expect(user_detail.location).to eq('Antarctica')
- expect(user_detail.organization).to eq('Gitlab')
- end
-
- context 'when user details are unchanged' do
- it 'does not change existing details' do
- expect { subject.perform }.not_to change {
- user_details.find_by!(user_id: user_with_details.id).attributes
- }
- end
- end
-
- context 'when user details are changed' do
- it 'updates existing user details' do
- expect { subject.perform }.to change {
- user_details.find_by!(user_id: user_different_details.id).attributes
- }
-
- user_detail = user_details.find_by!(user_id: user_different_details.id)
- expect(user_detail.linkedin).to eq('linked-in')
- expect(user_detail.twitter).to eq('@twitter')
- expect(user_detail.skype).to eq('skype')
- expect(user_detail.website_url).to eq('https://example.com')
- expect(user_detail.location).to eq('Antarctica')
- expect(user_detail.organization).to eq('Gitlab')
- end
- end
-end
diff --git a/spec/lib/gitlab/background_migration/backfill_vulnerability_reads_cluster_agent_spec.rb b/spec/lib/gitlab/background_migration/backfill_vulnerability_reads_cluster_agent_spec.rb
index 63135971cd3..f43440b9226 100644
--- a/spec/lib/gitlab/background_migration/backfill_vulnerability_reads_cluster_agent_spec.rb
+++ b/spec/lib/gitlab/background_migration/backfill_vulnerability_reads_cluster_agent_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-RSpec.describe Gitlab::BackgroundMigration::BackfillVulnerabilityReadsClusterAgent, :migration, schema: 20221111123146 do # rubocop:disable Layout/LineLength
+RSpec.describe Gitlab::BackgroundMigration::BackfillVulnerabilityReadsClusterAgent, :migration, schema: 20230216060333 do # rubocop:disable Layout/LineLength
let(:migration) do
described_class.new(
start_id: 1, end_id: 10,
diff --git a/spec/lib/gitlab/background_migration/backfill_work_item_type_id_for_issues_spec.rb b/spec/lib/gitlab/background_migration/backfill_work_item_type_id_for_issues_spec.rb
deleted file mode 100644
index 4c1af279804..00000000000
--- a/spec/lib/gitlab/background_migration/backfill_work_item_type_id_for_issues_spec.rb
+++ /dev/null
@@ -1,102 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-
-RSpec.describe Gitlab::BackgroundMigration::BackfillWorkItemTypeIdForIssues,
- :migration,
- schema: 20221111123146,
- feature_category: :team_planning do
- let(:batch_column) { 'id' }
- let(:sub_batch_size) { 2 }
- let(:pause_ms) { 0 }
-
- # let_it_be can't be used in migration specs because all tables but `work_item_types` are deleted after each spec
- let(:issue_type_enum) { { issue: 0, incident: 1, test_case: 2, requirement: 3, task: 4 } }
- let(:namespace) { table(:namespaces).create!(name: 'namespace', path: 'namespace') }
- let(:project) { table(:projects).create!(namespace_id: namespace.id, project_namespace_id: namespace.id) }
- let(:issues_table) { table(:issues) }
- let(:issue_type) { table(:work_item_types).find_by!(namespace_id: nil, base_type: issue_type_enum[:issue]) }
- let(:task_type) { table(:work_item_types).find_by!(namespace_id: nil, base_type: issue_type_enum[:task]) }
-
- let(:issue1) { issues_table.create!(project_id: project.id, issue_type: issue_type_enum[:issue]) }
- let(:issue2) { issues_table.create!(project_id: project.id, issue_type: issue_type_enum[:issue]) }
- let(:issue3) { issues_table.create!(project_id: project.id, issue_type: issue_type_enum[:issue]) }
- let(:incident1) { issues_table.create!(project_id: project.id, issue_type: issue_type_enum[:incident]) }
- # test_case and requirement are EE only, but enum values exist on the FOSS model
- let(:test_case1) { issues_table.create!(project_id: project.id, issue_type: issue_type_enum[:test_case]) }
- let(:requirement1) { issues_table.create!(project_id: project.id, issue_type: issue_type_enum[:requirement]) }
-
- let(:start_id) { issue1.id }
- let(:end_id) { requirement1.id }
-
- let!(:all_issues) { [issue1, issue2, issue3, incident1, test_case1, requirement1] }
-
- let(:migration) do
- described_class.new(
- start_id: start_id,
- end_id: end_id,
- batch_table: :issues,
- batch_column: :id,
- sub_batch_size: sub_batch_size,
- pause_ms: pause_ms,
- job_arguments: [issue_type_enum[:issue], issue_type.id],
- connection: ApplicationRecord.connection
- )
- end
-
- subject(:migrate) { migration.perform }
-
- it 'sets work_item_type_id only for the given type' do
- expect(all_issues).to all(have_attributes(work_item_type_id: nil))
-
- expect { migrate }.to make_queries_matching(/UPDATE "issues" SET "work_item_type_id"/, 2)
- all_issues.each(&:reload)
-
- expect([issue1, issue2, issue3]).to all(have_attributes(work_item_type_id: issue_type.id))
- expect(all_issues - [issue1, issue2, issue3]).to all(have_attributes(work_item_type_id: nil))
- end
-
- context 'when a record already had a work_item_type_id assigned' do
- let!(:issue4) do
- issues_table.create!(
- project_id: project.id,
- issue_type: issue_type_enum[:issue],
- work_item_type_id: task_type.id
- )
- end
-
- let(:end_id) { issue4.id }
-
- it 'ovewrites the work_item_type_id' do
- # creating with the wrong issue_type/work_item_type_id on purpose so we can test
- # that the migration is capable of fixing such inconsistencies
- expect do
- migrate
- issue4.reload
- end.to change { issue4.work_item_type_id }.from(task_type.id).to(issue_type.id)
- end
- end
-
- it 'tracks timings of queries' do
- expect(migration.batch_metrics.timings).to be_empty
-
- expect { migrate }.to change { migration.batch_metrics.timings }
- end
-
- context 'when database timeouts' do
- using RSpec::Parameterized::TableSyntax
-
- where(error_class: [ActiveRecord::StatementTimeout, ActiveRecord::QueryCanceled])
-
- with_them do
- it 'retries on timeout error' do
- expect(migration).to receive(:update_batch).exactly(3).times.and_raise(error_class)
- expect(migration).to receive(:sleep).with(30).twice
-
- expect do
- migrate
- end.to raise_error(error_class)
- end
- end
- end
-end
diff --git a/spec/lib/gitlab/background_migration/destroy_invalid_members_spec.rb b/spec/lib/gitlab/background_migration/destroy_invalid_members_spec.rb
index 95c5a64bc7b..98c814902b4 100644
--- a/spec/lib/gitlab/background_migration/destroy_invalid_members_spec.rb
+++ b/spec/lib/gitlab/background_migration/destroy_invalid_members_spec.rb
@@ -3,7 +3,7 @@
require 'spec_helper'
# rubocop: disable RSpec/MultipleMemoizedHelpers
-RSpec.describe Gitlab::BackgroundMigration::DestroyInvalidMembers, :migration, schema: 20221111123146 do
+RSpec.describe Gitlab::BackgroundMigration::DestroyInvalidMembers, :migration, schema: 20230216060333 do
let!(:migration_attrs) do
{
start_id: 1,
@@ -124,7 +124,7 @@ RSpec.describe Gitlab::BackgroundMigration::DestroyInvalidMembers, :migration, s
expect(Gitlab::AppLogger).to receive(:info).with({ message: 'Removing invalid member records',
deleted_count: 4,
- deleted_member_data: member_data })
+ deleted_member_data: match_array(member_data) })
perform_migration
end
diff --git a/spec/lib/gitlab/background_migration/disable_legacy_open_source_license_for_no_issues_no_repo_projects_spec.rb b/spec/lib/gitlab/background_migration/disable_legacy_open_source_license_for_no_issues_no_repo_projects_spec.rb
deleted file mode 100644
index 8afbd7403d3..00000000000
--- a/spec/lib/gitlab/background_migration/disable_legacy_open_source_license_for_no_issues_no_repo_projects_spec.rb
+++ /dev/null
@@ -1,63 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-
-RSpec.describe Gitlab::BackgroundMigration::DisableLegacyOpenSourceLicenseForNoIssuesNoRepoProjects,
- :migration,
- schema: 20221111123146 do
- let(:namespaces_table) { table(:namespaces) }
- let(:projects_table) { table(:projects) }
- let(:project_settings_table) { table(:project_settings) }
- let(:project_statistics_table) { table(:project_statistics) }
- let(:issues_table) { table(:issues) }
-
- subject(:perform_migration) do
- described_class.new(
- start_id: projects_table.minimum(:id),
- end_id: projects_table.maximum(:id),
- batch_table: :projects,
- batch_column: :id,
- sub_batch_size: 2,
- pause_ms: 0,
- connection: ActiveRecord::Base.connection
- ).perform
- end
-
- it 'sets `legacy_open_source_license_available` to false only for public projects with no issues and no repo',
- :aggregate_failures do
- project_with_no_issues_no_repo = create_legacy_license_public_project('project-with-no-issues-no-repo')
- project_with_repo = create_legacy_license_public_project('project-with-repo', repo_size: 1)
- project_with_issues = create_legacy_license_public_project('project-with-issues', with_issue: true)
- project_with_issues_and_repo =
- create_legacy_license_public_project('project-with-issues-and-repo', repo_size: 1, with_issue: true)
-
- queries = ActiveRecord::QueryRecorder.new { perform_migration }
-
- expect(queries.count).to eq(7)
- expect(migrated_attribute(project_with_no_issues_no_repo)).to be_falsey
- expect(migrated_attribute(project_with_repo)).to be_truthy
- expect(migrated_attribute(project_with_issues)).to be_truthy
- expect(migrated_attribute(project_with_issues_and_repo)).to be_truthy
- end
-
- def create_legacy_license_public_project(path, repo_size: 0, with_issue: false)
- namespace = namespaces_table.create!(name: "namespace-#{path}", path: "namespace-#{path}")
- project_namespace = namespaces_table.create!(
- name: "-project-namespace-#{path}", path: "project-namespace-#{path}", type: 'Project'
- )
- project = projects_table.create!(
- name: path, path: path, namespace_id: namespace.id,
- project_namespace_id: project_namespace.id, visibility_level: 20
- )
-
- project_statistics_table.create!(project_id: project.id, namespace_id: namespace.id, repository_size: repo_size)
- issues_table.create!(project_id: project.id, namespace_id: project.project_namespace_id) if with_issue
- project_settings_table.create!(project_id: project.id, legacy_open_source_license_available: true)
-
- project
- end
-
- def migrated_attribute(project)
- project_settings_table.find(project.id).legacy_open_source_license_available
- end
-end
diff --git a/spec/lib/gitlab/background_migration/disable_legacy_open_source_license_for_one_member_no_repo_projects_spec.rb b/spec/lib/gitlab/background_migration/disable_legacy_open_source_license_for_one_member_no_repo_projects_spec.rb
index 185e2da6f1d..9ad54c35087 100644
--- a/spec/lib/gitlab/background_migration/disable_legacy_open_source_license_for_one_member_no_repo_projects_spec.rb
+++ b/spec/lib/gitlab/background_migration/disable_legacy_open_source_license_for_one_member_no_repo_projects_spec.rb
@@ -4,7 +4,7 @@ require 'spec_helper'
RSpec.describe Gitlab::BackgroundMigration::DisableLegacyOpenSourceLicenseForOneMemberNoRepoProjects,
:migration,
- schema: 20221111123146 do
+ schema: 20230216060333 do
let(:namespaces_table) { table(:namespaces) }
let(:projects_table) { table(:projects) }
let(:project_settings_table) { table(:project_settings) }
diff --git a/spec/lib/gitlab/background_migration/disable_legacy_open_source_license_for_projects_less_than_five_mb_spec.rb b/spec/lib/gitlab/background_migration/disable_legacy_open_source_license_for_projects_less_than_five_mb_spec.rb
index fedee9c5068..0c9c1dbde9a 100644
--- a/spec/lib/gitlab/background_migration/disable_legacy_open_source_license_for_projects_less_than_five_mb_spec.rb
+++ b/spec/lib/gitlab/background_migration/disable_legacy_open_source_license_for_projects_less_than_five_mb_spec.rb
@@ -4,7 +4,7 @@ require 'spec_helper'
RSpec.describe Gitlab::BackgroundMigration::DisableLegacyOpenSourceLicenseForProjectsLessThanFiveMb,
:migration,
- schema: 20221018095434,
+ schema: 20230216060333,
feature_category: :groups_and_projects do
let(:namespaces_table) { table(:namespaces) }
let(:projects_table) { table(:projects) }
diff --git a/spec/lib/gitlab/background_migration/disable_legacy_open_source_license_for_projects_less_than_one_mb_spec.rb b/spec/lib/gitlab/background_migration/disable_legacy_open_source_license_for_projects_less_than_one_mb_spec.rb
index f1ec09840ab..16144643296 100644
--- a/spec/lib/gitlab/background_migration/disable_legacy_open_source_license_for_projects_less_than_one_mb_spec.rb
+++ b/spec/lib/gitlab/background_migration/disable_legacy_open_source_license_for_projects_less_than_one_mb_spec.rb
@@ -4,7 +4,7 @@ require 'spec_helper'
RSpec.describe Gitlab::BackgroundMigration::DisableLegacyOpenSourceLicenseForProjectsLessThanOneMb,
:migration,
- schema: 20221111123146 do
+ schema: 20230216060333 do
let(:namespaces_table) { table(:namespaces) }
let(:projects_table) { table(:projects) }
let(:project_settings_table) { table(:project_settings) }
diff --git a/spec/lib/gitlab/background_migration/expire_o_auth_tokens_spec.rb b/spec/lib/gitlab/background_migration/expire_o_auth_tokens_spec.rb
deleted file mode 100644
index 4997ae3763e..00000000000
--- a/spec/lib/gitlab/background_migration/expire_o_auth_tokens_spec.rb
+++ /dev/null
@@ -1,36 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-
-RSpec.describe Gitlab::BackgroundMigration::ExpireOAuthTokens, :migration, schema: 20221111123146 do
- let(:migration) { described_class.new }
- let(:oauth_access_tokens_table) { table(:oauth_access_tokens) }
-
- let(:table_name) { 'oauth_access_tokens' }
-
- subject(:perform_migration) do
- described_class.new(
- start_id: 1,
- end_id: 30,
- batch_table: :oauth_access_tokens,
- batch_column: :id,
- sub_batch_size: 2,
- pause_ms: 0,
- connection: ActiveRecord::Base.connection
- ).perform
- end
-
- before do
- oauth_access_tokens_table.create!(id: 1, token: 's3cr3t-1', expires_in: nil)
- oauth_access_tokens_table.create!(id: 2, token: 's3cr3t-2', expires_in: 42)
- oauth_access_tokens_table.create!(id: 3, token: 's3cr3t-3', expires_in: nil)
- end
-
- it 'adds expiry to oauth tokens', :aggregate_failures do
- expect(ActiveRecord::QueryRecorder.new { perform_migration }.count).to eq(3)
-
- expect(oauth_access_tokens_table.find(1).expires_in).to eq(7_200)
- expect(oauth_access_tokens_table.find(2).expires_in).to eq(42)
- expect(oauth_access_tokens_table.find(3).expires_in).to eq(7_200)
- end
-end
diff --git a/spec/lib/gitlab/background_migration/nullify_creator_id_column_of_orphaned_projects_spec.rb b/spec/lib/gitlab/background_migration/nullify_creator_id_column_of_orphaned_projects_spec.rb
index facc3c435da..82a3f548e02 100644
--- a/spec/lib/gitlab/background_migration/nullify_creator_id_column_of_orphaned_projects_spec.rb
+++ b/spec/lib/gitlab/background_migration/nullify_creator_id_column_of_orphaned_projects_spec.rb
@@ -3,7 +3,7 @@
require 'spec_helper'
RSpec.describe Gitlab::BackgroundMigration::NullifyCreatorIdColumnOfOrphanedProjects,
- feature_category: :groups_and_projects, schema: 20230130073109 do
+ feature_category: :groups_and_projects, schema: 20230216060333 do
let(:users) { table(:users) }
let(:projects) { table(:projects) }
let(:namespaces) { table(:namespaces) }
diff --git a/spec/lib/gitlab/background_migration/populate_projects_star_count_spec.rb b/spec/lib/gitlab/background_migration/populate_projects_star_count_spec.rb
index 35f93c9982b..c41eb98bc5d 100644
--- a/spec/lib/gitlab/background_migration/populate_projects_star_count_spec.rb
+++ b/spec/lib/gitlab/background_migration/populate_projects_star_count_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-RSpec.describe Gitlab::BackgroundMigration::PopulateProjectsStarCount, schema: 20221111123146 do
+RSpec.describe Gitlab::BackgroundMigration::PopulateProjectsStarCount, schema: 20230216060333 do
let(:namespaces) { table(:namespaces) }
let(:projects) { table(:projects) }
let(:users) { table(:users) }
diff --git a/spec/lib/gitlab/background_migration/remove_project_group_link_with_missing_groups_spec.rb b/spec/lib/gitlab/background_migration/remove_project_group_link_with_missing_groups_spec.rb
deleted file mode 100644
index 126e928fa77..00000000000
--- a/spec/lib/gitlab/background_migration/remove_project_group_link_with_missing_groups_spec.rb
+++ /dev/null
@@ -1,124 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-
-RSpec.describe Gitlab::BackgroundMigration::RemoveProjectGroupLinkWithMissingGroups, :migration,
- feature_category: :groups_and_projects, schema: 20230206172702 do
- let(:projects) { table(:projects) }
- let(:namespaces) { table(:namespaces) }
- let(:project_group_links) { table(:project_group_links) }
-
- let!(:group) do
- namespaces.create!(
- name: 'Group0', type: 'Group', path: 'space0'
- )
- end
-
- let!(:group_1) do
- namespaces.create!(
- name: 'Group1', type: 'Group', path: 'space1'
- )
- end
-
- let!(:group_2) do
- namespaces.create!(
- name: 'Group2', type: 'Group', path: 'space2'
- )
- end
-
- let!(:group_3) do
- namespaces.create!(
- name: 'Group3', type: 'Group', path: 'space3'
- )
- end
-
- let!(:project_namespace_1) do
- namespaces.create!(
- name: 'project_1', path: 'project_1', type: 'Project'
- )
- end
-
- let!(:project_namespace_2) do
- namespaces.create!(
- name: 'project_2', path: 'project_2', type: 'Project'
- )
- end
-
- let!(:project_namespace_3) do
- namespaces.create!(
- name: 'project_3', path: 'project_3', type: 'Project'
- )
- end
-
- let!(:project_1) do
- projects.create!(
- name: 'project_1', path: 'project_1', namespace_id: group.id, project_namespace_id: project_namespace_1.id
- )
- end
-
- let!(:project_2) do
- projects.create!(
- name: 'project_2', path: 'project_2', namespace_id: group.id, project_namespace_id: project_namespace_2.id
- )
- end
-
- let!(:project_3) do
- projects.create!(
- name: 'project_3', path: 'project_3', namespace_id: group.id, project_namespace_id: project_namespace_3.id
- )
- end
-
- let!(:project_group_link_1) do
- project_group_links.create!(
- project_id: project_1.id, group_id: group_1.id, group_access: Gitlab::Access::DEVELOPER
- )
- end
-
- let!(:project_group_link_2) do
- project_group_links.create!(
- project_id: project_2.id, group_id: group_2.id, group_access: Gitlab::Access::DEVELOPER
- )
- end
-
- let!(:project_group_link_3) do
- project_group_links.create!(
- project_id: project_3.id, group_id: group_3.id, group_access: Gitlab::Access::DEVELOPER
- )
- end
-
- let!(:project_group_link_4) do
- project_group_links.create!(
- project_id: project_3.id, group_id: group_2.id, group_access: Gitlab::Access::DEVELOPER
- )
- end
-
- subject do
- described_class.new(
- start_id: project_group_link_1.id,
- end_id: project_group_link_4.id,
- batch_table: :project_group_links,
- batch_column: :id,
- sub_batch_size: 1,
- pause_ms: 0,
- connection: ApplicationRecord.connection
- ).perform
- end
-
- it 'removes the `project_group_links` records whose associated group does not exist anymore' do
- group_2.delete
-
- # Schema is fixed to `20230206172702` on this spec.
- # This expectation is needed to make sure that the orphaned records are indeed deleted via the migration
- # and not via the foreign_key relationship introduced after `20230206172702`, in `20230207002330`
- expect(project_group_links.count).to eq(4)
-
- expect { subject }
- .to change { project_group_links.count }.from(4).to(2)
- .and change {
- project_group_links.where(project_id: project_2.id, group_id: group_2.id).present?
- }.from(true).to(false)
- .and change {
- project_group_links.where(project_id: project_3.id, group_id: group_2.id).present?
- }.from(true).to(false)
- end
-end
diff --git a/spec/lib/gitlab/background_migration/remove_self_managed_wiki_notes_spec.rb b/spec/lib/gitlab/background_migration/remove_self_managed_wiki_notes_spec.rb
index 74fe2c63139..c373323c0e3 100644
--- a/spec/lib/gitlab/background_migration/remove_self_managed_wiki_notes_spec.rb
+++ b/spec/lib/gitlab/background_migration/remove_self_managed_wiki_notes_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-RSpec.describe Gitlab::BackgroundMigration::RemoveSelfManagedWikiNotes, :migration, schema: 20221111123146 do
+RSpec.describe Gitlab::BackgroundMigration::RemoveSelfManagedWikiNotes, :migration, schema: 20230216060333 do
let(:notes) { table(:notes) }
subject(:perform_migration) do
diff --git a/spec/lib/gitlab/background_migration/reset_too_many_tags_skipped_registry_imports_spec.rb b/spec/lib/gitlab/background_migration/reset_too_many_tags_skipped_registry_imports_spec.rb
index 86c2ab35136..655d8dea739 100644
--- a/spec/lib/gitlab/background_migration/reset_too_many_tags_skipped_registry_imports_spec.rb
+++ b/spec/lib/gitlab/background_migration/reset_too_many_tags_skipped_registry_imports_spec.rb
@@ -4,7 +4,7 @@ require 'spec_helper'
RSpec.describe Gitlab::BackgroundMigration::ResetTooManyTagsSkippedRegistryImports, :migration,
:aggregate_failures,
- schema: 20221111123146 do
+ schema: 20230216060333 do
let(:namespaces) { table(:namespaces) }
let(:projects) { table(:projects) }
let(:container_repositories) { table(:container_repositories) }
diff --git a/spec/lib/gitlab/background_migration/set_legacy_open_source_license_available_for_non_public_projects_spec.rb b/spec/lib/gitlab/background_migration/set_legacy_open_source_license_available_for_non_public_projects_spec.rb
index 5f7a699ac0b..91c5b60258f 100644
--- a/spec/lib/gitlab/background_migration/set_legacy_open_source_license_available_for_non_public_projects_spec.rb
+++ b/spec/lib/gitlab/background_migration/set_legacy_open_source_license_available_for_non_public_projects_spec.rb
@@ -4,7 +4,7 @@ require 'spec_helper'
RSpec.describe Gitlab::BackgroundMigration::SetLegacyOpenSourceLicenseAvailableForNonPublicProjects,
:migration,
- schema: 20221111123146 do
+ schema: 20230216060333 do
let(:namespaces_table) { table(:namespaces) }
let(:projects_table) { table(:projects) }
let(:project_settings_table) { table(:project_settings) }
diff --git a/spec/lib/gitlab/background_migration/truncate_overlong_vulnerability_html_titles_spec.rb b/spec/lib/gitlab/background_migration/truncate_overlong_vulnerability_html_titles_spec.rb
index fcd88d523bc..e4be70cb84f 100644
--- a/spec/lib/gitlab/background_migration/truncate_overlong_vulnerability_html_titles_spec.rb
+++ b/spec/lib/gitlab/background_migration/truncate_overlong_vulnerability_html_titles_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
# rubocop:disable Layout/LineLength
-RSpec.describe Gitlab::BackgroundMigration::TruncateOverlongVulnerabilityHtmlTitles, schema: 20221110100602, feature_category: :vulnerability_management do
+RSpec.describe Gitlab::BackgroundMigration::TruncateOverlongVulnerabilityHtmlTitles, schema: 20230216060333, feature_category: :vulnerability_management do
# rubocop:enable Layout/LineLength
let(:namespaces) { table(:namespaces) }
diff --git a/spec/lib/gitlab/database/migration_helpers_spec.rb b/spec/lib/gitlab/database/migration_helpers_spec.rb
index 8bf05f56b3f..13f7178924f 100644
--- a/spec/lib/gitlab/database/migration_helpers_spec.rb
+++ b/spec/lib/gitlab/database/migration_helpers_spec.rb
@@ -1055,11 +1055,16 @@ RSpec.describe Gitlab::Database::MigrationHelpers, feature_category: :database d
around do |ex|
model.transaction do
- require_migration!('add_columns_to_postgres_foreign_keys')
- AddColumnsToPostgresForeignKeys.new.down
+ require_relative '../../../fixtures/migrations/db/migrate/schema_cache_migration_test'
+
+ # Uses the init_schema migration, as it is always present in the codebase (not affected by squashing process)
+ require_migration!('init_schema')
+
+ InitSchema.prepend(SchemaCacheMigrationTest)
+ InitSchema.new.down
Gitlab::Database::PostgresForeignKey.reset_column_information
Gitlab::Database::PostgresForeignKey.columns_hash # Force populate the column hash in the old schema
- AddColumnsToPostgresForeignKeys.new.up
+ InitSchema.new.up
# Rolling back reverts the schema cache information, so we need to run the example here before the rollback.
ex.run