Skip to content

fix(migration): tags name widening was on wrong table - #236

Open
DocArmoryTech wants to merge 4 commits into
cerebrate-project:mainfrom
DocArmoryTech:fix/ginormous-tags-tab
Open

fix(migration): tags name widening was on wrong table#236
DocArmoryTech wants to merge 4 commits into
cerebrate-project:mainfrom
DocArmoryTech:fix/ginormous-tags-tab

Conversation

@DocArmoryTech

Copy link
Copy Markdown
Contributor

20250829000000_GinormousTags - "extend name field to 255 length, matching MISP" - never widened the column it was aiming at (I think), and created an empty table as a side effect.

Why

It operates on a table called tags:

$this->table('tags')->removeIndex('name')->save();
$this->table('tags')->changeColumn('name', 'string', ['limit' => 255])->update();
$this->table('tags')->addIndex('name', ['limit' => 191])->save();

The Tags plugin's table is tags_tagsTagsTable::initialize() calls
setTable('tags_tags'), and
plugins/Tags/config/Migrations/20210831121348_TagSystem.php creates it. No
migration anywhere creates a bare tags table, so Phinx's ->save() created
one.

Changes

A new/repeat migration, since the original has already run everywhere and will not run again. It widens tags_tags.name to 255 and drops the stray tags table, guarded on it being empty.

A second bug in the original, worth flagging

The index on tags_tags.name is UNIQUETagSystem creates it with
['unique' => true], and getExistingTag() plus every "create the tag if it
does not exist" path depends on it.

The original migration re-adds the index without unique; harmless because it was on an empty table nothing reads. Fixing by correcting the table name could silently drop the uniqueness constraint on the live table.

iglocska and others added 4 commits June 11, 2026 09:45
20250829000000_GinormousTags ("extend name field to 255 length, matching
MISP") operates on a table called `tags`:

    $this->table('tags')->removeIndex('name')->save();
    $this->table('tags')->changeColumn('name', 'string', ['limit' => 255])->update();
    $this->table('tags')->addIndex('name', ['limit' => 191])->save();

The Tags plugin's table is `tags_tags` -- TagsTable::initialize() calls
setTable('tags_tags'), and plugins/Tags/config/Migrations/20210831121348_TagSystem.php
creates it. No migration anywhere creates a bare `tags` table.

So the widening never happened, and an empty `tags` table was created as a
side effect, Phinx's ->save() creating a table that does not exist.
Confirmed on an instance at main:

    +------------+-------------+--------------------------+
    | table_name | column_name | character_maximum_length |
    +------------+-------------+--------------------------+
    | tags       | name        |                      255 |
    | tags_tags  | name        |                      191 |
    +------------+-------------+--------------------------+

Adds a new migration rather than correcting the original, which has already
run everywhere and will not run again. It widens tags_tags.name and drops
the stray table, guarded on it being empty.

The index on tags_tags.name is UNIQUE, created that way by TagSystem, and
getExistingTag() together with every "create tag if absent" path depends on
it. The original re-added the index without `unique`, harmless only because
it was acting on an empty table nothing reads -- applying it verbatim to
tags_tags would silently have dropped the constraint. Preserved here.

The 191-byte prefix is kept, as intended originally: utf8mb4 at 255
characters is 1020 bytes, past the 767-byte index limit on older InnoDB row
formats. Uniqueness is therefore enforced on the first 191 characters.

down() narrows back only when no name exceeds 191 characters, so a rollback
cannot truncate tag names.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants