Commit 4991cc1d authored by Andreas Brandl's avatar Andreas Brandl

Merge branch '330276-noop-migration-with-faulty-sql-regex' into 'master'

Noop migrations containing faulty SQL regex

See merge request gitlab-org/gitlab!68296
parents b9552fca 4fe9fac7
# frozen_string_literal: true
class RemoveIndexContainingFaultyRegex < ActiveRecord::Migration[6.1]
include Gitlab::Database::MigrationHelpers
INDEX_NAME = "tmp_index_merge_requests_draft_and_status"
disable_ddl_transaction!
def up
remove_concurrent_index_by_name :merge_requests, INDEX_NAME
end
def down
# noop
#
end
end
# frozen_string_literal: true
class ScheduleBackfillDraftStatusOnMergeRequests < ActiveRecord::Migration[6.1]
include Gitlab::Database::MigrationHelpers
INDEX_NAME = "tmp_index_merge_requests_draft_and_status"
MIGRATION = 'BackfillDraftStatusOnMergeRequests'
DELAY_INTERVAL = 2.minutes
BATCH_SIZE = 100
disable_ddl_transaction!
def up
add_concurrent_index :merge_requests, :id,
where: "draft = false AND state_id = 1 AND ((title)::text ~* '^\\[draft\\]|\\(draft\\)|draft:|draft|\\[WIP\\]|WIP:|WIP'::text)",
name: INDEX_NAME
eligible_mrs = Gitlab::BackgroundMigration::BackfillDraftStatusOnMergeRequests::MergeRequest.eligible
queue_background_migration_jobs_by_range_at_intervals(
eligible_mrs,
MIGRATION,
DELAY_INTERVAL,
track_jobs: true,
batch_size: BATCH_SIZE
)
# noop
#
end
def down
remove_concurrent_index_by_name :merge_requests, INDEX_NAME
# noop
#
end
end
# frozen_string_literal: true
class ScheduleBackfillDraftColumnOnMergeRequestsRerun < ActiveRecord::Migration[6.1]
include Gitlab::Database::MigrationHelpers
MIGRATION = 'BackfillDraftStatusOnMergeRequests'
DELAY_INTERVAL = 2.minutes
BATCH_SIZE = 50
disable_ddl_transaction!
def up
eligible_mrs = Gitlab::BackgroundMigration::BackfillDraftStatusOnMergeRequests::MergeRequest.eligible
queue_background_migration_jobs_by_range_at_intervals(
eligible_mrs,
MIGRATION,
DELAY_INTERVAL,
track_jobs: true,
batch_size: BATCH_SIZE
)
# noop
#
end
def down
......
1e4d0b062c8e43b1af37c6cf869f9c173248d7bf5451b4aa5468d48c1004b97c
\ No newline at end of file
......@@ -25743,8 +25743,6 @@ CREATE INDEX tmp_idx_on_namespaces_delayed_project_removal ON namespaces USING b
CREATE INDEX tmp_index_approval_project_rules_scanners ON approval_project_rules USING gin (scanners) WHERE (scanners @> '{cluster_image_scanning}'::text[]);
CREATE INDEX tmp_index_merge_requests_draft_and_status ON merge_requests USING btree (id) WHERE ((draft = false) AND (state_id = 1) AND ((title)::text ~* '^\[draft\]|\(draft\)|draft:|draft|\[WIP\]|WIP:|WIP'::text));
CREATE INDEX tmp_index_namespaces_empty_traversal_ids_with_child_namespaces ON namespaces USING btree (id) WHERE ((parent_id IS NOT NULL) AND (traversal_ids = '{}'::integer[]));
CREATE INDEX tmp_index_namespaces_empty_traversal_ids_with_root_namespaces ON namespaces USING btree (id) WHERE ((parent_id IS NULL) AND (traversal_ids = '{}'::integer[]));
# frozen_string_literal: true
require 'spec_helper'
require_migration!
RSpec.describe ScheduleBackfillDraftStatusOnMergeRequests, :sidekiq 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
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
stub_const("#{described_class}::BATCH_SIZE", 1)
end
it 'schedules BackfillDraftStatusOnMergeRequests background jobs' do
Sidekiq::Testing.fake! do
draft_mrs = Gitlab::BackgroundMigration::BackfillDraftStatusOnMergeRequests::MergeRequest.eligible
first_mr_id = draft_mrs.first.id
second_mr_id = draft_mrs.second.id
freeze_time do
migrate!
expect(BackgroundMigrationWorker.jobs.size).to eq(7)
expect(described_class::MIGRATION)
.to be_scheduled_delayed_migration(2.minutes, first_mr_id, first_mr_id)
expect(described_class::MIGRATION)
.to be_scheduled_delayed_migration(4.minutes, second_mr_id, second_mr_id)
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment