summaryrefslogtreecommitdiff
path: root/db/post_migrate/20220505044348_fix_automatic_iterations_cadences_start_date.rb
diff options
context:
space:
mode:
Diffstat (limited to 'db/post_migrate/20220505044348_fix_automatic_iterations_cadences_start_date.rb')
-rw-r--r--db/post_migrate/20220505044348_fix_automatic_iterations_cadences_start_date.rb28
1 files changed, 28 insertions, 0 deletions
diff --git a/db/post_migrate/20220505044348_fix_automatic_iterations_cadences_start_date.rb b/db/post_migrate/20220505044348_fix_automatic_iterations_cadences_start_date.rb
new file mode 100644
index 00000000000..90d70da1a28
--- /dev/null
+++ b/db/post_migrate/20220505044348_fix_automatic_iterations_cadences_start_date.rb
@@ -0,0 +1,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