Skip to content

Create work_item_types table

What does this MR do?

There is an issue_type column in the Issues table. As we need to support customer defined issue types, we're extracting that column into its own table, work_item_types. It also adds a :work_item_type_id column to the issues table. Each issue will then be assigned to the proper type. Properly migrating old types to new types will happen in upcoming MRs. This is just the first step.

This is the first step of the plan being laid out in !66519 (merged) (thanks @acroitor)

As of right now, we're eventually aiming for a structure like this:

Diagram source
```plantuml
hide circle
hide empty members

entity issues {
  used for WorkItem/Issue model
  ---
  + id
  + project_id
  + work_item_type_id
  -- normal attributes --
  + milestone_id
  - assignees
  + ...
}

entity work_item_types {
  + id
  + namespace_id
  + title
  + description
  + base_type
  - work_items
  - widget_defs
}

entity widget_defs {
  widget_data would be nil for our standard
  widget types
  ---
  + id
  + name
  + disabled
  + row_order
  + widget_type
}

entity widget_type_enum {
  * assignees
  * milestone
  * labels
  * status
  * other "first class" attributes
}

entity base_type_enum {
  * issue
  * test_case
  * requirement
  * incident
}

issues::work_item_type_id <-- work_item_types::work_items
work_item_types::base_type -[dashed]- base_type_enum
work_item_types::widget_defs --> widget_defs
widget_defs::widget_type -[dashed]- widget_type_enum
```

DB

> rake db:migrate
== 20210709221051 CreateWorkItemTypes: migrating ==============================
-- create_table(:work_item_types, {})
-- quote_column_name(:name)
   -> 0.0000s
-- quote_column_name(:icon_name)
   -> 0.0000s
   -> 0.0093s
-- quote_table_name("check_104d2410f6")
   -> 0.0000s
-- quote_table_name("check_fecb3a98d1")
   -> 0.0000s
-- quote_table_name(:work_item_types)
   -> 0.0000s
-- execute("ALTER TABLE \"work_item_types\"\nADD CONSTRAINT \"check_104d2410f6\" CHECK (char_length(\"name\") <= 255),\nADD CONSTRAINT \"check_fecb3a98d1\" CHECK (char_length(\"icon_name\") <= 255)\n")
   -> 0.0010s
-- transaction_open?()
   -> 0.0000s
-- index_exists?(:work_item_types, "namespace_id, TRIM(BOTH FROM LOWER(name))", {:unique=>true, :name=>:work_item_types_namespace_id_and_name_unique, :algorithm=>:concurrently})
   -> 0.0019s
-- execute("SET statement_timeout TO 0")
   -> 0.0005s
-- add_index(:work_item_types, "namespace_id, TRIM(BOTH FROM LOWER(name))", {:unique=>true, :name=>:work_item_types_namespace_id_and_name_unique, :algorithm=>:concurrently})
   -> 0.0026s
-- execute("RESET ALL")
   -> 0.0005s
== 20210709221051 CreateWorkItemTypes: migrated (0.0232s) =====================

== 20210709221659 AddWorkItemTypeIdToIssue: migrating =========================
-- column_exists?(:issues, :work_item_type_id)
   -> 0.0037s
-- add_column(:issues, :work_item_type_id, :bigint)
   -> 0.0009s
-- transaction_open?()
   -> 0.0000s
-- index_exists?(:issues, :work_item_type_id, {:algorithm=>:concurrently})
   -> 0.0071s
-- add_index(:issues, :work_item_type_id, {:algorithm=>:concurrently})
   -> 0.0049s
-- transaction_open?()
   -> 0.0000s
-- foreign_keys(:issues)
   -> 0.0032s
-- execute("ALTER TABLE issues\nADD CONSTRAINT fk_b37be69be6\nFOREIGN KEY (work_item_type_id)\nREFERENCES work_item_types (id)\n\nNOT VALID;\n")
   -> 0.0014s
-- execute("ALTER TABLE issues VALIDATE CONSTRAINT fk_b37be69be6;")
   -> 0.0081s
== 20210709221659 AddWorkItemTypeIdToIssue: migrated (0.0371s) ================
> rake db:migrate:down VERSION=20210709221659
== 20210709221659 AddWorkItemTypeIdToIssue: reverting =========================
-- remove_column(:issues, :work_item_type_id)
   -> 0.0023s
== 20210709221659 AddWorkItemTypeIdToIssue: reverted (0.0125s) ================


> rake db:migrate:down VERSION=20210709221051
== 20210709221051 CreateWorkItemTypes: reverting ==============================
-- drop_table(:work_item_types)
   -> 0.0026s
== 20210709221051 CreateWorkItemTypes: reverted (0.0083s) =====================

Screenshots (strongly suggested)

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team

Related to #335722 (closed) and #337998 (closed)

Edited by Brett Walker

Merge request reports