Commit 42b43125 authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch 'revert-29a04635' into 'master'

Revert !62627 to fix a production incident

See merge request gitlab-org/gitlab!63574
parents 688db7c7 05b566ab
# frozen_string_literal: true
class BackfillDraftStatusOnMergeRequests < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
INDEX_NAME = "tmp_index_merge_requests_draft_and_status"
disable_ddl_transaction!
# include Gitlab::Database::MigrationHelpers
# Marking these as no-op as the original contents caused timeouts on
# staging. Removing the code here per
# #https://docs.gitlab.com/ee/development/deleting_migrations.html#how-to-disable-a-data-migration
# =>
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
update_column_in_batches(:merge_requests, :draft, true, batch_size: 100) do |table, query|
query
.where(table[:state_id].eq(1))
.where(table[:draft].eq(false))
.where(table[:title].matches_regexp('^\\[draft\\]|\\(draft\\)|draft:|draft|\\[WIP\\]|WIP:|WIP', false))
end
remove_concurrent_index_by_name :merge_requests, INDEX_NAME
# no-op
end
def down
remove_concurrent_index_by_name :merge_requests, INDEX_NAME
# no-op
end
end
# frozen_string_literal: true
require 'spec_helper'
require Rails.root.join('db', 'post_migrate', '20210526222715_backfill_draft_status_on_merge_requests.rb')
RSpec.describe BackfillDraftStatusOnMergeRequests, :migration 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|
merge_request = create_merge_request(title: "#{prefix} This is a title", state_id: n)
merge_request.update_columns(draft: false)
end
end
end
it "updates all open draft merge request's draft field to true" do
mr_count = merge_requests.all.count
expect { disable_migrations_output { migrate! } }
.to change { MergeRequest.where(draft: false).count }
.from(mr_count).to(mr_count - draft_prefixes.length)
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