Skip to content
Snippets Groups Projects

Add MergeRequestReviewer for dedicated Reviewers section

Merged Sincheol (David) Kim requested to merge add-reviewers-to-merge-requests into master
1 unresolved thread

What does this MR do?

Related to #216054 (closed)

This is the first step towards adding dedicated reviewer section to MergeRequests. It'll be available for EE and I'll add a feature flag in controller level so I don't think we need documentation update at this stage.

FYI, this is the next WIP MR that uses this model. !40378 (closed)

Screenshots

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team
Edited by Sincheol (David) Kim

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • 1 # frozen_string_literal: true
    2
    3 class CreateMergeRequestReviewers < ActiveRecord::Migration[6.0]
    4 include Gitlab::Database::MigrationHelpers
    5
    6 DOWNTIME = false
    7
    8 def change
    9 create_table :merge_request_reviewers do |t|
    10 t.references :user, foreign_key: { on_delete: :cascade }, index: true, null: false
    11 t.references :merge_request, foreign_key: { on_delete: :cascade }, index: true, null: false
    • Can you please check our guidelines for adding a new table with two foreign keys: https://docs.gitlab.com/ee/development/migration_style_guide.html#examples

      For creating a new table when we have two foreign keys:

      It is suggested to have three migrations:

      • Creating the table without foreign keys (with the indices).
      • Add a foreign key to the first table.
      • Add a foreign key to the second table.

      Also, create_table is suggested to be used with with_lock_retries, and with_lock_retries method cannot be used within the change method, you must manually define the up and down methods to make the migration reversible. https://docs.gitlab.com/ee/development/migration_style_guide.html#when-to-use-the-helper-method

    • With 2 foreign keys to be created in the same transaction, we first acquire a lock on the first target table. After creating the FK, we hold on to that lock and try to acquire the lock on the second table.

      So with 2 FKs in the same transaction, we risk locking the first target table for an extended period of time.

      Edited by Nikola Milojevic
    • Thanks a lot for your suggestions @nmilojevic1.

      I missed the database guideline!

      rubocop was complaining that we should use add_concurrent_foreign_key instead, but I felt using with_lock_entries seems more relevant so I disabled the cop. Please let me know if I missed anything.

      Also, I don't think with_lock_entries is required for creating a new table? Is there any reasoning behind that? I couldn't find anything on the doc about that either. :thinking:

    • rubocop was complaining that we should use add_concurrent_foreign_key instead

      There is no need to use add_concurrent_foreign_key on a new table with no data.

      Rubocop is complaining because it can not figure out that this is a new table (it was created in another migration/file), so it defaults to complaining even if there are some false positives like this case.

      I think it's ok to disable the cop.

      Also, I don't think with_lock_entries is required for creating a new table?

      Yes, now, with separated migrations for adding new foreign keys, there is no need for with_lock_entries.

      Well, this part is maybe a little confusing in the documentation.

      Creating a new table with a single foreign key, it is ok to add a reference column when creating a table in the single transaction, but we should simply wrap the create_table method with_lock_retries because it will also lock the targeted table which is not empty.

      When we add several foreign keys, we risk locking the table for a long time and hat's probably the main reason why we suggest splitting this up if there are multiple foreign keys involved.

      with_lock_retries guards only against too long lock acquires, but it doesn't guard you when you are already holding other locks in the transaction.

      This way, when we have separate migration for each foreign_key wrapped in a with_lock_retries, it guarantees that we provide each DDL operation the best possible conditions to succeed without competing for time.

      Please check @iroussos's very good and detailed explanation here for more details.

    • Thanks, @dskim_gitlab. database LGTM :rocket:

      @tigerwnz can you please do the maintainer review for database?

    • LGTM thanks @dskim_gitlab!

    • Thanks a lot for your detailed explanation and a link :bow:

      It makes a lot of sense and I agree it'd be great if we can update the doc to clarify the reasoning as well. :thumbsup:

    • Thanks a lot for your review as well @tigerwnz :bow:

    • Please register or sign in to reply
  • Nikola Milojevic assigned to @ayufan and unassigned @nmilojevic1

    assigned to @ayufan and unassigned @nmilojevic1

  • added 1 commit

    • 5c2028bd - Split migration into three and replace validation with unique index

    Compare with previous version

  • Sincheol (David) Kim changed the description

    changed the description

  • Kamil Trzciński
  • Kamil Trzciński approved this merge request

    approved this merge request

  • added 739 commits

    Compare with previous version

  • Tiger Watson approved this merge request

    approved this merge request

  • added databaseapproved label and removed databasereviewed label

  • Tiger Watson resolved all threads

    resolved all threads

  • Tiger Watson enabled an automatic merge when the pipeline for 0aa521a9 succeeds

    enabled an automatic merge when the pipeline for 0aa521a9 succeeds

  • merged

  • Tiger Watson mentioned in commit c09f0508

    mentioned in commit c09f0508

  • added workflowcanary label and removed workflowstaging label

  • added workflowproduction label and removed workflowcanary label

  • This merge request has been deployed to the pre.gitlab.com environment, and will be included in the upcoming self-managed GitLab 13.5.0 release.


    :robot: This comment is generated automatically using the Release Tools project.

  • This merge request has been deployed to the release.gitlab.net environment, and will be included in the upcoming self-managed GitLab 13.5.0 release.


    :robot: This comment is generated automatically using the Release Tools project.

  • Please register or sign in to reply
    Loading