Skip to content

fix(migrations): fit indexed columns to the MyISAM key limit - #30

Open
elcreator wants to merge 2 commits into
Seiger:2.xfrom
elcreator:fix-myisam-index-lengths
Open

elcreator wants to merge 2 commits into
Seiger:2.xfrom
elcreator:fix-myisam-index-lengths

Conversation

@elcreator

@elcreator elcreator commented Dec 5, 2026 •

Copy link
Copy Markdown

Installing sTask on a MyISAM site stops with:

SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes
(SQL: alter table `evo_s_workers` add unique `s_workers_identifier_unique`(`identifier`))

MyISAM is a supported Evolution CMS engine: the installers write it into the connection config for older servers, and sites keep it, often with a utf8 (utf8mb3) connection. It allows 1000 bytes per index key. The indexed string() columns are VARCHAR(255), which takes 1020 bytes in utf8mb4. s_tasks (identifier, action) is over the limit even in utf8mb3 (1530 bytes).

Since #27-#29 each create is guarded by hasTable(). So the failed create leaves its table behind without keys, and the next migrate skips it and records it as done: workers and tasks are then stored with no unique key and no indexes.

Found with the MyISAM CI legs added in evolution-cms/evolution#2675 / evolution-cms/evolution#2676. On 3.6 the bundled sTask v2.3.2 makes both legs fail: a 3.6 install on MyISAM, and the upgrade of a MyISAM 3.5 site.

Changes

  • Create migrations: the indexed strings are sized so every key fits 1000 bytes in utf8mb4.
    • identifier: 128 (workers, tasks, supervisor states)
    • scope: 128
    • action: 96 (identifier + action = 896 bytes)
    • priority: 16
    • Unindexed strings (class, supervisor_key) stay 255.
  • 2026_12_06_000000_fit_indexed_columns_to_myisam (MySQL / MariaDB only, idempotent). For each table missing any of the create migrations' indexes:
    • shortens the indexed columns to the new lengths, only where no stored value is longer, keeping each column's own collation;
    • adds the missing indexes;
    • skips, with a log warning, an index over a column whose values are too long, and a unique key whose rows share a value.
    • Tables with all their keys are left alone, so the 255-character columns of existing InnoDB sites do not change.
  • Models: FitsIndexedColumns (with INDEXED_LENGTHS on sWorker, sTaskModel, sSupervisorState) refuses to save a longer value; a non-strict MySQL session would cut it silently, and the worker or task would no longer be found. sTaskController::create() validates the same limits.
    • Only values being written are checked: a row stored before the limit can still be updated (status, progress), but a new identifier over 128 characters, or a new action over 96, is now refused everywhere, also on sites whose columns are still 255.
  • Tests:
    • tests/myisam.php, documented in tests/README.md. tests/run.php starts it in its own process, because heartbeat.php declares a stub sWorker.
    • tests/bootstrap.php now maps every class of the checkout. Before, it mapped only classes the site's authoritative class map already knew, so a new class such as the trait could not load.

Tests

  • tests/myisam.php, always:
    • the create migrations use the models' lengths;
    • every key fits 1000 bytes in utf8mb4;
    • the models refuse an over-long identifier, action, priority or supervisor identifier, and an over-long row stored earlier can still be updated (SQLite).
  • tests/myisam.php, with STASK_TEST_MYSQL:
    • fresh installs on MyISAM utf8mb4, MyISAM utf8mb3 and InnoDB create every index;
    • a table set left without keys by a failed 2.3.2 create gets them back, rows kept, and shortened columns keep their own collation (fails without the fix);
    • duplicates and over-long values keep their rows and block only their own keys;
    • a table with all its keys is left as it is.
    • Passes on MySQL 8.0.46, 9.7.4 and MariaDB 10.11, with the Evolution 3.5 and 3.6 vendors.
  • Every other tests/*.php: the same result as on 2.x.
    • metrics_memory.php and navigation-aside.php fail in my environment on 2.x too.
    • tests/run.php already fails on 2.x on two composer.json assertions: it expects ^3.5.7 and ^1.3, while the file requires ^3.5 and *. Not touched here.
  • End to end with Evolution 3.6.x + fix(migrations): keep the file_groups charset when making paths case-sensitive (3.6) evolution-cms/evolution#2676, against MySQL 9.7, with this branch in place of the vendor copy:
    • the MyISAM install gets through the installer, and every MySQL check passes (keys, collation, every table MyISAM);
    • 3.5.7 turned MyISAM / utf8mb3 and upgraded to 3.6 passes all checks.
    • Without this branch, both stop with the 1071 above.

🤖 Generated with Claude Code

MyISAM allows 1000 bytes per index key. The indexed VARCHAR(255) columns
need 1020 in utf8mb4, and s_tasks (identifier, action) is over the limit even
in utf8mb3, so installing sTask on a MyISAM site stopped with error 1071. The
create then left its table behind without keys, and the next migrate skipped
the existing table (hasTable) and recorded it.

- Create migrations size the indexed strings so every key fits: identifier
  128, scope 128, action 96, priority 16.
- 2026_12_06_000000_fit_indexed_columns_to_myisam restores missing indexes on
  MySQL: it shortens a column only where no stored value is longer, and skips
  a unique key whose rows share a value; tables with all keys stay as they are.
- The models refuse longer values (FitsIndexedColumns, INDEXED_LENGTHS), and
  the task API validates them, so a non-strict session never cuts them.
- tests/myisam.php: lengths, key budget and the guard always; installs on
  MyISAM utf8mb4/utf8mb3 and InnoDB and the repair with STASK_TEST_MYSQL.
  tests/bootstrap.php maps every class of the checkout.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…repair

- FitsIndexedColumns checks only values being written, so a row stored
  before the limit in a 255-character column can still be updated.
- The repair passes each column's own collation to the MODIFY; without it
  MySQL moves the column to the table default.
- run.php starts myisam.php in its own process: heartbeat.php declares a
  stub sWorker.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant