[go: up one dir, main page]

Skip to content

Reorganize auto merge related information into the dedicated table - `auto_merges`

Problem

Today, auto_merge_strategy (The strategy to merge a merge request automatically e.g. MWPS, etc) is persisted in merge_requests.merge_params column. This is a text type column in database and it's casted as Hash in rails.

We also use merge_requests.merge_user for the user who triggered the auto merge and merge_requests.merge_when_pipeline_succeeds (The internal alias is auto_merge_enabled) for the flag if the merge request is to be marked to be auto merged.

The problem is that when we search merge requests with a specific auto merge strategy, it requires to filter with merge_params column (e.g. (merge_params SIMILAR TO '%(auto\_merge\_strategy: merge\_when\_pipeline\_succeeds)%')). This is not performant process if the query processes the regexp search to many rows. Thus, we'd need something better architecture.

Proposal

I'd propose to have the following architecture at the second iteration.

Introduce a new table to manage all auto merged merge requests

  create_table "auto_merges", force: :cascade do |t|
    t.integer "merge_request_id", null: false
    t.integer "user_id", null: false
    t.integer "strategy", null: false, limit: 2
    t.integer "pipeline_id"
    t.datetime_with_timezone "created_at", null: false
    t.datetime_with_timezone "updated_at", null: false
    t.integer "target_project_id", null: false
    t.text "target_branch", null: false
    t.index ["merge_request_id"], name: "index_merge_trains_on_merge_request_id", unique: true
    t.index ["pipeline_id"], name: "index_merge_trains_on_pipeline_id"
    t.index ["target_project_id"], name: "index_merge_trains_on_target_project_id"
    t.index ["user_id"], name: "index_merge_trains_on_user_id"
  end

This is basically the same table architecture with merge_trains today. We can reuse/extend the existing architecture for more general purpose.

class AutoMerge < ApplicationRecord
  belongs_to :target_project, class_name: "Project"
  belongs_to :merge_request
  belongs_to :user

  enum strategy: {
    merge_when_pipeline_succeeds: 0,
    merge_train: 1
    add_to_merge_train_when_pipeline_succeeds: 2
  }

  ## ...
end

With that, we can

  • Migrate all merge_requests.merge_params and merge_requests.merge_user to the auto_merges table.
  • Migrate all merge_trains rows to the auto_merges table.
  • Deprecate/Remove column merge_requests.merge_when_pipeline_succeeds (boolean)
  • Deprecate/Remove column merge_requests.merge_user
  • Deprecate/Remove table merge_trains
Edited by Shinya Maeda