Skip to content

Update and migrate iteration state_enum for current

What does this MR do and why?

We want to implement a new sort option for iterations using state_enum #336611 (comment 710234013).

The underlying table for Iteration AR model is sprints.

Here are the current mapping of state_enum values:

# ee/app/models/ee/iteration.rb
    STATE_ENUM_MAP = {
      upcoming: 1,
      current: 2,
      closed: 3
    }.with_indifferent_access.freeze

The sort order we want to implement must have current come first before upcoming and closed.

To achieve the desired sort order, we are changing the enum value for current to be 0 and migrate the sprints DB records accordingly in this MR. (we will migrate closed to 2 in a follow up MR.)

Migration

migration up/down outputs:

rails db:migrate:up VERSION=20211207143334

== 20211207143334 UpdateStateEnumInSprintsWhereStateEnumIsTwo: migrating ======
-- execute("UPDATE sprints SET state_enum=0 WHERE state_enum=2;\n")
   -> 0.0048s
== 20211207143334 UpdateStateEnumInSprintsWhereStateEnumIsTwo: migrated (0.0049s) 

rails db:migrate:down VERSION=20211207143334

== 20211207143334 UpdateStateEnumInSprintsWhereStateEnumIsTwo: reverting ======
-- execute("UPDATE sprints SET state_enum=2 WHERE state_enum=0;\n")
   -> 0.0038s
== 20211207143334 UpdateStateEnumInSprintsWhereStateEnumIsTwo: reverted (0.0038s)

query plan for migration up:

                                                   QUERY PLAN                                                   
----------------------------------------------------------------------------------------------------------------
 Update on sprints  (cost=0.00..2722.04 rows=917 width=406) (actual time=1935.887..1935.888 rows=0 loops=1)
   Buffers: shared hit=22157 read=769 dirtied=1384 written=102
   I/O Timings: read=1765.278
   ->  Seq Scan on sprints  (cost=0.00..2722.04 rows=917 width=406) (actual time=0.030..6.412 rows=900 loops=1)
         Filter: (state_enum = 2)
         Rows Removed by Filter: 15261
         Buffers: shared hit=628 dirtied=80
 Planning Time: 1.353 ms
 Execution Time: 1935.961 ms
(9 rows)

query plan for migration down:

----------------------------------------------------------------------------------------------------------------
 Update on sprints  (cost=0.00..2956.10 rows=996 width=406) (actual time=102.320..102.322 rows=0 loops=1)
   Buffers: shared hit=25838 read=2 dirtied=145 written=138
   I/O Timings: read=1.568
   ->  Seq Scan on sprints  (cost=0.00..2956.10 rows=996 width=406) (actual time=0.032..5.296 rows=900 loops=1)
         Filter: (state_enum = 2)
         Rows Removed by Filter: 15261
         Buffers: shared hit=682
 Planning Time: 0.234 ms
 Execution Time: 102.406 ms
(9 rows)

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by euko

Merge request reports

Loading