summaryrefslogtreecommitdiff
path: root/db/post_migrate/20220505044348_fix_automatic_iterations_cadences_start_date.rb
blob: 90d70da1a285a411d3403c991ae812edb9836c0c (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
27
28
# frozen_string_literal: true

class FixAutomaticIterationsCadencesStartDate < Gitlab::Database::Migration[2.0]
  restrict_gitlab_migration gitlab_schema: :gitlab_main

  def up
    execute(<<~SQL)
      UPDATE iterations_cadences
      SET start_date=COALESCE(
        (
          SELECT start_date
          FROM sprints
          WHERE iterations_cadences.id=sprints.iterations_cadence_id
          ORDER BY sprints.start_date ASC
          LIMIT 1
        ),
        start_date
      )
      WHERE iterations_cadences.automatic=true;
    SQL
  end

  def down
    # no-op
    # The migration updates the records for the feature used behind a non-default feature flag.
    # The correct data can be computed with the records from 'sprints' table.
  end
end