Draft: Stop using issue_type enum generated methods in issues
What does this MR do and why?
Using an enum in the Issue model generates
several methods for each enum type. We are
preventing the usage of those since they
use the issue_type
column underneath. Replacing used forbidden scopes with .with_issue_type
DB review
Database plans
I have placed the DB plan links next to each changed line in this MR so it's easier to understand what part of the app the change affects. Comments starting with !120520 (comment 1393013440)
I'm not splitting this MR into multiple smaller ones since I think it would be best to see all the places that will be affected by this change so we can create a single index for all. While working on this change I had to change the index multiple times before I ended up with the proposed change.
Index creation
Index needs to be created async over the weekend. I'll do that in a separate MR once it's validated here that the index in this MR is the correct one to add.
Migration output
UP
bin/rails db:migrate
main: == [advisory_lock_connection] object_id: 275740, pg_backend_pid: 70813
main: == 20230516192543 AddIssuesWorkItemTypeIdProjectIdIndex: migrating ============
main: -- transaction_open?()
main: -> 0.0000s
main: -- view_exists?(:postgres_partitions)
main: -> 0.2462s
main: -- index_exists?(:issues, [:work_item_type_id, :project_id, :created_at, :state_id], {:name=>"index_issues_on_work_item_type_id_project_id_created_at_state", :algorithm=>:concurrently})
main: -> 0.0314s
main: -- execute("SET statement_timeout TO 0")
main: -> 0.0004s
main: -- add_index(:issues, [:work_item_type_id, :project_id, :created_at, :state_id], {:name=>"index_issues_on_work_item_type_id_project_id_created_at_state", :algorithm=>:concurrently})
main: -> 0.0124s
main: -- execute("RESET statement_timeout")
main: -> 0.0004s
main: == 20230516192543 AddIssuesWorkItemTypeIdProjectIdIndex: migrated (0.3179s) ===
main: == [advisory_lock_connection] object_id: 275740, pg_backend_pid: 70813
ci: == [advisory_lock_connection] object_id: 276040, pg_backend_pid: 70815
ci: == 20230516192543 AddIssuesWorkItemTypeIdProjectIdIndex: migrating ============
ci: -- transaction_open?()
ci: -> 0.0000s
ci: -- view_exists?(:postgres_partitions)
ci: -> 0.0009s
ci: -- index_exists?(:issues, [:work_item_type_id, :project_id, :created_at, :state_id], {:name=>"index_issues_on_work_item_type_id_project_id_created_at_state", :algorithm=>:concurrently})
ci: -> 0.0483s
ci: -- execute("SET statement_timeout TO 0")
ci: -> 0.0006s
ci: -- add_index(:issues, [:work_item_type_id, :project_id, :created_at, :state_id], {:name=>"index_issues_on_work_item_type_id_project_id_created_at_state", :algorithm=>:concurrently})
ci: -> 0.0128s
ci: -- execute("RESET statement_timeout")
ci: -> 0.0007s
ci: == 20230516192543 AddIssuesWorkItemTypeIdProjectIdIndex: migrated (0.0947s) ===
ci: == [advisory_lock_connection] object_id: 276040, pg_backend_pid: 70815
DOWN
bin/rails db:rollback:main db:rollback:ci
main: == [advisory_lock_connection] object_id: 275540, pg_backend_pid: 73710
main: == 20230516192543 AddIssuesWorkItemTypeIdProjectIdIndex: reverting ============
main: -- transaction_open?()
main: -> 0.0000s
main: -- view_exists?(:postgres_partitions)
main: -> 0.2921s
main: -- indexes(:issues)
main: -> 0.0293s
main: -- execute("SET statement_timeout TO 0")
main: -> 0.0004s
main: -- remove_index(:issues, {:algorithm=>:concurrently, :name=>"index_issues_on_work_item_type_id_project_id_created_at_state"})
main: -> 0.0039s
main: -- execute("RESET statement_timeout")
main: -> 0.0006s
main: == 20230516192543 AddIssuesWorkItemTypeIdProjectIdIndex: reverted (0.3528s) ===
main: == [advisory_lock_connection] object_id: 275540, pg_backend_pid: 73710
ci: == [advisory_lock_connection] object_id: 311780, pg_backend_pid: 73962
ci: == 20230516192543 AddIssuesWorkItemTypeIdProjectIdIndex: reverting ============
ci: -- transaction_open?()
ci: -> 0.0000s
ci: -- view_exists?(:postgres_partitions)
ci: -> 0.0018s
ci: -- indexes(:issues)
ci: -> 0.0649s
ci: -- execute("SET statement_timeout TO 0")
ci: -> 0.0008s
ci: -- remove_index(:issues, {:algorithm=>:concurrently, :name=>"index_issues_on_work_item_type_id_project_id_created_at_state"})
ci: -> 0.0058s
ci: -- execute("RESET statement_timeout")
ci: -> 0.0011s
ci: == 20230516192543 AddIssuesWorkItemTypeIdProjectIdIndex: reverted (0.1252s) ===
ci: == [advisory_lock_connection] object_id: 311780, pg_backend_pid: 73962
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Related to #410225 (closed)