incident_components keeps an index that the July composite unique now covers

Open Beginner friendly
#465 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
84/100
Issue type
Refactor
Clarity
Clearly specified
Activity status
Active
Tech stack
laravel, php
Domain
database

Research direction

Start by reading 2017_07_18_214718_CreateIncidentComponents.php and 2026_07_25_000002_add_constraints_to_component_pivots.php, then run the schema checks with Laravel Truss's truss:doctor. Determine the migration path for existing installs and the fresh-install schema change. Done means incident_components no longer has the redundant single-column index while the composite unique remains intact.

Written by the indexing model from the issue text.

Description

incident_components has a single column index on incident_id, from 2017_07_18_214718_CreateIncidentComponents.php:

$table->integer('incident_id')->unsigned()->index();

Since 2026_07_25_000002_add_constraints_to_component_pivots.php added the unique on (incident_id, component_id), that older index is a left prefix of the unique. MySQL and PostgreSQL can both answer a query filtering on incident_id alone from the composite, so the single column index no longer adds a read path. It is still maintained on every insert and update to the pivot, and still takes space.

Nothing here was written wrong. The composite arrived nine years after the single index, which is the ordinary way this happens.

schedule_components is not affected. It was constrained in the same migration, but its 2016 migration adds no single column indexes, so there is nothing to remove there.

The fix is to drop the index. An existing install needs a follow up migration; for new installs it is removing ->index() from the 2017 migration, though you may prefer not to edit a historical one.

Found with Laravel Truss, a structure only schema linter, running truss:doctor against a Cachet install. Checked against main today.

Dominant language
PHP
Stars
228
Forks
84
Avg merge
11h 19m
Merged PRs (30d)
22

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from cachethq/core

All issues in cachethq/core

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.