Skip to content

Resolve "Duplicate rows with the same tag name in Release"

What does this MR do and why?

Removes any existing releases with duplicate tags in a project, keeping the latest release (i.e. released_at)

Screenshots or screen recordings

The query takes about 3 seconds, which is within the tolerance for post-release migrations

!77035 (comment 806068737)

https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/7831/commands/27959

Unfortunately I see no way to undo this migration once it is applied.

User Impact

Since creation of these duplicate releases are blocked at the service level there aren't many of these releases. Only the most recent of the duplicate releases would be available after this migration.

Also according to @shinya.maeda in the comments below However, since invalid rows are very rare (we do NOT allow users to create such records in the service class) and they can't be operated correctly (e.g. it's fetched randomly), it's highly unlikely that users face issues.

Currently in production there seem to be 591 of these releases that would be removed

###Migration Output

== 20211217192453 RemoveDuplicateProjectTagReleases: migrating ================
== 20211217192453 RemoveDuplicateProjectTagReleases: migrated (0.0023s) =======

How to set up and validate locally

To test the migration

  1. Open rails console
  2. Note how many releases there are with Release.count
  3. Create some old duplicate releases with Release.last.dup.update_attribute(:released_at, 5.years.ago)
  4. Note how many new releases there are
  5. Run the migration
  6. Release count should be back to original number (or lower if you had existing duplicates)

To test the validation

  1. Open rails console
  2. Try to save a duplicate Release.last.dup.save!
  3. See that it fails

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 #31869 (closed)

Edited by Allen Cook

Merge request reports