Skip to content

Introduce tables and models for custom status and lifecycle

What does this MR do and why?

This MR introduces the database foundation for configurable work item statuses, allowing users to create custom statuses and lifecycles for their work items. This is part of the configurable work item statuses initiative, which will enable teams to customize the statuses beyond the default, system-defined options that live under WorkItems::Statuses::SystemDefined.

Database Changes

This MR adds four new tables with their corresponding models and associations:

  • work_item_custom_statuses - Stores namespace-level custom status definitions with name, color, and category
  • work_item_custom_lifecycles - Stores namespace-level custom lifecycle configurations with default statuses
  • work_item_custom_lifecycle_statuses - Join table that associates statuses with lifecycles and tracks position
  • work_item_type_custom_lifecycles - Join table that associates work item types with custom lifecycles within a namespace

Model Relationships

  • WorkItems::Statuses::Custom::Status - Belongs to a namespace, has many lifecycles through the join table
  • WorkItems::Statuses::Custom::Lifecycle - Belongs to a namespace, has default statuses (open, closed, duplicate), and has many statuses through the join table
  • WorkItems::Statuses::Custom::LifecycleStatus - Join model that connects lifecycles and statuses with position information
  • WorkItems::TypeCustomLifecycle - Join model that connects work item types with custom lifecycles

Callbacks

WorkItems::Statuses::Custom::LifecycleStatus and WorkItems::TypeCustomLifecycle models implement callbacks that automatically copy the namespace, simplifying record creation.

Upcoming changes

To keep this MR focused and minimize the number of migrations per MR, the following changes will be addressed separately:

References

Here's the overview of the classes from the Work Items Custom Status Design Doc. Please note, that the diagram requires a slight refresh after this MR is released.

Note: As discussed here, the custom_status_enabled column on the namespaces table is no longer required.

models.svg

Screenshots or screen recordings

backend changes only.

How to set up and validate locally

Click to expand
  1. Enable the work_item_status_feature_flag feature flag

  2. Find a namespace

project = Project.find(7) # flightjs/Flight
namespace = project.root_ancestor
  1. Create custom statuses for a given namespace
open_status = WorkItems::Statuses::Custom::Status.create!(
  namespace: namespace,
  name: "To do",
  color: "#737278",
  category: :to_do
)

closed_status = WorkItems::Statuses::Custom::Status.create!(
  namespace: namespace,
  name: "Done",
  color: "#108548",
  category: :done
)

duplicate_status = WorkItems::Statuses::Custom::Status.create!(
  namespace: namespace,
  name: "Duplicate",
  color: "#DD2B0E",
  category: :cancelled
)
  1. Create a custom lifecycle with default statuses
lifecycle = WorkItems::Statuses::Custom::Lifecycle.create!(
  namespace: namespace,
  name: "Engineering",
  default_open_status: open_status,
  default_closed_status: closed_status,
  default_duplicate_status: duplicate_status
)
  1. Associate custom statuses with the lifecycle (namespace is automatically populated)
lifecycle_status_1 = WorkItems::Statuses::Custom::LifecycleStatus.create!(
  lifecycle: lifecycle,
  status: open_status,
  position: 1
)

lifecycle_status_1 = WorkItems::Statuses::Custom::LifecycleStatus.create!(
  lifecycle: lifecycle,
  status: closed_status,
  position: 2
)

lifecycle_status_3 = WorkItems::Statuses::Custom::LifecycleStatus.create!(
  lifecycle: lifecycle,
  status: duplicate_status,
  position: 3
)
  1. Associate work item types with the lifecycle (namespace is automatically populated)
task_type = WorkItems::Type.find_by(base_type: :task)

type_custom_lifecycle = WorkItems::TypeCustomLifecycle.create!(
  work_item_type: task_type,
  lifecycle: lifecycle
)
  1. Verify the data
WorkItems::Statuses::Custom::Status.all
WorkItems::Statuses::Custom::Lifecycle.all
WorkItems::Statuses::Custom::Lifecycle.last.default_open_status
WorkItems::Statuses::Custom::Lifecycle.last.default_closed_status
WorkItems::Statuses::Custom::Lifecycle.last.default_duplicate_status
WorkItems::Statuses::Custom::LifecycleStatus.all
WorkItems::TypeCustomLifecycle.all
  1. Trigger validation errors by attempting to create a custom status or lifecycle with the same name under the same namespace.

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Agnes Slota

Merge request reports

Loading