summaryrefslogtreecommitdiff
path: root/db/post_migrate/20220307192610_remove_duplicate_project_tag_releases.rb
blob: d8b9938082524b2662de05f16e5994c60cbe39e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# frozen_string_literal: true

class RemoveDuplicateProjectTagReleases < Gitlab::Database::Migration[1.0]
  disable_ddl_transaction!

  class Release < ActiveRecord::Base
    include EachBatch

    self.table_name = 'releases'
  end

  def up
    Release.each_batch(of: 5000) do |relation|
      relation
        .where('exists (select 1 from releases r2 where r2.project_id = releases.project_id and r2.tag = releases.tag and r2.id > releases.id)')
        .delete_all
    end
  end

  def down
    # no-op
    #
    # releases with the same tag within a project have been removed
    # and therefore the duplicate release data is no longer available
  end
end