Skip to content

fix(migrations): keep the file_groups charset when making paths case-sensitive - #2675

Open
elcreator wants to merge 2 commits into
evolution-cms:3.5.xfrom
elcreator:fix-file-groups-collation-keep-charset
Open

elcreator wants to merge 2 commits into
evolution-cms:3.5.xfrom
elcreator:fix-file-groups-collation-keep-charset

Conversation

@elcreator

@elcreator elcreator commented Dec 5, 2026 •

Copy link
Copy Markdown

An update from 3.5.9 stops in 2026_10_11_000000_make_file_groups_file_case_sensitive when file_groups is a MyISAM table with a utf8mb3 column (an older site on MySQL 8.0, connection config engine MyISAM, charset utf8):

SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes
(SQL: ALTER TABLE `evo_file_groups` MODIFY `file` VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL DEFAULT '')

The migration converted the column to utf8mb4 on the way to a binary collation. That widens the indexed VARCHAR(255) from 765 to 1020 bytes, past the MyISAM key limit of 1000. make:site finish stops there: the new files are in place, but the update seeders, the Extras module, the settings version and the removal of install/ never run, so the manager reports the leftover install folder.

MyISAM is a supported engine, not a legacy one: the installers write it into the connection config for servers older than MySQL 5.7.6, and sites keep it. Checking the whole chain on MyISAM found a second gap: on a MyISAM site with a utf8mb4 connection, even a fresh install failed. The create migration's unique key (document_group, file VARCHAR(255)) needs 4 + 1020 bytes. The table stayed behind without its indexes, and the next migrate skipped it (hasTable()) and reported success.

Changes

  • core/includes/file_groups_schema.php, loaded by path (a migration must not depend on a classmap rebuild). It provides:
    • the engine and charset a new table gets (connection config, else server defaults; utf8 resolves to utf8mb3 on MySQL 8.0.30+);
    • the bytes per character;
    • the binary collation as the server names it (utf8_bin on 5.7, utf8mb3_bin on 8.0);
    • the longest file the unique key allows (249 for MyISAM with utf8mb4, 255 otherwise).
  • 2026_10_11 changes only the collation, keeping the charset and the length.
  • Create migration (both copies):
    • declares the binary collation itself, so 2026_10_11 has nothing left to do on a new site;
    • creates file as VARCHAR(249) on MyISAM with utf8mb4. The unique key still covers the full, case-exact path, with no prefix.
  • 2026_12_05_000000_restore_file_groups_indexes (new, idempotent):
    • restores the indexes of a table that hit the key limit;
    • shortens file only when no stored path is longer;
    • drops duplicate rows, keeping the oldest;
    • when a stored path is longer, keeps the rows, restores only the group index and writes the reason to the event log.
    • A table with all its indexes is left alone.
  • Review (thanks): collation names are matched with RIGHT(COLLATION_NAME, 4) = '_bin'. Under NO_BACKSLASH_ESCAPES, LIKE '%\_bin' matched nothing on MySQL 8.0.46 and 9.7.4, and the migration would have been recorded without changing anything. The CI scripts match the table prefix with LEFT() for the same reason.
  • CI:
    • ci.yml: an install leg on MySQL with MyISAM (EVO_DB_ENGINE), whose updater pass replays the chain over it.
    • upgrade.yml: a nightly / on-demand leg (legacy: myisam) that turns the older site into MyISAM / utf8mb3 before upgrading it (legacy-myisam.php).
    • smoke.php checks the file_groups unique key and binary collation on MySQL, and the engine of every table when one was asked for.
    • The unit-test job starts MySQL for the lowest PHP version and runs FileGroupsMysqlTest there (EVO_TEST_MYSQL).
  • AGENTS.md: a "Migrations on MySQL: MyISAM and older charsets" section with the rules behind this (key budget per engine and charset, change only what the migration is for, server-named collations, repair after a partial create, both migration copies, CI legs).

A site already stuck on it can finish before this is released:

  1. Give the column its binary collation in its own charset. For utf8mb3:
    ALTER TABLE evo_file_groups MODIFY file VARCHAR(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_bin NOT NULL DEFAULT '';
  2. Run php artisan make:site finish in core/.

Tests

  • FileGroupsStorageEngineTest (SQLite, always runs): key budget per engine and charset, engine/charset resolution, server collation names, the generated ALTER, both copies of the create migration, and the three migrations on SQLite.
  • FileGroupsMysqlTest (needs EVO_TEST_MYSQL), in the default SQL mode and under NO_BACKSLASH_ESCAPES:
    • the collation lookup;
    • an old MyISAM utf8mb3 table: charset and length kept, becomes _bin;
    • a new MyISAM utf8mb4 table: VARCHAR(249), all indexes;
    • InnoDB: 255;
    • the repair: indexes back, duplicates dropped, case variants kept, an over-long path kept.
    • Passes on MySQL 5.7.44, 8.0.46, 9.7.4 and MariaDB 10.11.
  • Full suite: 2893 passed, 35 skipped. With EVO_TEST_MYSQL (MySQL 9.7): 2896 passed, 32 skipped.
  • CI scripts, run locally against mysql:9.7:
    • install on MyISAM: all checks pass, including the updater pass;
    • 3.5.7 turned MyISAM / utf8mb3, upgraded to this branch: passes.
    • The same two legs on a tree with only the CI changes and the old migrations fail with 1071, so they catch this class of error.
  • End to end on MySQL 8.0: 3.5.9 installed, file_groups made MyISAM utf8mb3, 3.5.12 laid over it. make:site finish fails as above. Laying this branch over it, or applying the manual ALTER on 3.5.12, completes it: exit 0, install/ removed, no pending migrations.

🤖 Generated with Claude Code

…sensitive

The 2026_10_11 migration converted file_groups.file to utf8mb4. On a MyISAM
table with a utf8mb3 column that widens the indexed VARCHAR(255) to 1020
bytes, past the MyISAM key limit of 1000, and the update stops with error
1071. Change only the collation, to the binary one of the column's own
character set, named as the server spells it (utf8_bin on MySQL 5.7).

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

Seiger commented Dec 5, 2026

Copy link
Copy Markdown

The charset-preserving ALTER is the right approach. One compatibility blocker in 2026_10_11_000000_make_file_groups_file_case_sensitive.php:37: the binary-collation lookup relies on backslash escaping in LIKE. MySQL changes those semantics when the session uses NO_BACKSLASH_ESCAPES, so the query can return no match and the migration can be recorded as successful without changing the column collation. Could you use a SQL-mode-independent suffix check, e.g. RIGHT(COLLATION_NAME, 4) = '_bin', and cover the lookup in a MySQL regression test that asserts the original charset and the resulting binary collation? The new SQL-builder test does not exercise that lookup.

— SokilAI

…QL engines in CI

MyISAM is a supported engine: the installers write it for older servers and
sites keep it, often with a utf8 (utf8mb3) connection. The file_groups
migrations now respect its 1000-byte key limit:

- core/includes/file_groups_schema.php, loaded by path: the engine and
  charset a new table gets, bytes per character, the binary collation as the
  server names it (RIGHT(), not LIKE '%\_bin', which matches nothing under
  NO_BACKSLASH_ESCAPES), and the longest `file` the unique key allows.
- The create migration (both copies) declares the binary collation itself and,
  on MyISAM with utf8mb4, creates `file` as VARCHAR(249).
- 2026_10_11 keeps the column length as well as its charset.
- 2026_12_05_000000_restore_file_groups_indexes puts back the indexes a create
  that hit the key limit left out, drops the duplicates it let in, and keeps
  rows whose path is longer than the key allows.

CI: an install leg on MySQL with MyISAM, a nightly upgrade of a site turned
MyISAM / utf8mb3 (legacy-myisam.php), smoke checks for the file_groups key and
collation and the engine of every table, and FileGroupsMysqlTest run against a
real server (EVO_TEST_MYSQL) in both SQL modes. AGENTS.md lists the rules.

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

Copy link
Copy Markdown
Author

Thanks, confirmed and fixed in 686bb62.

On MySQL 8.0.46 and 9.7.4, COLLATION_NAME LIKE '%\_bin' returns nothing once the session has NO_BACKSLASH_ESCAPES, while RIGHT(COLLATION_NAME, 4) = '_bin' finds utf8mb3_bin in both modes. The lookup now lives in core/includes/file_groups_schema.php (binaryCollation()) and uses RIGHT(). The CI scripts match the table prefix with LEFT() for the same reason.

The MySQL regression test is core/tests/Unit/Install/FileGroupsMysqlTest.php. It needs EVO_TEST_MYSQL=user:password@host:port, and the unit-test job now starts MySQL and sets it for the lowest PHP version. Each case runs in the default SQL mode and under NO_BACKSLASH_ESCAPES:

  • the binary collation is found;
  • an old MyISAM utf8mb3 table keeps its charset and length and becomes _bin;
  • a new MyISAM utf8mb4 table, plus the repair cases.

It passes on MySQL 5.7.44, 8.0.46, 9.7.4 and MariaDB 10.11.

The same commit also covers MyISAM in the rest of the chain: the create migration, a repair migration for tables a failed create left without indexes, and CI legs for MyISAM. The PR description has the details.

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