summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/background_migration
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/background_migration')
-rw-r--r--spec/lib/gitlab/background_migration/backfill_draft_status_on_merge_requests_spec.rb47
-rw-r--r--spec/lib/gitlab/background_migration/backfill_jira_tracker_deployment_type2_spec.rb6
-rw-r--r--spec/lib/gitlab/background_migration/backfill_upvotes_count_on_issues_spec.rb46
-rw-r--r--spec/lib/gitlab/background_migration/delete_orphaned_deployments_spec.rb63
-rw-r--r--spec/lib/gitlab/background_migration/migrate_issue_trackers_sensitive_data_spec.rb22
-rw-r--r--spec/lib/gitlab/background_migration/migrate_merge_request_diff_commit_users_spec.rb400
-rw-r--r--spec/lib/gitlab/background_migration/migrate_u2f_webauthn_spec.rb2
-rw-r--r--spec/lib/gitlab/background_migration/update_jira_tracker_data_deployment_type_based_on_url_spec.rb2
8 files changed, 573 insertions, 15 deletions
diff --git a/spec/lib/gitlab/background_migration/backfill_draft_status_on_merge_requests_spec.rb b/spec/lib/gitlab/background_migration/backfill_draft_status_on_merge_requests_spec.rb
new file mode 100644
index 00000000000..f56cf899410
--- /dev/null
+++ b/spec/lib/gitlab/background_migration/backfill_draft_status_on_merge_requests_spec.rb
@@ -0,0 +1,47 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Gitlab::BackgroundMigration::BackfillDraftStatusOnMergeRequests do
+ 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) }
+
+ let(:draft_prefixes) { ["[Draft]", "(Draft)", "Draft:", "Draft", "[WIP]", "WIP:", "WIP"] }
+
+ def create_merge_request(params)
+ common_params = {
+ target_project_id: project.id,
+ target_branch: 'feature1',
+ source_branch: 'master'
+ }
+
+ merge_requests.create!(common_params.merge(params))
+ end
+
+ context "for MRs with #draft? == true titles but draft attribute false" do
+ before do
+ draft_prefixes.each do |prefix|
+ (1..4).each do |n|
+ create_merge_request(
+ title: "#{prefix} This is a title",
+ draft: false,
+ state_id: n
+ )
+ end
+ end
+ end
+
+ it "updates all open draft merge request's draft field to true" do
+ mr_count = merge_requests.all.count
+ mr_ids = merge_requests.all.collect(&:id)
+
+ expect { subject.perform(mr_ids.first, mr_ids.last) }
+ .to change { MergeRequest.where(draft: false).count }
+ .from(mr_count).to(mr_count - draft_prefixes.length)
+ end
+ end
+end
diff --git a/spec/lib/gitlab/background_migration/backfill_jira_tracker_deployment_type2_spec.rb b/spec/lib/gitlab/background_migration/backfill_jira_tracker_deployment_type2_spec.rb
index 7fe82420364..58864aac084 100644
--- a/spec/lib/gitlab/background_migration/backfill_jira_tracker_deployment_type2_spec.rb
+++ b/spec/lib/gitlab/background_migration/backfill_jira_tracker_deployment_type2_spec.rb
@@ -3,18 +3,18 @@
require 'spec_helper'
RSpec.describe Gitlab::BackgroundMigration::BackfillJiraTrackerDeploymentType2, :migration, schema: 20201028182809 do
- let_it_be(:jira_service_temp) { described_class::JiraServiceTemp }
+ let_it_be(:jira_integration_temp) { described_class::JiraServiceTemp }
let_it_be(:jira_tracker_data_temp) { described_class::JiraTrackerDataTemp }
let_it_be(:atlassian_host) { 'https://api.atlassian.net' }
let_it_be(:mixedcase_host) { 'https://api.AtlassiaN.nEt' }
let_it_be(:server_host) { 'https://my.server.net' }
- let(:jira_service) { jira_service_temp.create!(type: 'JiraService', active: true, category: 'issue_tracker') }
+ let(:jira_integration) { jira_integration_temp.create!(type: 'JiraService', active: true, category: 'issue_tracker') }
subject { described_class.new }
def create_tracker_data(options = {})
- jira_tracker_data_temp.create!({ service_id: jira_service.id }.merge(options))
+ jira_tracker_data_temp.create!({ service_id: jira_integration.id }.merge(options))
end
describe '#perform' do
diff --git a/spec/lib/gitlab/background_migration/backfill_upvotes_count_on_issues_spec.rb b/spec/lib/gitlab/background_migration/backfill_upvotes_count_on_issues_spec.rb
new file mode 100644
index 00000000000..b084e3fe885
--- /dev/null
+++ b/spec/lib/gitlab/background_migration/backfill_upvotes_count_on_issues_spec.rb
@@ -0,0 +1,46 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Gitlab::BackgroundMigration::BackfillUpvotesCountOnIssues, schema: 20210701111909 do
+ let(:award_emoji) { table(:award_emoji) }
+
+ let!(:namespace) { table(:namespaces).create!(name: 'namespace', path: 'namespace') }
+ let!(:project1) { table(:projects).create!(namespace_id: namespace.id) }
+ let!(:project2) { table(:projects).create!(namespace_id: namespace.id) }
+ let!(:issue1) { table(:issues).create!(project_id: project1.id) }
+ let!(:issue2) { table(:issues).create!(project_id: project2.id) }
+ let!(:issue3) { table(:issues).create!(project_id: project2.id) }
+ let!(:issue4) { table(:issues).create!(project_id: project2.id) }
+
+ describe '#perform' do
+ before do
+ add_upvotes(issue1, :thumbsdown, 1)
+ add_upvotes(issue2, :thumbsup, 2)
+ add_upvotes(issue2, :thumbsdown, 1)
+ add_upvotes(issue3, :thumbsup, 3)
+ add_upvotes(issue4, :thumbsup, 4)
+ end
+
+ it 'updates upvotes_count' do
+ subject.perform(issue1.id, issue4.id)
+
+ expect(issue1.reload.upvotes_count).to eq(0)
+ expect(issue2.reload.upvotes_count).to eq(2)
+ expect(issue3.reload.upvotes_count).to eq(3)
+ expect(issue4.reload.upvotes_count).to eq(4)
+ end
+ end
+
+ private
+
+ def add_upvotes(issue, name, count)
+ count.times do
+ award_emoji.create!(
+ name: name.to_s,
+ awardable_type: 'Issue',
+ awardable_id: issue.id
+ )
+ end
+ end
+end
diff --git a/spec/lib/gitlab/background_migration/delete_orphaned_deployments_spec.rb b/spec/lib/gitlab/background_migration/delete_orphaned_deployments_spec.rb
new file mode 100644
index 00000000000..c4039b85459
--- /dev/null
+++ b/spec/lib/gitlab/background_migration/delete_orphaned_deployments_spec.rb
@@ -0,0 +1,63 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Gitlab::BackgroundMigration::DeleteOrphanedDeployments, :migration, schema: 20210617161348 do
+ let!(:namespace) { table(:namespaces).create!(name: 'user', path: 'user') }
+ let!(:project) { table(:projects).create!(namespace_id: namespace.id) }
+ let!(:environment) { table(:environments).create!(name: 'production', slug: 'production', project_id: project.id) }
+ let(:background_migration_jobs) { table(:background_migration_jobs) }
+
+ before do
+ create_deployment!(environment.id, project.id)
+ create_deployment!(non_existing_record_id, project.id)
+ end
+
+ it 'deletes only orphaned deployments' do
+ expect(valid_deployments.pluck(:id)).not_to be_empty
+ expect(orphaned_deployments.pluck(:id)).not_to be_empty
+
+ subject.perform(table(:deployments).minimum(:id), table(:deployments).maximum(:id))
+
+ expect(valid_deployments.pluck(:id)).not_to be_empty
+ expect(orphaned_deployments.pluck(:id)).to be_empty
+ end
+
+ it 'marks jobs as done' do
+ first_job = background_migration_jobs.create!(
+ class_name: 'DeleteOrphanedDeployments',
+ arguments: [table(:deployments).minimum(:id), table(:deployments).minimum(:id)]
+ )
+
+ second_job = background_migration_jobs.create!(
+ class_name: 'DeleteOrphanedDeployments',
+ arguments: [table(:deployments).maximum(:id), table(:deployments).maximum(:id)]
+ )
+
+ subject.perform(table(:deployments).minimum(:id), table(:deployments).minimum(:id))
+
+ expect(first_job.reload.status).to eq(Gitlab::Database::BackgroundMigrationJob.statuses[:succeeded])
+ expect(second_job.reload.status).to eq(Gitlab::Database::BackgroundMigrationJob.statuses[:pending])
+ end
+
+ private
+
+ def valid_deployments
+ table(:deployments).where('EXISTS (SELECT 1 FROM environments WHERE deployments.environment_id = environments.id)')
+ end
+
+ def orphaned_deployments
+ table(:deployments).where('NOT EXISTS (SELECT 1 FROM environments WHERE deployments.environment_id = environments.id)')
+ end
+
+ def create_deployment!(environment_id, project_id)
+ table(:deployments).create!(
+ environment_id: environment_id,
+ project_id: project_id,
+ ref: 'master',
+ tag: false,
+ sha: 'x',
+ status: 1,
+ iid: table(:deployments).count + 1)
+ end
+end
diff --git a/spec/lib/gitlab/background_migration/migrate_issue_trackers_sensitive_data_spec.rb b/spec/lib/gitlab/background_migration/migrate_issue_trackers_sensitive_data_spec.rb
index 80879c8c6d9..f2cd2acd4f3 100644
--- a/spec/lib/gitlab/background_migration/migrate_issue_trackers_sensitive_data_spec.rb
+++ b/spec/lib/gitlab/background_migration/migrate_issue_trackers_sensitive_data_spec.rb
@@ -283,11 +283,11 @@ RSpec.describe Gitlab::BackgroundMigration::MigrateIssueTrackersSensitiveData, s
end
context 'with Jira service with invalid properties, valid Jira service and valid bugzilla service' do
- let!(:jira_service_invalid) do
+ let!(:jira_integration_invalid) do
services.create!(id: 19, title: 'invalid - title', description: 'invalid - description', type: 'JiraService', properties: 'invalid data', category: 'issue_tracker')
end
- let!(:jira_service_valid) do
+ let!(:jira_integration_valid) do
services.create!(id: 20, type: 'JiraService', properties: jira_properties.to_json, category: 'issue_tracker')
end
@@ -298,21 +298,21 @@ RSpec.describe Gitlab::BackgroundMigration::MigrateIssueTrackersSensitiveData, s
it 'migrates data for the valid service' do
subject
- jira_service_invalid.reload
- expect(JiraTrackerData.find_by(service_id: jira_service_invalid.id)).to be_nil
- expect(jira_service_invalid.title).to eq('invalid - title')
- expect(jira_service_invalid.description).to eq('invalid - description')
- expect(jira_service_invalid.properties).to eq('invalid data')
+ jira_integration_invalid.reload
+ expect(JiraTrackerData.find_by(service_id: jira_integration_invalid.id)).to be_nil
+ expect(jira_integration_invalid.title).to eq('invalid - title')
+ expect(jira_integration_invalid.description).to eq('invalid - description')
+ expect(jira_integration_invalid.properties).to eq('invalid data')
- jira_service_valid.reload
- data = JiraTrackerData.find_by(service_id: jira_service_valid.id)
+ jira_integration_valid.reload
+ data = JiraTrackerData.find_by(service_id: jira_integration_valid.id)
expect(data.url).to eq(url)
expect(data.api_url).to eq(api_url)
expect(data.username).to eq(username)
expect(data.password).to eq(password)
- expect(jira_service_valid.title).to eq(title)
- expect(jira_service_valid.description).to eq(description)
+ expect(jira_integration_valid.title).to eq(title)
+ expect(jira_integration_valid.description).to eq(description)
bugzilla_integration_valid.reload
data = IssueTrackerData.find_by(service_id: bugzilla_integration_valid.id)
diff --git a/spec/lib/gitlab/background_migration/migrate_merge_request_diff_commit_users_spec.rb b/spec/lib/gitlab/background_migration/migrate_merge_request_diff_commit_users_spec.rb
new file mode 100644
index 00000000000..496ce151032
--- /dev/null
+++ b/spec/lib/gitlab/background_migration/migrate_merge_request_diff_commit_users_spec.rb
@@ -0,0 +1,400 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Gitlab::BackgroundMigration::MigrateMergeRequestDiffCommitUsers do
+ let(:namespaces) { table(:namespaces) }
+ let(:projects) { table(:projects) }
+ let(:users) { table(:users) }
+ let(:merge_requests) { table(:merge_requests) }
+ let(:diffs) { table(:merge_request_diffs) }
+ let(:commits) do
+ table(:merge_request_diff_commits).tap do |t|
+ t.extend(SuppressCompositePrimaryKeyWarning)
+ end
+ end
+
+ let(:commit_users) { described_class::MergeRequestDiffCommitUser }
+
+ let(:namespace) { namespaces.create!(name: 'foo', path: 'foo') }
+ let(:project) { projects.create!(namespace_id: namespace.id) }
+ let(:merge_request) do
+ merge_requests.create!(
+ source_branch: 'x',
+ target_branch: 'master',
+ target_project_id: project.id
+ )
+ end
+
+ let(:diff) { diffs.create!(merge_request_id: merge_request.id) }
+ let(:migration) { described_class.new }
+
+ describe 'MergeRequestDiffCommit' do
+ describe '.each_row_to_migrate' do
+ it 'yields the rows to migrate for a given range' do
+ commit1 = commits.create!(
+ merge_request_diff_id: diff.id,
+ relative_order: 0,
+ sha: Gitlab::Database::ShaAttribute.serialize('123abc'),
+ author_name: 'bob',
+ author_email: 'bob@example.com',
+ committer_name: 'bob',
+ committer_email: 'bob@example.com'
+ )
+
+ commit2 = commits.create!(
+ merge_request_diff_id: diff.id,
+ relative_order: 1,
+ sha: Gitlab::Database::ShaAttribute.serialize('123abc'),
+ author_name: 'Alice',
+ author_email: 'alice@example.com',
+ committer_name: 'Alice',
+ committer_email: 'alice@example.com'
+ )
+
+ # We stub this constant to make sure we run at least two pagination
+ # queries for getting the data. This way we can test if the pagination
+ # is actually working properly.
+ stub_const(
+ 'Gitlab::BackgroundMigration::MigrateMergeRequestDiffCommitUsers::COMMIT_ROWS_PER_QUERY',
+ 1
+ )
+
+ rows = []
+
+ described_class::MergeRequestDiffCommit.each_row_to_migrate(diff.id, diff.id + 1) do |row|
+ rows << row
+ end
+
+ expect(rows.length).to eq(2)
+
+ expect(rows[0].author_name).to eq(commit1.author_name)
+ expect(rows[1].author_name).to eq(commit2.author_name)
+ end
+ end
+ end
+
+ describe 'MergeRequestDiffCommitUser' do
+ describe '.union' do
+ it 'produces a union of the given queries' do
+ alice = commit_users.create!(name: 'Alice', email: 'alice@example.com')
+ bob = commit_users.create!(name: 'Bob', email: 'bob@example.com')
+ users = commit_users.union([
+ commit_users.where(name: 'Alice').to_sql,
+ commit_users.where(name: 'Bob').to_sql
+ ])
+
+ expect(users).to include(alice)
+ expect(users).to include(bob)
+ end
+ end
+ end
+
+ describe '#perform' do
+ it 'migrates the data in the range' do
+ commits.create!(
+ merge_request_diff_id: diff.id,
+ relative_order: 0,
+ sha: Gitlab::Database::ShaAttribute.serialize('123abc'),
+ author_name: 'bob',
+ author_email: 'bob@example.com',
+ committer_name: 'bob',
+ committer_email: 'bob@example.com'
+ )
+
+ migration.perform(diff.id, diff.id + 1)
+
+ bob = commit_users.find_by(name: 'bob')
+ commit = commits.first
+
+ expect(commit.commit_author_id).to eq(bob.id)
+ expect(commit.committer_id).to eq(bob.id)
+ end
+
+ it 'treats empty names and Emails the same as NULL values' do
+ commits.create!(
+ merge_request_diff_id: diff.id,
+ relative_order: 0,
+ sha: Gitlab::Database::ShaAttribute.serialize('123abc'),
+ author_name: 'bob',
+ author_email: 'bob@example.com',
+ committer_name: '',
+ committer_email: ''
+ )
+
+ migration.perform(diff.id, diff.id + 1)
+
+ bob = commit_users.find_by(name: 'bob')
+ commit = commits.first
+
+ expect(commit.commit_author_id).to eq(bob.id)
+ expect(commit.committer_id).to be_nil
+ end
+
+ it 'does not update rows without a committer and author' do
+ commits.create!(
+ merge_request_diff_id: diff.id,
+ relative_order: 0,
+ sha: Gitlab::Database::ShaAttribute.serialize('123abc')
+ )
+
+ migration.perform(diff.id, diff.id + 1)
+
+ commit = commits.first
+
+ expect(commit_users.count).to eq(0)
+ expect(commit.commit_author_id).to be_nil
+ expect(commit.committer_id).to be_nil
+ end
+
+ it 'marks the background job as done' do
+ Gitlab::Database::BackgroundMigrationJob.create!(
+ class_name: 'MigrateMergeRequestDiffCommitUsers',
+ arguments: [diff.id, diff.id + 1]
+ )
+
+ migration.perform(diff.id, diff.id + 1)
+
+ job = Gitlab::Database::BackgroundMigrationJob.first
+
+ expect(job.status).to eq('succeeded')
+ end
+ end
+
+ describe '#get_data_to_update' do
+ it 'returns the users and commit rows to update' do
+ commits.create!(
+ merge_request_diff_id: diff.id,
+ relative_order: 0,
+ sha: Gitlab::Database::ShaAttribute.serialize('123abc'),
+ author_name: 'bob' + ('a' * 510),
+ author_email: 'bob@example.com',
+ committer_name: 'bob' + ('a' * 510),
+ committer_email: 'bob@example.com'
+ )
+
+ commits.create!(
+ merge_request_diff_id: diff.id,
+ relative_order: 1,
+ sha: Gitlab::Database::ShaAttribute.serialize('456abc'),
+ author_name: 'alice',
+ author_email: 'alice@example.com',
+ committer_name: 'alice',
+ committer_email: 'alice@example.com'
+ )
+
+ users, to_update = migration.get_data_to_update(diff.id, diff.id + 1)
+
+ bob_name = 'bob' + ('a' * 509)
+
+ expect(users).to include(%w[alice alice@example.com])
+ expect(users).to include([bob_name, 'bob@example.com'])
+
+ expect(to_update[[diff.id, 0]])
+ .to eq([[bob_name, 'bob@example.com'], [bob_name, 'bob@example.com']])
+
+ expect(to_update[[diff.id, 1]])
+ .to eq([%w[alice alice@example.com], %w[alice alice@example.com]])
+ end
+
+ it 'does not include a user if both the name and Email are missing' do
+ commits.create!(
+ merge_request_diff_id: diff.id,
+ relative_order: 0,
+ sha: Gitlab::Database::ShaAttribute.serialize('123abc'),
+ author_name: nil,
+ author_email: nil,
+ committer_name: 'bob',
+ committer_email: 'bob@example.com'
+ )
+
+ users, _ = migration.get_data_to_update(diff.id, diff.id + 1)
+
+ expect(users).to eq([%w[bob bob@example.com]].to_set)
+ end
+ end
+
+ describe '#get_user_rows_in_batches' do
+ it 'retrieves all existing users' do
+ alice = commit_users.create!(name: 'alice', email: 'alice@example.com')
+ bob = commit_users.create!(name: 'bob', email: 'bob@example.com')
+
+ users = [[alice.name, alice.email], [bob.name, bob.email]]
+ mapping = {}
+
+ migration.get_user_rows_in_batches(users, mapping)
+
+ expect(mapping[%w[alice alice@example.com]]).to eq(alice)
+ expect(mapping[%w[bob bob@example.com]]).to eq(bob)
+ end
+ end
+
+ describe '#create_missing_users' do
+ it 'creates merge request diff commit users that are missing' do
+ alice = commit_users.create!(name: 'alice', email: 'alice@example.com')
+ users = [%w[alice alice@example.com], %w[bob bob@example.com]]
+ mapping = { %w[alice alice@example.com] => alice }
+
+ migration.create_missing_users(users, mapping)
+
+ expect(mapping[%w[alice alice@example.com]]).to eq(alice)
+ expect(mapping[%w[bob bob@example.com]].name).to eq('bob')
+ expect(mapping[%w[bob bob@example.com]].email).to eq('bob@example.com')
+ end
+ end
+
+ describe '#update_commit_rows' do
+ it 'updates the merge request diff commit rows' do
+ to_update = { [42, 0] => [%w[alice alice@example.com], []] }
+ user_mapping = { %w[alice alice@example.com] => double(:user, id: 1) }
+
+ expect(migration)
+ .to receive(:bulk_update_commit_rows)
+ .with({ [42, 0] => [1, nil] })
+
+ migration.update_commit_rows(to_update, user_mapping)
+ end
+ end
+
+ describe '#bulk_update_commit_rows' do
+ context 'when there are no authors and committers' do
+ it 'does not update any rows' do
+ migration.bulk_update_commit_rows({ [1, 0] => [] })
+
+ expect(described_class::MergeRequestDiffCommit.connection)
+ .not_to receive(:execute)
+ end
+ end
+
+ context 'when there are only authors' do
+ it 'only updates the author IDs' do
+ author = commit_users.create!(name: 'Alice', email: 'alice@example.com')
+ commit = commits.create!(
+ merge_request_diff_id: diff.id,
+ relative_order: 0,
+ sha: Gitlab::Database::ShaAttribute.serialize('123abc')
+ )
+
+ mapping = {
+ [commit.merge_request_diff_id, commit.relative_order] =>
+ [author.id, nil]
+ }
+
+ migration.bulk_update_commit_rows(mapping)
+
+ commit = commits.first
+
+ expect(commit.commit_author_id).to eq(author.id)
+ expect(commit.committer_id).to be_nil
+ end
+ end
+
+ context 'when there are only committers' do
+ it 'only updates the committer IDs' do
+ committer =
+ commit_users.create!(name: 'Alice', email: 'alice@example.com')
+
+ commit = commits.create!(
+ merge_request_diff_id: diff.id,
+ relative_order: 0,
+ sha: Gitlab::Database::ShaAttribute.serialize('123abc')
+ )
+
+ mapping = {
+ [commit.merge_request_diff_id, commit.relative_order] =>
+ [nil, committer.id]
+ }
+
+ migration.bulk_update_commit_rows(mapping)
+
+ commit = commits.first
+
+ expect(commit.committer_id).to eq(committer.id)
+ expect(commit.commit_author_id).to be_nil
+ end
+ end
+
+ context 'when there are both authors and committers' do
+ it 'updates both the author and committer IDs' do
+ author = commit_users.create!(name: 'Bob', email: 'bob@example.com')
+ committer =
+ commit_users.create!(name: 'Alice', email: 'alice@example.com')
+
+ commit = commits.create!(
+ merge_request_diff_id: diff.id,
+ relative_order: 0,
+ sha: Gitlab::Database::ShaAttribute.serialize('123abc')
+ )
+
+ mapping = {
+ [commit.merge_request_diff_id, commit.relative_order] =>
+ [author.id, committer.id]
+ }
+
+ migration.bulk_update_commit_rows(mapping)
+
+ commit = commits.first
+
+ expect(commit.commit_author_id).to eq(author.id)
+ expect(commit.committer_id).to eq(committer.id)
+ end
+ end
+
+ context 'when there are multiple commit rows to update' do
+ it 'updates all the rows' do
+ author = commit_users.create!(name: 'Bob', email: 'bob@example.com')
+ committer =
+ commit_users.create!(name: 'Alice', email: 'alice@example.com')
+
+ commit1 = commits.create!(
+ merge_request_diff_id: diff.id,
+ relative_order: 0,
+ sha: Gitlab::Database::ShaAttribute.serialize('123abc')
+ )
+
+ commit2 = commits.create!(
+ merge_request_diff_id: diff.id,
+ relative_order: 1,
+ sha: Gitlab::Database::ShaAttribute.serialize('456abc')
+ )
+
+ mapping = {
+ [commit1.merge_request_diff_id, commit1.relative_order] =>
+ [author.id, committer.id],
+
+ [commit2.merge_request_diff_id, commit2.relative_order] =>
+ [author.id, nil]
+ }
+
+ migration.bulk_update_commit_rows(mapping)
+
+ commit1 = commits.find_by(relative_order: 0)
+ commit2 = commits.find_by(relative_order: 1)
+
+ expect(commit1.commit_author_id).to eq(author.id)
+ expect(commit1.committer_id).to eq(committer.id)
+
+ expect(commit2.commit_author_id).to eq(author.id)
+ expect(commit2.committer_id).to be_nil
+ end
+ end
+ end
+
+ describe '#primary_key' do
+ it 'returns the primary key for the commits table' do
+ key = migration.primary_key
+
+ expect(key.to_sql).to eq('("merge_request_diff_commits"."merge_request_diff_id", "merge_request_diff_commits"."relative_order")')
+ end
+ end
+
+ describe '#prepare' do
+ it 'trims a value to at most 512 characters' do
+ expect(migration.prepare('€' * 1_000)).to eq('€' * 512)
+ end
+
+ it 'returns nil if the value is an empty string' do
+ expect(migration.prepare('')).to be_nil
+ end
+ end
+end
diff --git a/spec/lib/gitlab/background_migration/migrate_u2f_webauthn_spec.rb b/spec/lib/gitlab/background_migration/migrate_u2f_webauthn_spec.rb
index 33498ffa748..9eda51f6ec4 100644
--- a/spec/lib/gitlab/background_migration/migrate_u2f_webauthn_spec.rb
+++ b/spec/lib/gitlab/background_migration/migrate_u2f_webauthn_spec.rb
@@ -2,6 +2,8 @@
require 'spec_helper'
+require 'webauthn/u2f_migrator'
+
RSpec.describe Gitlab::BackgroundMigration::MigrateU2fWebauthn, :migration, schema: 20200925125321 do
let(:users) { table(:users) }
diff --git a/spec/lib/gitlab/background_migration/update_jira_tracker_data_deployment_type_based_on_url_spec.rb b/spec/lib/gitlab/background_migration/update_jira_tracker_data_deployment_type_based_on_url_spec.rb
index f7466a2ddfd..b96d3f7f0b5 100644
--- a/spec/lib/gitlab/background_migration/update_jira_tracker_data_deployment_type_based_on_url_spec.rb
+++ b/spec/lib/gitlab/background_migration/update_jira_tracker_data_deployment_type_based_on_url_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-RSpec.describe Gitlab::BackgroundMigration::UpdateJiraTrackerDataDeploymentTypeBasedOnUrl do
+RSpec.describe Gitlab::BackgroundMigration::UpdateJiraTrackerDataDeploymentTypeBasedOnUrl, schema: 20210421163509 do
let(:services_table) { table(:services) }
let(:service_jira_cloud) { services_table.create!(id: 1, type: 'JiraService') }
let(:service_jira_server) { services_table.create!(id: 2, type: 'JiraService') }