Skip to content

Cleanup draft column data

Kerri Miller requested to merge 337861-cleanup-draft-data-from-faulty-regex into master

What does this MR do and why?

In a prior, now reverted migration (!67687 (comment 649843625)), we attempted to populate the draft column based on the "draft" or "WIP" nature of the title, mirroring what is used in MergeRequest#draft?. However, an error in the SQL regexp caused us to grab an additional number of MRs and label them as "draft".

This MR introduces a migration that finds all MRs that

  1. are draft: true
  2. match the original "leaky" regexp
  3. do NOT match the new, "corrected" regexp

This should give us the set of MRs that were incorrectly modified. We then update them to draft: false

Database

Up

== 20210920163825 CleanupDraftDataFromFaultyRegex: migrating ==================
-- transaction_open?()
   -> 0.0000s
-- index_exists?(:merge_requests, :id, {:where=>"draft = true AND state_id = 1 AND ((title)::text ~* '^\\[draft\\]|\\(draft\\)|draft:|draft|\\[WIP\\]|WIP:|WIP'::text) AND ((title)::text !~* '^(\\[draft\\]|\\(draft\\)|draft:|draft|\\[WIP\\]|WIP:|WIP)'::text)", :name=>"tmp_index_merge_requests_draft_and_status_leaky_regex", :algorithm=>:concurrently})
   -> 0.0282s
-- execute("SET statement_timeout TO 0")
   -> 0.0006s
-- add_index(:merge_requests, :id, {:where=>"draft = true AND state_id = 1 AND ((title)::text ~* '^\\[draft\\]|\\(draft\\)|draft:|draft|\\[WIP\\]|WIP:|WIP'::text) AND ((title)::text !~* '^(\\[draft\\]|\\(draft\\)|draft:|draft|\\[WIP\\]|WIP:|WIP)'::text)", :name=>"tmp_index_merge_requests_draft_and_status_leaky_regex", :algorithm=>:concurrently})
   -> 0.0083s
-- execute("RESET statement_timeout")
   -> 0.0008s
== 20210920163825 CleanupDraftDataFromFaultyRegex: migrated (0.0838s) =========

Down

== 20210920163825 CleanupDraftDataFromFaultyRegex: reverting ==================
-- transaction_open?()
   -> 0.0000s
-- indexes(:merge_requests)
   -> 0.0196s
-- execute("SET statement_timeout TO 0")
   -> 0.0015s
-- remove_index(:merge_requests, {:algorithm=>:concurrently, :name=>"tmp_index_merge_requests_draft_and_status_leaky_regex"})
   -> 0.0065s
-- execute("RESET statement_timeout")
   -> 0.0015s
== 20210920163825 CleanupDraftDataFromFaultyRegex: reverted (0.0319s) =========

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #337861 (closed) and #356220 (closed)

Edited by Kerri Miller

Merge request reports

Loading